1 11 12 package org.eclipse.ui.internal.menus; 13 14 import java.util.List ; 15 16 import org.eclipse.core.runtime.IConfigurationElement; 17 import org.eclipse.core.runtime.IExtensionDelta; 18 import org.eclipse.core.runtime.IExtensionRegistry; 19 import org.eclipse.core.runtime.IRegistryChangeEvent; 20 import org.eclipse.core.runtime.Platform; 21 import org.eclipse.ui.PlatformUI; 22 import org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants; 23 import org.eclipse.ui.internal.services.RegistryPersistence; 24 25 36 final class MenuPersistence extends RegistryPersistence { 37 38 39 private final WorkbenchMenuService menuService; 40 41 49 MenuPersistence(final WorkbenchMenuService workbenchMenuService) { 50 if (workbenchMenuService == null) { 51 throw new NullPointerException ("The menu service cannot be null"); } 53 54 this.menuService = workbenchMenuService; 55 } 56 57 public final void dispose() { 58 super.dispose(); 59 } 60 61 protected final boolean isChangeImportant(final IRegistryChangeEvent event) { 62 67 final IExtensionDelta[] menuDeltas = event.getExtensionDeltas( 68 PlatformUI.PLUGIN_ID, IWorkbenchRegistryConstants.PL_MENUS); 69 if (menuDeltas.length == 0) { 70 return false; 71 } 72 73 return true; 74 } 75 76 84 protected final void read() { 85 super.read(); 86 87 readTrimAdditions(); 89 90 readAdditions(); 92 } 93 94 98 public void readTrimAdditions() { 99 if (menuService == null) 100 return; 101 102 final IExtensionRegistry registry = Platform.getExtensionRegistry(); 103 final IConfigurationElement[] configElements = registry 104 .getConfigurationElementsFor(EXTENSION_MENUS); 105 106 for (int i = 0; i < configElements.length; i++) { 108 if (!TAG_GROUP.equals(configElements[i].getName())) 110 continue; 111 112 String id = configElements[i].getAttribute(IWorkbenchRegistryConstants.ATT_ID); 113 114 String uriSpec = "toolbar:" + id; if (configElements[i].getChildren(TAG_LOCATION).length > 0) { 117 IConfigurationElement location = configElements[i].getChildren(TAG_LOCATION)[0]; 118 if (location.getChildren(TAG_ORDER).length > 0) { 119 IConfigurationElement order = location.getChildren(TAG_ORDER)[0]; 120 121 String pos = order.getAttribute(IWorkbenchRegistryConstants.ATT_POSITION); 122 String relTo = order.getAttribute(IWorkbenchRegistryConstants.ATT_RELATIVE_TO); 123 uriSpec += "?" + pos + "=" + relTo; 125 MenuLocationURI uri = new MenuLocationURI("toolbar:" + relTo); List trimAdditions = menuService.getAdditionsForURI(uri); 129 130 uri = new MenuLocationURI(uriSpec); 135 trimAdditions.add(new TrimAdditionCacheEntry(configElements[i], uri, menuService)); 136 } 137 else { 138 MenuLocationURI uri = new MenuLocationURI(uriSpec); 140 141 menuService.getAdditionsForURI(uri); 143 } 144 } 145 } 146 } 147 148 public void readAdditions() { 149 final IExtensionRegistry registry = Platform.getExtensionRegistry(); 150 final IConfigurationElement[] menusExtensionPoint = registry 151 .getConfigurationElementsFor(EXTENSION_MENUS); 152 153 for (int i = 0; i < menusExtensionPoint.length; i++) { 155 if (PL_MENU_CONTRIBUTION.equals(menusExtensionPoint[i].getName())) { 156 String location = menusExtensionPoint[i] 158 .getAttribute(TAG_LOCATION_URI); 159 160 menuService.addContributionFactory(new MenuAdditionCacheEntry(menuService, 161 menusExtensionPoint[i], location, 162 menusExtensionPoint[i].getNamespaceIdentifier())); 163 } 164 } 165 } 166 } 167 | Popular Tags |