1 11 package org.eclipse.debug.internal.ui.views.breakpoints; 12 13 import java.util.ArrayList ; 14 import java.util.Collection ; 15 import java.util.Collections ; 16 import java.util.Comparator ; 17 import java.util.HashMap ; 18 import java.util.List ; 19 import java.util.Map ; 20 21 import org.eclipse.core.runtime.IConfigurationElement; 22 import org.eclipse.core.runtime.IExtensionPoint; 23 import org.eclipse.core.runtime.Platform; 24 import org.eclipse.debug.internal.ui.DebugUIPlugin; 25 import org.eclipse.debug.ui.IDebugUIConstants; 26 import org.eclipse.jface.util.IPropertyChangeListener; 27 import org.eclipse.jface.util.PropertyChangeEvent; 28 29 39 public class BreakpointOrganizerManager { 40 41 private static BreakpointOrganizerManager fgManager; 42 43 private Map fOrganizers = new HashMap (); 45 private List fSorted = null; 47 48 52 public static BreakpointOrganizerManager getDefault() { 53 if (fgManager == null) { 54 fgManager= new BreakpointOrganizerManager(); 55 } 56 return fgManager; 57 } 58 59 62 private BreakpointOrganizerManager() { 63 loadOrganizers(); 64 start("org.eclipse.debug.ui.workingSetOrganizer"); start("org.eclipse.debug.ui.breakpointWorkingSetOrganizer"); } 68 69 74 private void start(String organizerId) { 75 IBreakpointOrganizer organizer = getOrganizer(organizerId); 76 IPropertyChangeListener listener = new IPropertyChangeListener() { 77 public void propertyChange(PropertyChangeEvent event) { 78 } 79 }; 80 organizer.addPropertyChangeListener(listener); 81 organizer.removePropertyChangeListener(listener); 82 } 83 84 87 private void loadOrganizers() { 88 IExtensionPoint extensionPoint= Platform.getExtensionRegistry().getExtensionPoint(DebugUIPlugin.getUniqueIdentifier(), IDebugUIConstants.EXTENSION_POINT_BREAKPOINT_ORGANIZERS); 89 IConfigurationElement[] configurationElements = extensionPoint.getConfigurationElements(); 90 for (int i = 0; i < configurationElements.length; i++) { 91 IConfigurationElement element= configurationElements[i]; 92 IBreakpointOrganizer organizer = new BreakpointOrganizerExtension(element); 93 if (validateOrganizer(organizer)) { 94 fOrganizers.put(organizer.getIdentifier(), organizer); 95 } 96 } 97 } 98 99 105 protected static boolean validateOrganizer(IBreakpointOrganizer organizer) { 106 String id = organizer.getIdentifier(); 107 String label = organizer.getLabel(); 108 return id != null && id.length() > 0 && label != null && label.length() > 0; 109 } 110 111 116 public IBreakpointOrganizer[] getOrganizers() { 117 if (fSorted == null) { 118 Collection collection = fOrganizers.values(); 119 fSorted = new ArrayList (); 120 fSorted.addAll(collection); 121 Collections.sort(fSorted, new Comparator () { 122 public int compare(Object o1, Object o2) { 123 IBreakpointOrganizer b1 = (IBreakpointOrganizer)o1; 124 IBreakpointOrganizer b2 = (IBreakpointOrganizer)o2; 125 return b1.getLabel().compareTo(b2.getLabel()); 126 } 127 128 public boolean equals(Object obj) { 129 return this == obj; 130 } 131 }); 132 } 133 return (IBreakpointOrganizer[]) fSorted.toArray(new IBreakpointOrganizer[fSorted.size()]); 134 } 135 136 141 public IBreakpointOrganizer getOrganizer(String id) { 142 return (IBreakpointOrganizer) fOrganizers.get(id); 143 } 144 145 148 public void shutdown() { 149 IBreakpointOrganizer[] organizers = getOrganizers(); 150 for (int i = 0; i < organizers.length; i++) { 151 IBreakpointOrganizer organizer = organizers[i]; 152 organizer.dispose(); 153 } 154 } 155 156 } 157 | Popular Tags |