001: /*******************************************************************************
002: * Copyright (c) 2000, 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;
011:
012: import java.io.IOException;
013: import java.util.ArrayList;
014: import java.util.Collections;
015: import java.util.List;
016:
017: import org.eclipse.core.runtime.IConfigurationElement;
018: import org.eclipse.core.runtime.IExtension;
019: import org.eclipse.core.runtime.IExtensionDelta;
020: import org.eclipse.core.runtime.IExtensionRegistry;
021: import org.eclipse.core.runtime.IRegistryChangeEvent;
022: import org.eclipse.core.runtime.IRegistryChangeListener;
023: import org.eclipse.ui.internal.util.ConfigurationElementMemento;
024:
025: final class ExtensionActivityRegistry extends AbstractActivityRegistry {
026: private List activityRequirementBindingDefinitions;
027:
028: private List activityDefinitions;
029:
030: private List activityPatternBindingDefinitions;
031:
032: private List categoryActivityBindingDefinitions;
033:
034: private List categoryDefinitions;
035:
036: private List defaultEnabledActivities;
037:
038: private IExtensionRegistry extensionRegistry;
039:
040: ExtensionActivityRegistry(IExtensionRegistry extensionRegistry) {
041: if (extensionRegistry == null) {
042: throw new NullPointerException();
043: }
044:
045: this .extensionRegistry = extensionRegistry;
046:
047: this .extensionRegistry
048: .addRegistryChangeListener(new IRegistryChangeListener() {
049: public void registryChanged(
050: IRegistryChangeEvent registryChangeEvent) {
051: IExtensionDelta[] extensionDeltas = registryChangeEvent
052: .getExtensionDeltas(
053: Persistence.PACKAGE_PREFIX,
054: Persistence.PACKAGE_BASE);
055:
056: if (extensionDeltas.length != 0) {
057: try {
058: load();
059: } catch (IOException eIO) {
060: }
061: }
062: }
063: });
064:
065: try {
066: load();
067: } catch (IOException eIO) {
068: }
069: }
070:
071: private String getNamespace(
072: IConfigurationElement configurationElement) {
073: String namespace = null;
074:
075: if (configurationElement != null) {
076: IExtension extension = configurationElement
077: .getDeclaringExtension();
078:
079: if (extension != null) {
080: namespace = extension.getNamespace();
081: }
082: }
083:
084: return namespace;
085: }
086:
087: private void load() throws IOException {
088: if (activityRequirementBindingDefinitions == null) {
089: activityRequirementBindingDefinitions = new ArrayList();
090: } else {
091: activityRequirementBindingDefinitions.clear();
092: }
093:
094: if (activityDefinitions == null) {
095: activityDefinitions = new ArrayList();
096: } else {
097: activityDefinitions.clear();
098: }
099:
100: if (activityPatternBindingDefinitions == null) {
101: activityPatternBindingDefinitions = new ArrayList();
102: } else {
103: activityPatternBindingDefinitions.clear();
104: }
105:
106: if (categoryActivityBindingDefinitions == null) {
107: categoryActivityBindingDefinitions = new ArrayList();
108: } else {
109: categoryActivityBindingDefinitions.clear();
110: }
111:
112: if (categoryDefinitions == null) {
113: categoryDefinitions = new ArrayList();
114: } else {
115: categoryDefinitions.clear();
116: }
117:
118: if (defaultEnabledActivities == null) {
119: defaultEnabledActivities = new ArrayList();
120: } else {
121: defaultEnabledActivities.clear();
122: }
123:
124: IConfigurationElement[] configurationElements = extensionRegistry
125: .getConfigurationElementsFor(Persistence.PACKAGE_FULL);
126:
127: for (int i = 0; i < configurationElements.length; i++) {
128: IConfigurationElement configurationElement = configurationElements[i];
129: String name = configurationElement.getName();
130:
131: if (Persistence.TAG_ACTIVITY_REQUIREMENT_BINDING
132: .equals(name)) {
133: readActivityRequirementBindingDefinition(configurationElement);
134: } else if (Persistence.TAG_ACTIVITY.equals(name)) {
135: readActivityDefinition(configurationElement);
136: } else if (Persistence.TAG_ACTIVITY_PATTERN_BINDING
137: .equals(name)) {
138: readActivityPatternBindingDefinition(configurationElement);
139: } else if (Persistence.TAG_CATEGORY_ACTIVITY_BINDING
140: .equals(name)) {
141: readCategoryActivityBindingDefinition(configurationElement);
142: } else if (Persistence.TAG_CATEGORY.equals(name)) {
143: readCategoryDefinition(configurationElement);
144: } else if (Persistence.TAG_DEFAULT_ENABLEMENT.equals(name)) {
145: readDefaultEnablement(configurationElement);
146: }
147: }
148:
149: boolean activityRegistryChanged = false;
150:
151: if (!activityRequirementBindingDefinitions
152: .equals(super .activityRequirementBindingDefinitions)) {
153: super .activityRequirementBindingDefinitions = Collections
154: .unmodifiableList(activityRequirementBindingDefinitions);
155: activityRegistryChanged = true;
156: }
157:
158: if (!activityDefinitions.equals(super .activityDefinitions)) {
159: super .activityDefinitions = Collections
160: .unmodifiableList(activityDefinitions);
161: activityRegistryChanged = true;
162: }
163:
164: if (!activityPatternBindingDefinitions
165: .equals(super .activityPatternBindingDefinitions)) {
166: super .activityPatternBindingDefinitions = Collections
167: .unmodifiableList(activityPatternBindingDefinitions);
168: activityRegistryChanged = true;
169: }
170:
171: if (!categoryActivityBindingDefinitions
172: .equals(super .categoryActivityBindingDefinitions)) {
173: super .categoryActivityBindingDefinitions = Collections
174: .unmodifiableList(categoryActivityBindingDefinitions);
175: activityRegistryChanged = true;
176: }
177:
178: if (!categoryDefinitions.equals(super .categoryDefinitions)) {
179: super .categoryDefinitions = Collections
180: .unmodifiableList(categoryDefinitions);
181: activityRegistryChanged = true;
182: }
183:
184: if (!defaultEnabledActivities
185: .equals(super .defaultEnabledActivities)) {
186: super .defaultEnabledActivities = Collections
187: .unmodifiableList(defaultEnabledActivities);
188: activityRegistryChanged = true;
189: }
190:
191: if (activityRegistryChanged) {
192: fireActivityRegistryChanged();
193: }
194: }
195:
196: private void readDefaultEnablement(
197: IConfigurationElement configurationElement) {
198: String enabledActivity = Persistence
199: .readDefaultEnablement(new ConfigurationElementMemento(
200: configurationElement));
201:
202: if (enabledActivity != null) {
203: defaultEnabledActivities.add(enabledActivity);
204: }
205:
206: }
207:
208: private void readActivityRequirementBindingDefinition(
209: IConfigurationElement configurationElement) {
210: ActivityRequirementBindingDefinition activityRequirementBindingDefinition = Persistence
211: .readActivityRequirementBindingDefinition(
212: new ConfigurationElementMemento(
213: configurationElement),
214: getNamespace(configurationElement));
215:
216: if (activityRequirementBindingDefinition != null) {
217: activityRequirementBindingDefinitions
218: .add(activityRequirementBindingDefinition);
219: }
220: }
221:
222: private void readActivityDefinition(
223: IConfigurationElement configurationElement) {
224: ActivityDefinition activityDefinition = Persistence
225: .readActivityDefinition(
226: new ConfigurationElementMemento(
227: configurationElement),
228: getNamespace(configurationElement));
229:
230: if (activityDefinition != null) {
231: activityDefinitions.add(activityDefinition);
232: }
233: }
234:
235: private void readActivityPatternBindingDefinition(
236: IConfigurationElement configurationElement) {
237: ActivityPatternBindingDefinition activityPatternBindingDefinition = Persistence
238: .readActivityPatternBindingDefinition(
239: new ConfigurationElementMemento(
240: configurationElement),
241: getNamespace(configurationElement));
242:
243: if (activityPatternBindingDefinition != null) {
244: activityPatternBindingDefinitions
245: .add(activityPatternBindingDefinition);
246: }
247: }
248:
249: private void readCategoryActivityBindingDefinition(
250: IConfigurationElement configurationElement) {
251: CategoryActivityBindingDefinition categoryActivityBindingDefinition = Persistence
252: .readCategoryActivityBindingDefinition(
253: new ConfigurationElementMemento(
254: configurationElement),
255: getNamespace(configurationElement));
256:
257: if (categoryActivityBindingDefinition != null) {
258: categoryActivityBindingDefinitions
259: .add(categoryActivityBindingDefinition);
260: }
261: }
262:
263: private void readCategoryDefinition(
264: IConfigurationElement configurationElement) {
265: CategoryDefinition categoryDefinition = Persistence
266: .readCategoryDefinition(
267: new ConfigurationElementMemento(
268: configurationElement),
269: getNamespace(configurationElement));
270:
271: if (categoryDefinition != null) {
272: categoryDefinitions.add(categoryDefinition);
273: }
274: }
275: }
|