KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > views > breakpoints > BreakpointsLabelProvider


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.debug.internal.ui.views.breakpoints;
12
13 import org.eclipse.debug.core.DebugPlugin;
14 import org.eclipse.debug.core.model.IBreakpoint;
15 import org.eclipse.debug.internal.ui.CompositeDebugImageDescriptor;
16 import org.eclipse.debug.internal.ui.DebugUIPlugin;
17 import org.eclipse.debug.ui.DebugUITools;
18 import org.eclipse.debug.ui.IDebugModelPresentation;
19 import org.eclipse.jface.viewers.IFontProvider;
20 import org.eclipse.jface.viewers.LabelProvider;
21 import org.eclipse.swt.graphics.Font;
22 import org.eclipse.swt.graphics.Image;
23 import org.eclipse.ui.model.WorkbenchLabelProvider;
24
25 /**
26  * Label provider for the breakpoints view
27  */

28 public class BreakpointsLabelProvider extends LabelProvider implements IFontProvider {
29
30     private WorkbenchLabelProvider fWorkbenchLabelProvider;
31     private IDebugModelPresentation fPresentation;
32     
33     /**
34      * Constructs a new label provide for the breakpoints view.
35      */

36     public BreakpointsLabelProvider() {
37         fWorkbenchLabelProvider = new WorkbenchLabelProvider();
38         fPresentation = DebugUITools.newDebugModelPresentation();
39     }
40     
41     /* (non-Javadoc)
42      * @see org.eclipse.jface.viewers.IBaseLabelProvider#dispose()
43      */

44     public void dispose() {
45         fWorkbenchLabelProvider.dispose();
46         fPresentation.dispose();
47         super.dispose();
48     }
49     
50     /* (non-Javadoc)
51      * @see org.eclipse.jface.viewers.ILabelProvider#getImage(java.lang.Object)
52      */

53     public Image getImage(Object JavaDoc element) {
54         if (element instanceof IBreakpoint) {
55             return fPresentation.getImage(element);
56         }
57         Image image = fWorkbenchLabelProvider.getImage(element);
58         if (image != null) {
59             int flags= computeAdornmentFlags();
60             if (flags > 0) {
61                 CompositeDebugImageDescriptor descriptor= new CompositeDebugImageDescriptor(image, flags);
62                 return DebugUIPlugin.getImageDescriptorRegistry().get(descriptor);
63             }
64         }
65         return image;
66     }
67     
68     /**
69      * Computes and return common adornment flags for the given category.
70      *
71      * @param element breakpoint category
72      * @return adornment flags defined in CompositeDebugImageDescriptor
73      */

74     private int computeAdornmentFlags() {
75         if (!DebugPlugin.getDefault().getBreakpointManager().isEnabled()) {
76             return CompositeDebugImageDescriptor.SKIP_BREAKPOINT;
77         }
78         return 0;
79     }
80     
81     /* (non-Javadoc)
82      * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
83      */

84     public String JavaDoc getText(Object JavaDoc element) {
85         if (element instanceof IBreakpoint) {
86             return fPresentation.getText(element);
87         }
88         return fWorkbenchLabelProvider.getText(element);
89     }
90
91     /* (non-Javadoc)
92      * @see org.eclipse.jface.viewers.IFontProvider#getFont(java.lang.Object)
93      */

94     public Font getFont(Object JavaDoc element) {
95         if (element instanceof IBreakpoint) {
96             return null;
97         }
98         return fWorkbenchLabelProvider.getFont(element);
99     }
100     
101     /**
102      * Returns the debug model presentation used by this label provider.
103      *
104      * @return the debug model presentation used by this label provider
105      */

106     protected IDebugModelPresentation getPresentation() {
107         return fPresentation;
108     }
109 }
110
Popular Tags