KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > activities > ws > TriggerPointManager


1 /*******************************************************************************
2  * Copyright (c) 2005, 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.ui.internal.activities.ws;
12
13 import java.util.HashMap JavaDoc;
14 import java.util.Set JavaDoc;
15
16 import org.eclipse.core.runtime.IConfigurationElement;
17 import org.eclipse.core.runtime.IExtension;
18 import org.eclipse.core.runtime.IExtensionPoint;
19 import org.eclipse.core.runtime.Platform;
20 import org.eclipse.core.runtime.dynamichelpers.ExtensionTracker;
21 import org.eclipse.core.runtime.dynamichelpers.IExtensionChangeHandler;
22 import org.eclipse.core.runtime.dynamichelpers.IExtensionTracker;
23 import org.eclipse.ui.PlatformUI;
24 import org.eclipse.ui.activities.ITriggerPoint;
25 import org.eclipse.ui.activities.ITriggerPointManager;
26 import org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants;
27
28 /**
29  * Workbench implementation of the trigger point manager.
30  *
31  * @since 3.1
32  */

33 public class TriggerPointManager implements ITriggerPointManager, IExtensionChangeHandler {
34
35     private HashMap JavaDoc triggerMap = new HashMap JavaDoc();
36
37     /**
38      *
39      */

40     public TriggerPointManager() {
41         super();
42         triggerMap.put(ITriggerPointManager.UNKNOWN_TRIGGER_POINT_ID,
43                 new AbstractTriggerPoint() {
44
45                     /*
46                      * (non-Javadoc)
47                      *
48                      * @see org.eclipse.ui.activities.ITriggerPoint#getId()
49                      */

50                     public String JavaDoc getId() {
51                         return ITriggerPointManager.UNKNOWN_TRIGGER_POINT_ID;
52                     }
53
54                     /*
55                      * (non-Javadoc)
56                      *
57                      * @see org.eclipse.ui.activities.ITriggerPoint#getStringHint(java.lang.String)
58                      */

59                     public String JavaDoc getStringHint(String JavaDoc key) {
60                         if (ITriggerPoint.HINT_INTERACTIVE.equals(key)) {
61                             // TODO: change to false when we have mapped our
62
// trigger points
63
return Boolean.TRUE.toString();
64                         }
65                         return null;
66                     }
67
68                     /*
69                      * (non-Javadoc)
70                      *
71                      * @see org.eclipse.ui.activities.ITriggerPoint#getBooleanHint(java.lang.String)
72                      */

73                     public boolean getBooleanHint(String JavaDoc key) {
74                         if (ITriggerPoint.HINT_INTERACTIVE.equals(key)) {
75                             // TODO: change to false when we have mapped our
76
// trigger points
77
return true;
78                         }
79                         return false;
80                     }
81                 });
82         IExtensionTracker tracker = PlatformUI.getWorkbench().getExtensionTracker();
83         tracker.registerHandler(this, ExtensionTracker.createExtensionPointFilter(getExtensionPointFilter()));
84
85         IExtensionPoint point = getExtensionPointFilter();
86         IExtension[] extensions = point.getExtensions();
87         for (int i = 0; i < extensions.length; i++) {
88             addExtension(tracker,
89                     extensions[i]);
90         }
91     }
92
93     /*
94      * (non-Javadoc)
95      *
96      * @see org.eclipse.ui.activities.ITriggerPointManager#getTriggerPoint(java.lang.String)
97      */

98     public ITriggerPoint getTriggerPoint(String JavaDoc id) {
99         return (ITriggerPoint) triggerMap.get(id);
100     }
101
102     /*
103      * (non-Javadoc)
104      *
105      * @see org.eclipse.ui.activities.ITriggerPointManager#getDefinedTriggerPointIds()
106      */

107     public Set JavaDoc getDefinedTriggerPointIds() {
108         return triggerMap.entrySet();
109     }
110
111     /*
112      * (non-Javadoc)
113      *
114      * @see org.eclipse.core.runtime.dynamicHelpers.IExtensionRemovalHandler#removeInstance(org.eclipse.core.runtime.IExtension,
115      * java.lang.Object[])
116      */

117     public void removeExtension(IExtension extension, Object JavaDoc[] objects) {
118         for (int i = 0; i < objects.length; i++) {
119             Object JavaDoc object = objects[i];
120             if (object instanceof RegistryTriggerPoint) {
121                 triggerMap.remove(((RegistryTriggerPoint) object).getId());
122             }
123         }
124     }
125
126     /*
127      * (non-Javadoc)
128      *
129      * @see org.eclipse.core.runtime.dynamicHelpers.IExtensionAdditionHandler#addInstance(org.eclipse.core.runtime.dynamicHelpers.IExtensionTracker,
130      * org.eclipse.core.runtime.IExtension)
131      */

132     public void addExtension(IExtensionTracker tracker, IExtension extension) {
133         IConfigurationElement[] elements = extension.getConfigurationElements();
134         for (int i = 0; i < elements.length; i++) {
135             IConfigurationElement element = elements[i];
136             if (element.getName().equals(
137                     IWorkbenchRegistryConstants.TAG_TRIGGERPOINT)) {
138                 String JavaDoc id = element
139                         .getAttribute(IWorkbenchRegistryConstants.ATT_ID);
140                 if (id == null) {
141                     continue;
142                 }
143                 RegistryTriggerPoint triggerPoint = new RegistryTriggerPoint(
144                         id, element);
145                 triggerMap.put(id, triggerPoint);
146                 tracker.registerObject(extension, triggerPoint,
147                         IExtensionTracker.REF_WEAK);
148             }
149         }
150     }
151
152     private IExtensionPoint getExtensionPointFilter() {
153         return Platform.getExtensionRegistry().getExtensionPoint(
154                 PlatformUI.PLUGIN_ID, IWorkbenchRegistryConstants.PL_ACTIVITYSUPPORT);
155     }
156 }
157
Popular Tags