KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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.core.runtime.CoreException;
14 import org.eclipse.core.runtime.IAdaptable;
15 import org.eclipse.core.runtime.IConfigurationElement;
16 import org.eclipse.debug.core.model.IBreakpoint;
17 import org.eclipse.debug.internal.ui.DebugUIPlugin;
18 import org.eclipse.debug.internal.ui.views.DebugUIViewsMessages;
19 import org.eclipse.debug.ui.IBreakpointOrganizerDelegate;
20 import org.eclipse.debug.ui.IBreakpointOrganizerDelegateExtension;
21 import org.eclipse.jface.resource.ImageDescriptor;
22 import org.eclipse.jface.util.IPropertyChangeListener;
23
24 /**
25  * A contributed breakpoint organizer.
26  */

27 public class BreakpointOrganizerExtension implements IBreakpointOrganizer, IBreakpointOrganizerDelegateExtension {
28     
29     private IConfigurationElement fElement;
30     private IBreakpointOrganizerDelegate fDelegate;
31     private ImageDescriptor fDescriptor;
32     
33     // attributes
34
public static final String JavaDoc ATTR_LABEL = "label"; //$NON-NLS-1$
35
public static final String JavaDoc ATTR_CLASS = "class"; //$NON-NLS-1$
36
public static final String JavaDoc ATTR_ID = "id"; //$NON-NLS-1$
37
public static final String JavaDoc ATTR_ICON = "icon"; //$NON-NLS-1$
38
public static final String JavaDoc ATTR_OTHERS_LABEL = "othersLabel"; //$NON-NLS-1$
39

40     public BreakpointOrganizerExtension(IConfigurationElement element) {
41         fElement = element;
42     }
43     
44     /**
45      * Returns the image descriptor for this organizer.
46      *
47      * @return image descriptor
48      */

49     public ImageDescriptor getImageDescriptor() {
50         if (fDescriptor == null) {
51             fDescriptor = DebugUIPlugin.getImageDescriptor(fElement, ATTR_ICON);
52             if (fDescriptor == null) {
53                 fDescriptor = ImageDescriptor.getMissingImageDescriptor();
54             }
55         }
56         return fDescriptor;
57     }
58     
59     /**
60      * Returns this organizer's label.
61      *
62      * @return this organizer's label
63      */

64     public String JavaDoc getLabel() {
65         return fElement.getAttribute(ATTR_LABEL);
66     }
67     
68     /**
69      * Returns this organizer's identifier.
70      *
71      * @return this organizer's identifier
72      */

73     public String JavaDoc getIdentifier() {
74         return fElement.getAttribute(ATTR_ID);
75     }
76     
77     /**
78      * Returns this organizer's delegate, instantiating it if required.
79      *
80      * @return this organizer's delegate
81      */

82     protected IBreakpointOrganizerDelegate getOrganizer() {
83         if (fDelegate == null) {
84             try {
85                 fDelegate = (IBreakpointOrganizerDelegate) fElement.createExecutableExtension(ATTR_CLASS);
86             } catch (CoreException e) {
87                 DebugUIPlugin.log(e);
88             }
89         }
90         return fDelegate;
91     }
92
93     /* (non-Javadoc)
94      * @see org.eclipse.debug.ui.IBreakpointOrganizerDelegate#getCategories(org.eclipse.debug.core.model.IBreakpoint)
95      */

96     public IAdaptable[] getCategories(IBreakpoint breakpoint) {
97         return getOrganizer().getCategories(breakpoint);
98     }
99
100     /* (non-Javadoc)
101      * @see org.eclipse.debug.ui.IBreakpointOrganizerDelegate#addPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener)
102      */

103     public void addPropertyChangeListener(IPropertyChangeListener listener) {
104         getOrganizer().addPropertyChangeListener(listener);
105     }
106
107     /* (non-Javadoc)
108      * @see org.eclipse.debug.ui.IBreakpointOrganizerDelegate#removePropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener)
109      */

110     public void removePropertyChangeListener(IPropertyChangeListener listener) {
111         getOrganizer().removePropertyChangeListener(listener);
112     }
113
114     /* (non-Javadoc)
115      * @see org.eclipse.debug.ui.IBreakpointOrganizerDelegate#addBreakpoint(org.eclipse.debug.core.model.IBreakpoint, org.eclipse.core.runtime.IAdaptable)
116      */

117     public void addBreakpoint(IBreakpoint breakpoint, IAdaptable category) {
118         getOrganizer().addBreakpoint(breakpoint, category);
119     }
120
121     /* (non-Javadoc)
122      * @see org.eclipse.debug.ui.IBreakpointOrganizerDelegate#removeBreakpoint(org.eclipse.debug.core.model.IBreakpoint, org.eclipse.core.runtime.IAdaptable)
123      */

124     public void removeBreakpoint(IBreakpoint breakpoint, IAdaptable category) {
125         getOrganizer().removeBreakpoint(breakpoint, category);
126     }
127
128     /* (non-Javadoc)
129      * @see org.eclipse.debug.ui.IBreakpointOrganizerDelegate#canAdd(org.eclipse.debug.core.model.IBreakpoint, org.eclipse.core.runtime.IAdaptable)
130      */

131     public boolean canAdd(IBreakpoint breakpoint, IAdaptable category) {
132         return getOrganizer().canAdd(breakpoint, category);
133     }
134
135     /* (non-Javadoc)
136      * @see org.eclipse.debug.ui.IBreakpointOrganizerDelegate#canRemove(org.eclipse.debug.core.model.IBreakpoint, org.eclipse.core.runtime.IAdaptable)
137      */

138     public boolean canRemove(IBreakpoint breakpoint, IAdaptable category) {
139         return getOrganizer().canRemove(breakpoint, category);
140     }
141
142     /* (non-Javadoc)
143      * @see org.eclipse.debug.ui.IBreakpointOrganizerDelegate#dispose()
144      */

145     public void dispose() {
146         // don't instantiate the delegate if it has not been used
147
if (fDelegate != null) {
148             fDelegate.dispose();
149         }
150     }
151
152     /* (non-Javadoc)
153      * @see org.eclipse.debug.internal.ui.views.breakpoints.IBreakpointOrganizer#getOthersLabel()
154      */

155     public String JavaDoc getOthersLabel() {
156         String JavaDoc attribute = fElement.getAttribute(ATTR_OTHERS_LABEL);
157         if (attribute == null) {
158             return DebugUIViewsMessages.OtherBreakpointOrganizer_0;
159         }
160         return attribute;
161     }
162
163     /* (non-Javadoc)
164      * @see org.eclipse.debug.ui.IBreakpointOrganizerDelegate#getCategories()
165      */

166     public IAdaptable[] getCategories() {
167         return getOrganizer().getCategories();
168     }
169
170     /* (non-Javadoc)
171      * @see org.eclipse.debug.ui.IBreakpointOrganizerDelegateExtension#addBreakpoints(org.eclipse.debug.core.model.IBreakpoint[], org.eclipse.core.runtime.IAdaptable)
172      */

173     public void addBreakpoints(IBreakpoint[] breakpoints, IAdaptable category) {
174         IBreakpointOrganizerDelegate organizer = getOrganizer();
175         if (organizer instanceof IBreakpointOrganizerDelegateExtension) {
176             ((IBreakpointOrganizerDelegateExtension)organizer).addBreakpoints(breakpoints, category);
177         } else {
178             for (int i = 0; i < breakpoints.length; i++) {
179                 addBreakpoint(breakpoints[i], category);
180             }
181         }
182     }
183
184     /* (non-Javadoc)
185      * @see org.eclipse.debug.ui.IBreakpointOrganizerDelegateExtension#removeBreakpoints(org.eclipse.debug.core.model.IBreakpoint[], org.eclipse.core.runtime.IAdaptable)
186      */

187     public void removeBreakpoints(IBreakpoint[] breakpoints, IAdaptable category) {
188         IBreakpointOrganizerDelegate organizer = getOrganizer();
189         if (organizer instanceof IBreakpointOrganizerDelegateExtension) {
190             ((IBreakpointOrganizerDelegateExtension)organizer).removeBreakpoints(breakpoints, category);
191         } else {
192             for (int i = 0; i < breakpoints.length; i++) {
193                 removeBreakpoint(breakpoints[i], category);
194             }
195         }
196         
197     }
198 }
199
Popular Tags