1 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 27 public class BreakpointOrganizerExtension implements IBreakpointOrganizer, IBreakpointOrganizerDelegateExtension { 28 29 private IConfigurationElement fElement; 30 private IBreakpointOrganizerDelegate fDelegate; 31 private ImageDescriptor fDescriptor; 32 33 public static final String ATTR_LABEL = "label"; public static final String ATTR_CLASS = "class"; public static final String ATTR_ID = "id"; public static final String ATTR_ICON = "icon"; public static final String ATTR_OTHERS_LABEL = "othersLabel"; 40 public BreakpointOrganizerExtension(IConfigurationElement element) { 41 fElement = element; 42 } 43 44 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 64 public String getLabel() { 65 return fElement.getAttribute(ATTR_LABEL); 66 } 67 68 73 public String getIdentifier() { 74 return fElement.getAttribute(ATTR_ID); 75 } 76 77 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 96 public IAdaptable[] getCategories(IBreakpoint breakpoint) { 97 return getOrganizer().getCategories(breakpoint); 98 } 99 100 103 public void addPropertyChangeListener(IPropertyChangeListener listener) { 104 getOrganizer().addPropertyChangeListener(listener); 105 } 106 107 110 public void removePropertyChangeListener(IPropertyChangeListener listener) { 111 getOrganizer().removePropertyChangeListener(listener); 112 } 113 114 117 public void addBreakpoint(IBreakpoint breakpoint, IAdaptable category) { 118 getOrganizer().addBreakpoint(breakpoint, category); 119 } 120 121 124 public void removeBreakpoint(IBreakpoint breakpoint, IAdaptable category) { 125 getOrganizer().removeBreakpoint(breakpoint, category); 126 } 127 128 131 public boolean canAdd(IBreakpoint breakpoint, IAdaptable category) { 132 return getOrganizer().canAdd(breakpoint, category); 133 } 134 135 138 public boolean canRemove(IBreakpoint breakpoint, IAdaptable category) { 139 return getOrganizer().canRemove(breakpoint, category); 140 } 141 142 145 public void dispose() { 146 if (fDelegate != null) { 148 fDelegate.dispose(); 149 } 150 } 151 152 155 public String getOthersLabel() { 156 String attribute = fElement.getAttribute(ATTR_OTHERS_LABEL); 157 if (attribute == null) { 158 return DebugUIViewsMessages.OtherBreakpointOrganizer_0; 159 } 160 return attribute; 161 } 162 163 166 public IAdaptable[] getCategories() { 167 return getOrganizer().getCategories(); 168 } 169 170 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 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 |