1 11 12 package org.eclipse.ui.internal.contexts; 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 ExtensionContextRegistry extends AbstractContextRegistry { 28 private List contextContextBindingDefinitions; 29 private List contextDefinitions; 30 private IExtensionRegistry extensionRegistry; 31 32 ExtensionContextRegistry(IExtensionRegistry extensionRegistry) { 33 if (extensionRegistry == null) 34 throw new NullPointerException (); 35 36 this.extensionRegistry = extensionRegistry; 37 38 this 39 .extensionRegistry 40 .addRegistryChangeListener(new IRegistryChangeListener() { 41 public void registryChanged(IRegistryChangeEvent registryChangeEvent) { 42 IExtensionDelta[] extensionDeltas = 43 registryChangeEvent.getExtensionDeltas( 44 Persistence.PACKAGE_PREFIX, 45 Persistence.PACKAGE_BASE); 46 47 if (extensionDeltas.length != 0) 48 try { 49 load(); 50 } catch (IOException eIO) { 51 } 52 } 53 }); 54 55 try { 56 load(); 57 } catch (IOException eIO) { 58 } 59 } 60 61 private String getNamespace(IConfigurationElement configurationElement) { 62 String namespace = null; 63 64 if (configurationElement != null) { 65 IExtension extension = configurationElement.getDeclaringExtension(); 66 67 if (extension != null) 68 namespace = extension.getNamespace(); 69 } 70 71 return namespace; 72 } 73 74 private void load() throws IOException { 75 if (contextContextBindingDefinitions == null) 76 contextContextBindingDefinitions = new ArrayList (); 77 else 78 contextContextBindingDefinitions.clear(); 79 80 if (contextDefinitions == null) 81 contextDefinitions = new ArrayList (); 82 else 83 contextDefinitions.clear(); 84 85 IConfigurationElement[] deprecatedConfigurationElements = extensionRegistry.getConfigurationElementsFor("org.eclipse.ui.acceleratorScopes"); 88 for (int i = 0; i < deprecatedConfigurationElements.length; i++) { 89 IConfigurationElement deprecatedConfigurationElement = 90 deprecatedConfigurationElements[i]; 91 String name = deprecatedConfigurationElement.getName(); 92 93 if ("acceleratorScope".equals(name)) readContextDefinition(deprecatedConfigurationElement); 95 } 96 97 deprecatedConfigurationElements = extensionRegistry.getConfigurationElementsFor("org.eclipse.ui.commands"); 99 for (int i = 0; i < deprecatedConfigurationElements.length; i++) { 100 IConfigurationElement deprecatedConfigurationElement = 101 deprecatedConfigurationElements[i]; 102 String name = deprecatedConfigurationElement.getName(); 103 104 if ("scope".equals(name)) readContextDefinition(deprecatedConfigurationElement); 106 } 107 109 IConfigurationElement[] configurationElements = 110 extensionRegistry.getConfigurationElementsFor( 111 Persistence.PACKAGE_FULL); 112 113 for (int i = 0; i < configurationElements.length; i++) { 114 IConfigurationElement configurationElement = 115 configurationElements[i]; 116 String name = configurationElement.getName(); 117 118 if (Persistence.TAG_CONTEXT.equals(name)) 119 readContextDefinition(configurationElement); 120 } 121 122 boolean contextRegistryChanged = false; 123 124 if (!contextContextBindingDefinitions 125 .equals(super.contextContextBindingDefinitions)) { 126 super.contextContextBindingDefinitions = 127 Collections.unmodifiableList(contextContextBindingDefinitions); 128 contextRegistryChanged = true; 129 } 130 131 if (!contextDefinitions.equals(super.contextDefinitions)) { 132 super.contextDefinitions = 133 Collections.unmodifiableList(contextDefinitions); 134 contextRegistryChanged = true; 135 } 136 137 if (contextRegistryChanged) 138 fireContextRegistryChanged(); 139 } 140 141 private void readContextDefinition(IConfigurationElement configurationElement) { 142 ContextDefinition contextDefinition = 143 Persistence.readContextDefinition( 144 new ConfigurationElementMemento(configurationElement), 145 getNamespace(configurationElement)); 146 147 if (contextDefinition != null) 148 contextDefinitions.add(contextDefinition); 149 } 150 } 151 | Popular Tags |