1 11 12 package org.eclipse.ui.internal.activities; 13 14 import java.io.IOException ; 15 import java.util.ArrayList ; 16 import java.util.Collections ; 17 import java.util.List ; 18 19 import org.eclipse.core.runtime.IConfigurationElement; 20 import org.eclipse.core.runtime.IExtension; 21 import org.eclipse.core.runtime.IExtensionDelta; 22 import org.eclipse.core.runtime.IExtensionRegistry; 23 import org.eclipse.core.runtime.IRegistryChangeEvent; 24 import org.eclipse.core.runtime.IRegistryChangeListener; 25 import org.eclipse.ui.internal.util.ConfigurationElementMemento; 26 27 final class ExtensionActivityRegistry extends AbstractActivityRegistry { 28 private List activityRequirementBindingDefinitions; 29 30 private List activityDefinitions; 31 32 private List activityPatternBindingDefinitions; 33 34 private List categoryActivityBindingDefinitions; 35 36 private List categoryDefinitions; 37 38 private List defaultEnabledActivities; 39 40 private IExtensionRegistry extensionRegistry; 41 42 ExtensionActivityRegistry(IExtensionRegistry extensionRegistry) { 43 if (extensionRegistry == null) { 44 throw new NullPointerException (); 45 } 46 47 this.extensionRegistry = extensionRegistry; 48 49 this.extensionRegistry 50 .addRegistryChangeListener(new IRegistryChangeListener() { 51 public void registryChanged( 52 IRegistryChangeEvent registryChangeEvent) { 53 IExtensionDelta[] extensionDeltas = registryChangeEvent 54 .getExtensionDeltas(Persistence.PACKAGE_PREFIX, 55 Persistence.PACKAGE_BASE); 56 57 if (extensionDeltas.length != 0) { 58 try { 59 load(); 60 } catch (IOException eIO) { 61 } 62 } 63 } 64 }); 65 66 try { 67 load(); 68 } catch (IOException eIO) { 69 } 70 } 71 72 private String getNamespace(IConfigurationElement configurationElement) { 73 String namespace = null; 74 75 if (configurationElement != null) { 76 IExtension extension = configurationElement.getDeclaringExtension(); 77 78 if (extension != null) { 79 namespace = extension.getNamespace(); 80 } 81 } 82 83 return namespace; 84 } 85 86 private void load() throws IOException { 87 if (activityRequirementBindingDefinitions == null) { 88 activityRequirementBindingDefinitions = new ArrayList (); 89 } else { 90 activityRequirementBindingDefinitions.clear(); 91 } 92 93 if (activityDefinitions == null) { 94 activityDefinitions = new ArrayList (); 95 } else { 96 activityDefinitions.clear(); 97 } 98 99 if (activityPatternBindingDefinitions == null) { 100 activityPatternBindingDefinitions = new ArrayList (); 101 } else { 102 activityPatternBindingDefinitions.clear(); 103 } 104 105 if (categoryActivityBindingDefinitions == null) { 106 categoryActivityBindingDefinitions = new ArrayList (); 107 } else { 108 categoryActivityBindingDefinitions.clear(); 109 } 110 111 if (categoryDefinitions == null) { 112 categoryDefinitions = new ArrayList (); 113 } else { 114 categoryDefinitions.clear(); 115 } 116 117 if (defaultEnabledActivities == null) { 118 defaultEnabledActivities = new ArrayList (); 119 } else { 120 defaultEnabledActivities.clear(); 121 } 122 123 IConfigurationElement[] configurationElements = extensionRegistry 124 .getConfigurationElementsFor(Persistence.PACKAGE_FULL); 125 126 for (int i = 0; i < configurationElements.length; i++) { 127 IConfigurationElement configurationElement = configurationElements[i]; 128 String name = configurationElement.getName(); 129 130 if (Persistence.TAG_ACTIVITY_REQUIREMENT_BINDING.equals(name)) { 131 readActivityRequirementBindingDefinition(configurationElement); 132 } else if (Persistence.TAG_ACTIVITY.equals(name)) { 133 readActivityDefinition(configurationElement); 134 } else if (Persistence.TAG_ACTIVITY_PATTERN_BINDING.equals(name)) { 135 readActivityPatternBindingDefinition(configurationElement); 136 } else if (Persistence.TAG_CATEGORY_ACTIVITY_BINDING.equals(name)) { 137 readCategoryActivityBindingDefinition(configurationElement); 138 } else if (Persistence.TAG_CATEGORY.equals(name)) { 139 readCategoryDefinition(configurationElement); 140 } else if (Persistence.TAG_DEFAULT_ENABLEMENT.equals(name)) { 141 readDefaultEnablement(configurationElement); 142 } 143 } 144 145 boolean activityRegistryChanged = false; 146 147 if (!activityRequirementBindingDefinitions 148 .equals(super.activityRequirementBindingDefinitions)) { 149 super.activityRequirementBindingDefinitions = Collections 150 .unmodifiableList(activityRequirementBindingDefinitions); 151 activityRegistryChanged = true; 152 } 153 154 if (!activityDefinitions.equals(super.activityDefinitions)) { 155 super.activityDefinitions = Collections 156 .unmodifiableList(activityDefinitions); 157 activityRegistryChanged = true; 158 } 159 160 if (!activityPatternBindingDefinitions 161 .equals(super.activityPatternBindingDefinitions)) { 162 super.activityPatternBindingDefinitions = Collections 163 .unmodifiableList(activityPatternBindingDefinitions); 164 activityRegistryChanged = true; 165 } 166 167 if (!categoryActivityBindingDefinitions 168 .equals(super.categoryActivityBindingDefinitions)) { 169 super.categoryActivityBindingDefinitions = Collections 170 .unmodifiableList(categoryActivityBindingDefinitions); 171 activityRegistryChanged = true; 172 } 173 174 if (!categoryDefinitions.equals(super.categoryDefinitions)) { 175 super.categoryDefinitions = Collections 176 .unmodifiableList(categoryDefinitions); 177 activityRegistryChanged = true; 178 } 179 180 if (!defaultEnabledActivities.equals(super.defaultEnabledActivities)) { 181 super.defaultEnabledActivities = Collections 182 .unmodifiableList(defaultEnabledActivities); 183 activityRegistryChanged = true; 184 } 185 186 if (activityRegistryChanged) { 187 fireActivityRegistryChanged(); 188 } 189 } 190 191 private void readDefaultEnablement( 192 IConfigurationElement configurationElement) { 193 String enabledActivity = Persistence 194 .readDefaultEnablement(new ConfigurationElementMemento( 195 configurationElement)); 196 197 if (enabledActivity != null) { 198 defaultEnabledActivities.add(enabledActivity); 199 } 200 201 } 202 203 private void readActivityRequirementBindingDefinition( 204 IConfigurationElement configurationElement) { 205 ActivityRequirementBindingDefinition activityRequirementBindingDefinition = Persistence 206 .readActivityRequirementBindingDefinition( 207 new ConfigurationElementMemento(configurationElement), 208 getNamespace(configurationElement)); 209 210 if (activityRequirementBindingDefinition != null) { 211 activityRequirementBindingDefinitions 212 .add(activityRequirementBindingDefinition); 213 } 214 } 215 216 private void readActivityDefinition( 217 IConfigurationElement configurationElement) { 218 ActivityDefinition activityDefinition = Persistence 219 .readActivityDefinition(new ConfigurationElementMemento( 220 configurationElement), 221 getNamespace(configurationElement)); 222 223 if (activityDefinition != null) { 224 activityDefinitions.add(activityDefinition); 225 } 226 } 227 228 private void readActivityPatternBindingDefinition( 229 IConfigurationElement configurationElement) { 230 ActivityPatternBindingDefinition activityPatternBindingDefinition = Persistence 231 .readActivityPatternBindingDefinition( 232 new ConfigurationElementMemento(configurationElement), 233 getNamespace(configurationElement)); 234 235 if (activityPatternBindingDefinition != null) { 236 activityPatternBindingDefinitions 237 .add(activityPatternBindingDefinition); 238 } 239 } 240 241 private void readCategoryActivityBindingDefinition( 242 IConfigurationElement configurationElement) { 243 CategoryActivityBindingDefinition categoryActivityBindingDefinition = Persistence 244 .readCategoryActivityBindingDefinition( 245 new ConfigurationElementMemento(configurationElement), 246 getNamespace(configurationElement)); 247 248 if (categoryActivityBindingDefinition != null) { 249 categoryActivityBindingDefinitions 250 .add(categoryActivityBindingDefinition); 251 } 252 } 253 254 private void readCategoryDefinition( 255 IConfigurationElement configurationElement) { 256 CategoryDefinition categoryDefinition = Persistence 257 .readCategoryDefinition(new ConfigurationElementMemento( 258 configurationElement), 259 getNamespace(configurationElement)); 260 261 if (categoryDefinition != null) { 262 categoryDefinitions.add(categoryDefinition); 263 } 264 } 265 } 266 | Popular Tags |