1 11 package org.eclipse.ui.internal.activities.ws; 12 13 import java.util.HashMap ; 14 import java.util.Set ; 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 33 public class TriggerPointManager implements ITriggerPointManager, IExtensionChangeHandler { 34 35 private HashMap triggerMap = new HashMap (); 36 37 40 public TriggerPointManager() { 41 super(); 42 triggerMap.put(ITriggerPointManager.UNKNOWN_TRIGGER_POINT_ID, 43 new AbstractTriggerPoint() { 44 45 50 public String getId() { 51 return ITriggerPointManager.UNKNOWN_TRIGGER_POINT_ID; 52 } 53 54 59 public String getStringHint(String key) { 60 if (ITriggerPoint.HINT_INTERACTIVE.equals(key)) { 61 return Boolean.TRUE.toString(); 64 } 65 return null; 66 } 67 68 73 public boolean getBooleanHint(String key) { 74 if (ITriggerPoint.HINT_INTERACTIVE.equals(key)) { 75 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 98 public ITriggerPoint getTriggerPoint(String id) { 99 return (ITriggerPoint) triggerMap.get(id); 100 } 101 102 107 public Set getDefinedTriggerPointIds() { 108 return triggerMap.entrySet(); 109 } 110 111 117 public void removeExtension(IExtension extension, Object [] objects) { 118 for (int i = 0; i < objects.length; i++) { 119 Object object = objects[i]; 120 if (object instanceof RegistryTriggerPoint) { 121 triggerMap.remove(((RegistryTriggerPoint) object).getId()); 122 } 123 } 124 } 125 126 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 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 |