KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2004, 2005 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 java.util.ArrayList JavaDoc;
14 import java.util.Collection JavaDoc;
15 import java.util.Collections JavaDoc;
16 import java.util.Comparator JavaDoc;
17 import java.util.HashMap JavaDoc;
18 import java.util.List JavaDoc;
19 import java.util.Map JavaDoc;
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 /**
30  * Manager which provides access to the breakpoint organizers
31  * contributed via the org.eclipse.debug.ui.breakpointOrganizers
32  * extension point.
33  * <p>
34  * Manages the default breakpoint working set and places newly
35  * create breakpoints in to that set.
36  * </p>
37  * @since 3.1
38  */

39 public class BreakpointOrganizerManager {
40     
41     private static BreakpointOrganizerManager fgManager;
42     
43     // map for lookup by id
44
private Map JavaDoc fOrganizers = new HashMap JavaDoc();
45     // cached sorted list by label
46
private List JavaDoc fSorted = null;
47
48     /**
49      * Returns the singleton instance of the breakpoint container
50      * factory manager.
51      */

52     public static BreakpointOrganizerManager getDefault() {
53         if (fgManager == null) {
54             fgManager= new BreakpointOrganizerManager();
55         }
56         return fgManager;
57     }
58     
59     /**
60      * Creates and initializes a new breakpoint container factory.
61      */

62     private BreakpointOrganizerManager() {
63         loadOrganizers();
64         // force the working set organizers to initialize their listeners
65
start("org.eclipse.debug.ui.workingSetOrganizer"); //$NON-NLS-1$
66
start("org.eclipse.debug.ui.breakpointWorkingSetOrganizer"); //$NON-NLS-1$
67
}
68     
69     /**
70      * Forces instantiation of orgranizer delegate.
71      *
72      * @param organizerId organizer to start
73      */

74     private void start(String JavaDoc 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     /**
85      * Loads all contributed breakpoint organizers.
86      */

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     /**
100      * Validates the given organizer. Checks that certain required attributes
101      * are available.
102      * @param extension the organizer to validate
103      * @return whether the given organizer is valid
104      */

105     protected static boolean validateOrganizer(IBreakpointOrganizer organizer) {
106         String JavaDoc id = organizer.getIdentifier();
107         String JavaDoc label = organizer.getLabel();
108         return id != null && id.length() > 0 && label != null && label.length() > 0;
109     }
110     
111     /**
112      * Returns all contributed breakpoint organizers.
113      *
114      * @return all contributed breakpoint organizers
115      */

116     public IBreakpointOrganizer[] getOrganizers() {
117         if (fSorted == null) {
118             Collection JavaDoc collection = fOrganizers.values();
119             fSorted = new ArrayList JavaDoc();
120             fSorted.addAll(collection);
121             Collections.sort(fSorted, new Comparator JavaDoc() {
122                 public int compare(Object JavaDoc o1, Object JavaDoc 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 JavaDoc obj) {
129                     return this == obj;
130                 }
131             });
132         }
133         return (IBreakpointOrganizer[]) fSorted.toArray(new IBreakpointOrganizer[fSorted.size()]);
134     }
135     
136     /**
137      * Returns the specified breakpoint organizer or <code>null</code>
138      * @param id organizer identifier
139      * @return breakpoint organizer or <code>null</code>
140      */

141     public IBreakpointOrganizer getOrganizer(String JavaDoc id) {
142         return (IBreakpointOrganizer) fOrganizers.get(id);
143     }
144     
145     /**
146      * Shuts down the organizer manager, disposing organizers.
147      */

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