1 11 package org.eclipse.ui.internal.wizards; 12 13 import org.eclipse.core.runtime.IConfigurationElement; 14 import org.eclipse.core.runtime.IExtension; 15 import org.eclipse.core.runtime.IExtensionPoint; 16 import org.eclipse.core.runtime.Platform; 17 import org.eclipse.core.runtime.dynamichelpers.ExtensionTracker; 18 import org.eclipse.core.runtime.dynamichelpers.IExtensionChangeHandler; 19 import org.eclipse.core.runtime.dynamichelpers.IExtensionTracker; 20 import org.eclipse.ui.PlatformUI; 21 import org.eclipse.ui.internal.dialogs.WizardCollectionElement; 22 import org.eclipse.ui.internal.dialogs.WorkbenchWizardElement; 23 import org.eclipse.ui.internal.registry.WizardsRegistryReader; 24 import org.eclipse.ui.internal.util.Util; 25 import org.eclipse.ui.wizards.IWizardDescriptor; 26 27 32 public abstract class AbstractExtensionWizardRegistry extends 33 AbstractWizardRegistry implements IExtensionChangeHandler{ 34 35 38 public AbstractExtensionWizardRegistry() { 39 super(); 40 } 41 42 45 public void addExtension(IExtensionTracker tracker, IExtension extension) { 46 WizardsRegistryReader reader = new WizardsRegistryReader(getPlugin(), 47 getExtensionPoint()); 48 reader.setInitialCollection(getWizardElements()); 49 IConfigurationElement[] configurationElements = extension 50 .getConfigurationElements(); 51 for (int i = 0; i < configurationElements.length; i++) { 52 reader.readElement(configurationElements[i]); 53 } 54 setWizardElements(reader.getWizardElements()); 58 registerWizards(getWizardElements()); 61 62 WorkbenchWizardElement[] additionalPrimary = reader.getPrimaryWizards(); 64 if (additionalPrimary.length == 0) { 65 return; 66 } 67 IWizardDescriptor[] localPrimaryWizards = getPrimaryWizards(); 68 WorkbenchWizardElement[] newPrimary = new WorkbenchWizardElement[additionalPrimary.length 69 + localPrimaryWizards.length]; 70 System.arraycopy(localPrimaryWizards, 0, newPrimary, 0, 71 localPrimaryWizards.length); 72 System.arraycopy(additionalPrimary, 0, newPrimary, 73 localPrimaryWizards.length, additionalPrimary.length); 74 setPrimaryWizards(newPrimary); 75 } 76 77 80 public void dispose() { 81 super.dispose(); 82 PlatformUI.getWorkbench().getExtensionTracker() 83 .unregisterHandler(this); 84 } 85 86 91 protected void doInitialize() { 92 93 PlatformUI.getWorkbench().getExtensionTracker().registerHandler(this, ExtensionTracker.createExtensionPointFilter(getExtensionPointFilter())); 94 95 WizardsRegistryReader reader = new WizardsRegistryReader(getPlugin(), 96 getExtensionPoint()); 97 setWizardElements(reader.getWizardElements()); 98 setPrimaryWizards(reader.getPrimaryWizards()); 99 registerWizards(getWizardElements()); 100 } 101 102 108 protected abstract String getExtensionPoint(); 109 110 private IExtensionPoint getExtensionPointFilter() { 111 return Platform.getExtensionRegistry().getExtensionPoint(getPlugin(), 112 getExtensionPoint()); 113 } 114 115 120 protected abstract String getPlugin(); 121 122 130 private void register(IExtension extension, Object object) { 131 PlatformUI.getWorkbench().getExtensionTracker().registerObject( 132 extension, object, IExtensionTracker.REF_WEAK); 133 } 134 135 141 private void registerWizards(WizardCollectionElement collection) { 142 registerWizards(collection.getWorkbenchWizardElements()); 143 144 WizardCollectionElement[] collections = collection 145 .getCollectionElements(); 146 for (int i = 0; i < collections.length; i++) { 147 IConfigurationElement configurationElement = collections[i] 148 .getConfigurationElement(); 149 if (configurationElement != null) { 150 register(configurationElement.getDeclaringExtension(), 151 collections[i]); 152 } 153 registerWizards(collections[i]); 154 } 155 } 156 157 163 private void registerWizards(WorkbenchWizardElement[] wizards) { 164 for (int i = 0; i < wizards.length; i++) { 165 register(wizards[i].getConfigurationElement() 166 .getDeclaringExtension(), wizards[i]); 167 } 168 } 169 170 173 public void removeExtension(IExtension extension, Object [] objects) { 174 if (!extension.getExtensionPointUniqueIdentifier().equals( 175 getExtensionPointFilter().getUniqueIdentifier())) { 176 return; 177 } 178 for (int i = 0; i < objects.length; i++) { 179 Object object = objects[i]; 180 if (object instanceof WizardCollectionElement) { 181 WizardCollectionElement collection = (WizardCollectionElement) object; 183 collection.getParentCollection().remove(collection); 184 } else if (object instanceof WorkbenchWizardElement) { 185 WorkbenchWizardElement wizard = (WorkbenchWizardElement) object; 186 WizardCollectionElement parent = wizard.getCollectionElement(); 187 if (parent != null) { 188 parent.remove(wizard); 189 } 190 IWizardDescriptor[] primaryWizards = getPrimaryWizards(); 191 for (int j = 0; j < primaryWizards.length; j++) { 192 if (primaryWizards[j] == wizard) { 193 WorkbenchWizardElement[] newPrimary = new WorkbenchWizardElement[primaryWizards.length - 1]; 194 Util 195 .arrayCopyWithRemoval(primaryWizards, 196 newPrimary, j); 197 primaryWizards = newPrimary; 198 break; 199 } 200 } 201 setPrimaryWizards((WorkbenchWizardElement[]) primaryWizards); 202 } 203 } 204 } 205 } 206 | Popular Tags |