001: /*******************************************************************************
002: * Copyright (c) 2005, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.ui.internal.activities.ws;
011:
012: import java.util.HashMap;
013: import java.util.Set;
014:
015: import org.eclipse.core.runtime.IConfigurationElement;
016: import org.eclipse.core.runtime.IExtension;
017: import org.eclipse.core.runtime.IExtensionPoint;
018: import org.eclipse.core.runtime.Platform;
019: import org.eclipse.core.runtime.dynamichelpers.ExtensionTracker;
020: import org.eclipse.core.runtime.dynamichelpers.IExtensionChangeHandler;
021: import org.eclipse.core.runtime.dynamichelpers.IExtensionTracker;
022: import org.eclipse.ui.PlatformUI;
023: import org.eclipse.ui.activities.ITriggerPoint;
024: import org.eclipse.ui.activities.ITriggerPointManager;
025: import org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants;
026:
027: /**
028: * Workbench implementation of the trigger point manager.
029: *
030: * @since 3.1
031: */
032: public class TriggerPointManager implements ITriggerPointManager,
033: IExtensionChangeHandler {
034:
035: private HashMap triggerMap = new HashMap();
036:
037: /**
038: *
039: */
040: public TriggerPointManager() {
041: super ();
042: triggerMap.put(ITriggerPointManager.UNKNOWN_TRIGGER_POINT_ID,
043: new AbstractTriggerPoint() {
044:
045: /*
046: * (non-Javadoc)
047: *
048: * @see org.eclipse.ui.activities.ITriggerPoint#getId()
049: */
050: public String getId() {
051: return ITriggerPointManager.UNKNOWN_TRIGGER_POINT_ID;
052: }
053:
054: /*
055: * (non-Javadoc)
056: *
057: * @see org.eclipse.ui.activities.ITriggerPoint#getStringHint(java.lang.String)
058: */
059: public String getStringHint(String key) {
060: if (ITriggerPoint.HINT_INTERACTIVE.equals(key)) {
061: // TODO: change to false when we have mapped our
062: // trigger points
063: return Boolean.TRUE.toString();
064: }
065: return null;
066: }
067:
068: /*
069: * (non-Javadoc)
070: *
071: * @see org.eclipse.ui.activities.ITriggerPoint#getBooleanHint(java.lang.String)
072: */
073: public boolean getBooleanHint(String key) {
074: if (ITriggerPoint.HINT_INTERACTIVE.equals(key)) {
075: // TODO: change to false when we have mapped our
076: // trigger points
077: return true;
078: }
079: return false;
080: }
081: });
082: IExtensionTracker tracker = PlatformUI.getWorkbench()
083: .getExtensionTracker();
084: tracker.registerHandler(this , ExtensionTracker
085: .createExtensionPointFilter(getExtensionPointFilter()));
086:
087: IExtensionPoint point = getExtensionPointFilter();
088: IExtension[] extensions = point.getExtensions();
089: for (int i = 0; i < extensions.length; i++) {
090: addExtension(tracker, extensions[i]);
091: }
092: }
093:
094: /*
095: * (non-Javadoc)
096: *
097: * @see org.eclipse.ui.activities.ITriggerPointManager#getTriggerPoint(java.lang.String)
098: */
099: public ITriggerPoint getTriggerPoint(String id) {
100: return (ITriggerPoint) triggerMap.get(id);
101: }
102:
103: /*
104: * (non-Javadoc)
105: *
106: * @see org.eclipse.ui.activities.ITriggerPointManager#getDefinedTriggerPointIds()
107: */
108: public Set getDefinedTriggerPointIds() {
109: return triggerMap.entrySet();
110: }
111:
112: /*
113: * (non-Javadoc)
114: *
115: * @see org.eclipse.core.runtime.dynamicHelpers.IExtensionRemovalHandler#removeInstance(org.eclipse.core.runtime.IExtension,
116: * java.lang.Object[])
117: */
118: public void removeExtension(IExtension extension, Object[] objects) {
119: for (int i = 0; i < objects.length; i++) {
120: Object object = objects[i];
121: if (object instanceof RegistryTriggerPoint) {
122: triggerMap.remove(((RegistryTriggerPoint) object)
123: .getId());
124: }
125: }
126: }
127:
128: /*
129: * (non-Javadoc)
130: *
131: * @see org.eclipse.core.runtime.dynamicHelpers.IExtensionAdditionHandler#addInstance(org.eclipse.core.runtime.dynamicHelpers.IExtensionTracker,
132: * org.eclipse.core.runtime.IExtension)
133: */
134: public void addExtension(IExtensionTracker tracker,
135: IExtension extension) {
136: IConfigurationElement[] elements = extension
137: .getConfigurationElements();
138: for (int i = 0; i < elements.length; i++) {
139: IConfigurationElement element = elements[i];
140: if (element.getName().equals(
141: IWorkbenchRegistryConstants.TAG_TRIGGERPOINT)) {
142: String id = element
143: .getAttribute(IWorkbenchRegistryConstants.ATT_ID);
144: if (id == null) {
145: continue;
146: }
147: RegistryTriggerPoint triggerPoint = new RegistryTriggerPoint(
148: id, element);
149: triggerMap.put(id, triggerPoint);
150: tracker.registerObject(extension, triggerPoint,
151: IExtensionTracker.REF_WEAK);
152: }
153: }
154: }
155:
156: private IExtensionPoint getExtensionPointFilter() {
157: return Platform.getExtensionRegistry().getExtensionPoint(
158: PlatformUI.PLUGIN_ID,
159: IWorkbenchRegistryConstants.PL_ACTIVITYSUPPORT);
160: }
161: }
|