Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 171886 Details for
Bug 316303
[Compatibility] turn actionSets into MenuContributions
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
ActionSets v01 (draft)
actionSets-v01.txt (text/plain), 34.17 KB, created by
Paul Webster
on 2010-06-14 20:30:42 EDT
(
hide
)
Description:
ActionSets v01 (draft)
Filename:
MIME Type:
Creator:
Paul Webster
Created:
2010-06-14 20:30:42 EDT
Size:
34.17 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.ui.workbench >Index: Eclipse UI/org/eclipse/ui/internal/menus/ActionSet.java >=================================================================== >RCS file: Eclipse UI/org/eclipse/ui/internal/menus/ActionSet.java >diff -N Eclipse UI/org/eclipse/ui/internal/menus/ActionSet.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ Eclipse UI/org/eclipse/ui/internal/menus/ActionSet.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,133 @@ >+/******************************************************************************* >+ * Copyright (c) 2010 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ ******************************************************************************/ >+ >+package org.eclipse.ui.internal.menus; >+ >+import org.eclipse.core.runtime.IConfigurationElement; >+import org.eclipse.core.runtime.Path; >+import org.eclipse.e4.core.contexts.IEclipseContext; >+import org.eclipse.e4.ui.model.application.MApplication; >+import org.eclipse.e4.ui.model.application.ui.MElementContainer; >+import org.eclipse.e4.ui.model.application.ui.menu.MMenu; >+import org.eclipse.e4.ui.model.application.ui.menu.MMenuContribution; >+import org.eclipse.e4.ui.model.application.ui.menu.MMenuElement; >+import org.eclipse.e4.ui.model.application.ui.menu.impl.MenuFactoryImpl; >+import org.eclipse.ui.IWorkbenchActionConstants; >+import org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants; >+ >+/** >+ * @since e4 >+ * >+ */ >+public class ActionSet { >+ >+ private IConfigurationElement configElement; >+ private MMenuContribution menuContribution; >+ private MApplication application; >+ >+ public ActionSet(MApplication application, IEclipseContext appContext, >+ IConfigurationElement element) { >+ this.application = application; >+ this.configElement = element; >+ } >+ >+ public void addToModel() { >+ menuContribution = MenuFactoryImpl.eINSTANCE.createMenuContribution(); >+ String idContrib = MenuHelper.getId(configElement); >+ if (idContrib != null && idContrib.length() > 0) { >+ menuContribution.setElementId(idContrib); >+ } >+ System.out.println("actionSet: " + idContrib); //$NON-NLS-1$ >+ IConfigurationElement[] menus = configElement >+ .getChildren(IWorkbenchRegistryConstants.TAG_MENU); >+ for (IConfigurationElement element : menus) { >+ addMenu(menuContribution, element); >+ } >+ } >+ >+ private void addMenu(MElementContainer<MMenuElement> menu, IConfigurationElement element) { >+ final String elementId = MenuHelper.getId(element); >+ String path = MenuHelper.getPath(element); >+ if (path == null || path.length() == 0) { >+ path = IWorkbenchActionConstants.MB_ADDITIONS; >+ } >+ Path menuPath = new Path(path); >+ MElementContainer<MMenuElement> parentMenu = menu; >+ if (menuPath.segmentCount() > 1) { >+ parentMenu = findMenuFromPath(menu, menuPath, 0); >+ } >+ if (parentMenu == menu) { >+ System.err.println("Using parent menu for menu " + elementId + ':' + path); //$NON-NLS-1$ >+ } >+ if (parentMenu == null) { >+ System.err.println("Unable to find group for menu " + elementId + ':' + path); //$NON-NLS-1$ >+ return; >+ } >+ String id = MenuHelper.getId(element); >+ MMenu item = null; >+ final int itemIdx = MenuHelper.indexForId(parentMenu, id); >+ if (itemIdx == -1) { >+ int idx = MenuHelper.indexForId(parentMenu, menuPath.lastSegment()); >+ if (idx == -1) { >+ idx = MenuHelper.indexForId(parentMenu, IWorkbenchActionConstants.MB_ADDITIONS); >+ } >+ if (idx == -1) { >+ System.err.println("Failed to find group for menu " + elementId + ':' + path); //$NON-NLS-1$ >+ return; >+ } >+ item = MenuHelper.createMenuAddition(element); >+ parentMenu.getChildren().add(idx + 1, item); >+ } else { >+ item = (MMenu) parentMenu.getChildren().get(itemIdx); >+ } >+ processGroups(item, element); >+ } >+ >+ private void processGroups(MMenu menu, IConfigurationElement element) { >+ IConfigurationElement[] children = element.getChildren(); >+ for (IConfigurationElement sepAddition : children) { >+ String name = sepAddition.getAttribute(IWorkbenchRegistryConstants.ATT_NAME); >+ if (MenuHelper.indexForId(menu, name) == -1) { >+ MMenuElement sep = MenuFactoryImpl.eINSTANCE.createMenuSeparator(); >+ sep.setElementId(name); >+ if (!MenuHelper.isSeparatorVisible(sepAddition)) { >+ sep.setVisible(false); >+ } >+ menu.getChildren().add(sep); >+ } >+ } >+ } >+ >+ private MElementContainer<MMenuElement> findMenuFromPath(MElementContainer<MMenuElement> menu, >+ Path menuPath, int segment) { >+ int idx = MenuHelper.indexForId(menu, menuPath.segment(segment)); >+ if (idx == -1) { >+ if (segment + 1 < menuPath.segmentCount() || !menuPath.hasTrailingSeparator()) { >+ return null; >+ } >+ return menu; >+ } >+ MElementContainer<MMenuElement> item = (MElementContainer<MMenuElement>) menu.getChildren() >+ .get(idx); >+ if (item.getChildren().size() == 0) { >+ if (segment + 1 == menuPath.segmentCount()) { >+ return menu; >+ } else { >+ return null; >+ } >+ } >+ return findMenuFromPath(item, menuPath, segment + 1); >+ } >+ >+ public void dispose() { >+ application.getMenuContributions().remove(menuContribution); >+ } >+} >Index: Eclipse UI/org/eclipse/ui/internal/menus/MenuAdditionCacheEntry.java >=================================================================== >RCS file: /cvsroot/eclipse/e4/org.eclipse.e4.compatibility/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/menus/MenuAdditionCacheEntry.java,v >retrieving revision 1.6 >diff -u -r1.6 MenuAdditionCacheEntry.java >--- Eclipse UI/org/eclipse/ui/internal/menus/MenuAdditionCacheEntry.java 11 Jun 2010 00:41:30 -0000 1.6 >+++ Eclipse UI/org/eclipse/ui/internal/menus/MenuAdditionCacheEntry.java 15 Jun 2010 00:28:31 -0000 >@@ -12,38 +12,21 @@ > > package org.eclipse.ui.internal.menus; > >-import java.net.MalformedURLException; >-import java.net.URL; >-import java.util.HashMap; > import java.util.Map; >-import org.eclipse.core.expressions.Expression; >-import org.eclipse.core.expressions.ExpressionConverter; >-import org.eclipse.core.runtime.CoreException; >-import org.eclipse.core.runtime.FileLocator; > import org.eclipse.core.runtime.IConfigurationElement; >-import org.eclipse.core.runtime.InvalidRegistryObjectException; > import org.eclipse.e4.core.contexts.IEclipseContext; > import org.eclipse.e4.ui.model.application.MApplication; >-import org.eclipse.e4.ui.model.application.commands.MCommand; > import org.eclipse.e4.ui.model.application.commands.MParameter; > import org.eclipse.e4.ui.model.application.commands.impl.CommandsFactoryImpl; >-import org.eclipse.e4.ui.model.application.ui.MCoreExpression; > import org.eclipse.e4.ui.model.application.ui.MElementContainer; >-import org.eclipse.e4.ui.model.application.ui.MExpression; >-import org.eclipse.e4.ui.model.application.ui.impl.UiFactoryImpl; >-import org.eclipse.e4.ui.model.application.ui.menu.ItemType; > import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem; > import org.eclipse.e4.ui.model.application.ui.menu.MMenu; > import org.eclipse.e4.ui.model.application.ui.menu.MMenuContribution; > import org.eclipse.e4.ui.model.application.ui.menu.MMenuElement; > import org.eclipse.e4.ui.model.application.ui.menu.impl.MenuFactoryImpl; > import org.eclipse.e4.ui.workbench.swt.modeling.MenuServiceFilter; >-import org.eclipse.jface.resource.ImageDescriptor; > import org.eclipse.ui.internal.e4.compatibility.E4Util; > import org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants; >-import org.eclipse.ui.internal.util.Util; >-import org.eclipse.ui.menus.CommandContributionItem; >-import org.eclipse.ui.plugin.AbstractUIPlugin; > > /** > * @since 3.3 >@@ -116,48 +99,25 @@ > return null; > } > >- MMenu element = MenuFactoryImpl.eINSTANCE.createMenu(); >- String id = getId(menuAddition); >- element.setElementId(id); >- String text = getLabel(menuAddition); >- String mnemonic = getMnemonic(menuAddition); >- if (text != null && mnemonic != null) { >- E4Util.unsupported("mnemonic processing in menus: " + id + ": " + text); //$NON-NLS-1$//$NON-NLS-2$ >- int idx = text.indexOf(mnemonic); >- if (idx != -1) { >- text = text.substring(0, idx) + '&' + text.substring(idx); >- } >- } >- element.setIconURI(getIconUrl(menuAddition, IWorkbenchRegistryConstants.ATT_ICON)); >- element.setLabel(Util.safeString(text)); >- >- return element; >+ return MenuHelper.createMenuAddition(menuAddition); > } > > private MMenuElement createSeparatorAddition(final IConfigurationElement sepAddition) { >- String name = getName(sepAddition); >+ String name = MenuHelper.getName(sepAddition); > MMenuElement element = MenuFactoryImpl.eINSTANCE.createMenuSeparator(); > element.setElementId(name); >- if (!isSeparatorVisible(sepAddition)) { >+ if (!MenuHelper.isSeparatorVisible(sepAddition)) { > element.setVisible(false); > } > return element; > } > >- private MCommand findCommand(String id) { >- for (MCommand cmd : application.getCommands()) { >- if (id.equals(cmd.getElementId())) { >- return cmd; >- } >- } >- return null; >- } >- > private MMenuElement createCommandAddition(final IConfigurationElement commandAddition) { > MHandledMenuItem item = MenuFactoryImpl.eINSTANCE.createHandledMenuItem(); >- item.setElementId(getId(commandAddition)); >- item.setCommand(findCommand(getCommandId(commandAddition))); >- Map parms = getParameters(commandAddition); >+ item.setElementId(MenuHelper.getId(commandAddition)); >+ item.setCommand(MenuHelper.getCommandById(application, >+ MenuHelper.getCommandId(commandAddition))); >+ Map parms = MenuHelper.getParameters(commandAddition); > for (Object obj : parms.entrySet()) { > Map.Entry e = (Map.Entry) obj; > MParameter parm = CommandsFactoryImpl.eINSTANCE.createParameter(); >@@ -165,217 +125,23 @@ > parm.setValue(e.getValue().toString()); > item.getParameters().add(parm); > } >- item.setIconURI(getIconUrl(commandAddition, IWorkbenchRegistryConstants.ATT_ICON)); >- item.setLabel(getLabel(commandAddition)); >- item.setMnemonics(getMnemonic(commandAddition)); >- item.setTooltip(getTooltip(commandAddition)); >- item.setType(getStyle(commandAddition)); >- item.setVisibleWhen(getVisibleWhen(commandAddition)); >+ item.setIconURI(MenuHelper >+ .getIconUrl(commandAddition, IWorkbenchRegistryConstants.ATT_ICON)); >+ item.setLabel(MenuHelper.getLabel(commandAddition)); >+ item.setMnemonics(MenuHelper.getMnemonic(commandAddition)); >+ item.setTooltip(MenuHelper.getTooltip(commandAddition)); >+ item.setType(MenuHelper.getStyle(commandAddition)); >+ item.setVisibleWhen(MenuHelper.getVisibleWhen(commandAddition)); > return item; > } > >- /** >- * @param commandAddition >- * @return >- */ >- private MExpression getVisibleWhen(IConfigurationElement commandAddition) { >- try { >- IConfigurationElement[] visibleConfig = configElement >- .getChildren(IWorkbenchRegistryConstants.TAG_VISIBLE_WHEN); >- if (visibleConfig.length > 0 && visibleConfig.length < 2) { >- IConfigurationElement[] visibleChild = visibleConfig[0].getChildren(); >- if (visibleChild.length > 0) { >- Expression visWhen = ExpressionConverter.getDefault().perform(visibleChild[0]); >- MCoreExpression exp = UiFactoryImpl.eINSTANCE.createCoreExpression(); >- exp.setCoreExpressionId("programmatic.value"); //$NON-NLS-1$ >- exp.setCoreExpression(visWhen); >- return exp; >- // visWhenMap.put(configElement, visWhen); >- } >- } >- } catch (InvalidRegistryObjectException e) { >- // visWhenMap.put(configElement, null); >- // TODO Auto-generated catch block >- e.printStackTrace(); >- } catch (CoreException e) { >- // visWhenMap.put(configElement, null); >- // TODO Auto-generated catch block >- e.printStackTrace(); >- } >- return null; >- } >- >- /** >- * @param element >- * the configuration element >- * @return <code>true</code> if the checkEnabled is <code>true</code>. >- */ >- static boolean getVisibleEnabled(IConfigurationElement element) { >- IConfigurationElement[] children = element >- .getChildren(IWorkbenchRegistryConstants.TAG_VISIBLE_WHEN); >- String checkEnabled = null; >- >- if (children.length > 0) { >- checkEnabled = children[0].getAttribute(IWorkbenchRegistryConstants.ATT_CHECK_ENABLED); >- } >- >- return checkEnabled != null && checkEnabled.equalsIgnoreCase("true"); //$NON-NLS-1$ >- } >- >- /* >- * Support Utilities >- */ >- public static String getId(IConfigurationElement element) { >- String id = element.getAttribute(IWorkbenchRegistryConstants.ATT_ID); >- >- // For sub-menu management -all- items must be id'd so enforce this >- // here (we could optimize by checking the 'name' of the config >- // element == "menu" >- if (id == null || id.length() == 0) { >- id = getCommandId(element); >- } >- if (id == null || id.length() == 0) { >- id = element.toString(); >- } >- >- return id; >- } >- >- static String getName(IConfigurationElement element) { >- return element.getAttribute(IWorkbenchRegistryConstants.ATT_NAME); >- } >- >- static int getMode(IConfigurationElement element) { >- if ("FORCE_TEXT".equals(element.getAttribute(IWorkbenchRegistryConstants.ATT_MODE))) { //$NON-NLS-1$ >- return CommandContributionItem.MODE_FORCE_TEXT; >- } >- return 0; >- } >- >- static String getLabel(IConfigurationElement element) { >- return element.getAttribute(IWorkbenchRegistryConstants.ATT_LABEL); >- } >- >- static String getMnemonic(IConfigurationElement element) { >- return element.getAttribute(IWorkbenchRegistryConstants.ATT_MNEMONIC); >- } >- >- static String getTooltip(IConfigurationElement element) { >- return element.getAttribute(IWorkbenchRegistryConstants.ATT_TOOLTIP); >- } >- >- static String getIconPath(IConfigurationElement element) { >- return element.getAttribute(IWorkbenchRegistryConstants.ATT_ICON); >- } >- >- static String getDisabledIconPath(IConfigurationElement element) { >- return element.getAttribute(IWorkbenchRegistryConstants.ATT_DISABLEDICON); >- } >- >- static String getHoverIconPath(IConfigurationElement element) { >- return element.getAttribute(IWorkbenchRegistryConstants.ATT_HOVERICON); >- } >- >- static String getIconUrl(IConfigurationElement element, String attr) { >- String extendingPluginId = element.getDeclaringExtension().getContributor().getName(); >- >- String iconPath = element.getAttribute(attr); >- if (iconPath == null) { >- return null; >- } >- if (!iconPath.startsWith("platform:")) { //$NON-NLS-1$ >- iconPath = "platform:/plugin/" + extendingPluginId + "/" + iconPath; //$NON-NLS-1$//$NON-NLS-2$ >- } >- URL url = null; >- try { >- url = FileLocator.find(new URL(iconPath)); >- } catch (MalformedURLException e) { >- // TODO Auto-generated catch block >- e.printStackTrace(); >- } >- return url == null ? null : url.toString(); >- } >- >- static ImageDescriptor getDisabledIconDescriptor(IConfigurationElement element) { >- String extendingPluginId = element.getDeclaringExtension().getContributor().getName(); >- >- String iconPath = getDisabledIconPath(element); >- if (iconPath != null) { >- return AbstractUIPlugin.imageDescriptorFromPlugin(extendingPluginId, iconPath); >- } >- return null; >- } >- >- static ImageDescriptor getHoverIconDescriptor(IConfigurationElement element) { >- String extendingPluginId = element.getDeclaringExtension().getContributor().getName(); >- >- String iconPath = getHoverIconPath(element); >- if (iconPath != null) { >- return AbstractUIPlugin.imageDescriptorFromPlugin(extendingPluginId, iconPath); >- } >- return null; >- } >- >- static String getHelpContextId(IConfigurationElement element) { >- return element.getAttribute(IWorkbenchRegistryConstants.ATT_HELP_CONTEXT_ID); >- } >- >- public static boolean isSeparatorVisible(IConfigurationElement element) { >- String val = element.getAttribute(IWorkbenchRegistryConstants.ATT_VISIBLE); >- return Boolean.valueOf(val).booleanValue(); >- } >- >- public static String getClassSpec(IConfigurationElement element) { >- return element.getAttribute(IWorkbenchRegistryConstants.ATT_CLASS); >- } >- >- public static String getCommandId(IConfigurationElement element) { >- return element.getAttribute(IWorkbenchRegistryConstants.ATT_COMMAND_ID); >- } >- >- private ItemType getStyle(IConfigurationElement element) { >- String style = element.getAttribute(IWorkbenchRegistryConstants.ATT_STYLE); >- if (style == null || style.length() == 0) { >- return ItemType.PUSH; >- } >- if (IWorkbenchRegistryConstants.STYLE_TOGGLE.equals(style)) { >- return ItemType.CHECK; >- } >- if (IWorkbenchRegistryConstants.STYLE_RADIO.equals(style)) { >- return ItemType.RADIO; >- } >- if (IWorkbenchRegistryConstants.STYLE_PULLDOWN.equals(style)) { >- E4Util.unsupported("Failed to get style for " + IWorkbenchRegistryConstants.STYLE_PULLDOWN); //$NON-NLS-1$ >- // return CommandContributionItem.STYLE_PULLDOWN; >- } >- return ItemType.PUSH; >- } >- >- /** >- * @param element >- * @return A map of parameters names to parameter values. All Strings. The >- * map may be empty. >- */ >- public static Map getParameters(IConfigurationElement element) { >- HashMap map = new HashMap(); >- IConfigurationElement[] parameters = element >- .getChildren(IWorkbenchRegistryConstants.TAG_PARAMETER); >- for (int i = 0; i < parameters.length; i++) { >- String name = parameters[i].getAttribute(IWorkbenchRegistryConstants.ATT_NAME); >- String value = parameters[i].getAttribute(IWorkbenchRegistryConstants.ATT_VALUE); >- if (name != null && value != null) { >- map.put(name, value); >- } >- } >- return map; >- } > > private void addChildren(final MElementContainer<MMenuElement> container, > IConfigurationElement parent, String filter) { > IConfigurationElement[] items = parent.getChildren(); > for (int i = 0; i < items.length; i++) { > String itemType = items[i].getName(); >- String id = getId(items[i]); >+ String id = MenuHelper.getId(items[i]); > > if (IWorkbenchRegistryConstants.TAG_COMMAND.equals(itemType)) { > MMenuElement element = createCommandAddition(items[i]); >@@ -417,7 +183,7 @@ > return; > } > menuContribution = MenuFactoryImpl.eINSTANCE.createMenuContribution(); >- String idContrib = getId(configElement); >+ String idContrib = MenuHelper.getId(configElement); > if (idContrib != null && idContrib.length() > 0) { > menuContribution.setElementId(idContrib); > } >@@ -437,6 +203,7 @@ > filter = MenuServiceFilter.MC_POPUP; > } > menuContribution.getTags().add(filter); >+ menuContribution.setVisibleWhen(MenuHelper.getVisibleWhen(configElement)); > addChildren(menuContribution, configElement, filter); > application.getMenuContributions().add(menuContribution); > } >Index: Eclipse UI/org/eclipse/ui/internal/menus/MenuHelper.java >=================================================================== >RCS file: Eclipse UI/org/eclipse/ui/internal/menus/MenuHelper.java >diff -N Eclipse UI/org/eclipse/ui/internal/menus/MenuHelper.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ Eclipse UI/org/eclipse/ui/internal/menus/MenuHelper.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,318 @@ >+package org.eclipse.ui.internal.menus; >+ >+import java.lang.reflect.Field; >+import java.net.MalformedURLException; >+import java.net.URL; >+import java.util.HashMap; >+import java.util.List; >+import java.util.Map; >+import org.eclipse.core.expressions.Expression; >+import org.eclipse.core.expressions.ExpressionConverter; >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.FileLocator; >+import org.eclipse.core.runtime.IConfigurationElement; >+import org.eclipse.core.runtime.InvalidRegistryObjectException; >+import org.eclipse.e4.ui.model.application.MApplication; >+import org.eclipse.e4.ui.model.application.commands.MCommand; >+import org.eclipse.e4.ui.model.application.ui.MCoreExpression; >+import org.eclipse.e4.ui.model.application.ui.MElementContainer; >+import org.eclipse.e4.ui.model.application.ui.MExpression; >+import org.eclipse.e4.ui.model.application.ui.impl.UiFactoryImpl; >+import org.eclipse.e4.ui.model.application.ui.menu.ItemType; >+import org.eclipse.e4.ui.model.application.ui.menu.MMenu; >+import org.eclipse.e4.ui.model.application.ui.menu.MMenuElement; >+import org.eclipse.e4.ui.model.application.ui.menu.impl.MenuFactoryImpl; >+import org.eclipse.jface.resource.ImageDescriptor; >+import org.eclipse.ui.internal.e4.compatibility.E4Util; >+import org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants; >+import org.eclipse.ui.internal.util.Util; >+import org.eclipse.ui.menus.CommandContributionItem; >+ >+public class MenuHelper { >+ >+ public static final String ACTION_SET_CMD_PREFIX = "AS::"; //$NON-NLS-1$ >+ public static final String MAIN_MENU_ID = "org.eclipse.ui.main.menu"; //$NON-NLS-1$ >+ private static Field urlField; >+ >+ >+ public static int indexForId(MElementContainer<MMenuElement> parentMenu, String id) { >+ if (id == null || id.length() == 0) { >+ return -1; >+ } >+ int i = 0; >+ for (MMenuElement item : parentMenu.getChildren()) { >+ if (id.equals(item.getElementId())) { >+ return i; >+ } >+ i++; >+ } >+ return -1; >+ } >+ >+ public static String getActionSetCommandId(IConfigurationElement element) { >+ String id = MenuHelper.getDefinitionId(element); >+ if (id != null) { >+ return id; >+ } >+ id = MenuHelper.getId(element); >+ String actionSetId = null; >+ Object obj = element.getParent(); >+ while (obj instanceof IConfigurationElement && actionSetId == null) { >+ IConfigurationElement parent = (IConfigurationElement) obj; >+ if (parent.getName().equals( >+ IWorkbenchRegistryConstants.TAG_ACTION_SET)) { >+ actionSetId = MenuHelper.getId(parent); >+ } >+ obj = parent.getParent(); >+ } >+ return ACTION_SET_CMD_PREFIX + actionSetId + '/' + id; >+ } >+ >+ /** >+ * @param imageDescriptor >+ * @return >+ */ >+ public static String getImageUrl(ImageDescriptor imageDescriptor) { >+ if (imageDescriptor == null) >+ return null; >+ Class idc = imageDescriptor.getClass(); >+ if (idc.getName().endsWith("URLImageDescriptor")) { //$NON-NLS-1$ >+ URL url = getUrl(idc, imageDescriptor); >+ return url.toExternalForm(); >+ } >+ return null; >+ } >+ >+ private static URL getUrl(Class idc, ImageDescriptor imageDescriptor) { >+ try { >+ if (urlField == null) { >+ urlField = idc.getDeclaredField("url"); //$NON-NLS-1$ >+ urlField.setAccessible(true); >+ } >+ return (URL) urlField.get(imageDescriptor); >+ } catch (SecurityException e) { >+ // TODO Auto-generated catch block >+ e.printStackTrace(); >+ } catch (NoSuchFieldException e) { >+ // TODO Auto-generated catch block >+ e.printStackTrace(); >+ } catch (IllegalArgumentException e) { >+ // TODO Auto-generated catch block >+ e.printStackTrace(); >+ } catch (IllegalAccessException e) { >+ // TODO Auto-generated catch block >+ e.printStackTrace(); >+ } >+ return null; >+ } >+ >+ static MCommand getCommandById(MApplication app, String cmdId) { >+ final List<MCommand> cmds = app.getCommands(); >+ for (MCommand cmd : cmds) { >+ if (cmdId.equals(cmd.getElementId())) { >+ return cmd; >+ } >+ } >+ return null; >+ } >+ >+ /** >+ * @param element >+ * the configuration element >+ * @return <code>true</code> if the checkEnabled is <code>true</code>. >+ */ >+ static boolean getVisibleEnabled(IConfigurationElement element) { >+ IConfigurationElement[] children = element >+ .getChildren(IWorkbenchRegistryConstants.TAG_VISIBLE_WHEN); >+ String checkEnabled = null; >+ >+ if (children.length > 0) { >+ checkEnabled = children[0].getAttribute(IWorkbenchRegistryConstants.ATT_CHECK_ENABLED); >+ } >+ >+ return checkEnabled != null && checkEnabled.equalsIgnoreCase("true"); //$NON-NLS-1$ >+ } >+ >+ static MExpression getVisibleWhen(IConfigurationElement commandAddition) { >+ try { >+ IConfigurationElement[] visibleConfig = commandAddition >+ .getChildren(IWorkbenchRegistryConstants.TAG_VISIBLE_WHEN); >+ if (visibleConfig.length > 0 && visibleConfig.length < 2) { >+ IConfigurationElement[] visibleChild = visibleConfig[0].getChildren(); >+ if (visibleChild.length > 0) { >+ Expression visWhen = ExpressionConverter.getDefault().perform(visibleChild[0]); >+ MCoreExpression exp = UiFactoryImpl.eINSTANCE.createCoreExpression(); >+ exp.setCoreExpressionId("programmatic.value"); //$NON-NLS-1$ >+ exp.setCoreExpression(visWhen); >+ return exp; >+ // visWhenMap.put(configElement, visWhen); >+ } >+ } >+ } catch (InvalidRegistryObjectException e) { >+ // visWhenMap.put(configElement, null); >+ // TODO Auto-generated catch block >+ e.printStackTrace(); >+ } catch (CoreException e) { >+ // visWhenMap.put(configElement, null); >+ // TODO Auto-generated catch block >+ e.printStackTrace(); >+ } >+ return null; >+ } >+ >+ /* >+ * Support Utilities >+ */ >+ public static String getId(IConfigurationElement element) { >+ String id = element.getAttribute(IWorkbenchRegistryConstants.ATT_ID); >+ >+ // For sub-menu management -all- items must be id'd so enforce this >+ // here (we could optimize by checking the 'name' of the config >+ // element == "menu" >+ if (id == null || id.length() == 0) { >+ id = getCommandId(element); >+ } >+ if (id == null || id.length() == 0) { >+ id = element.toString(); >+ } >+ >+ return id; >+ } >+ >+ static String getName(IConfigurationElement element) { >+ return element.getAttribute(IWorkbenchRegistryConstants.ATT_NAME); >+ } >+ >+ static int getMode(IConfigurationElement element) { >+ if ("FORCE_TEXT".equals(element.getAttribute(IWorkbenchRegistryConstants.ATT_MODE))) { //$NON-NLS-1$ >+ return CommandContributionItem.MODE_FORCE_TEXT; >+ } >+ return 0; >+ } >+ >+ static String getLabel(IConfigurationElement element) { >+ return element.getAttribute(IWorkbenchRegistryConstants.ATT_LABEL); >+ } >+ >+ static String getPath(IConfigurationElement element) { >+ return element.getAttribute(IWorkbenchRegistryConstants.ATT_PATH); >+ } >+ >+ static String getMnemonic(IConfigurationElement element) { >+ return element.getAttribute(IWorkbenchRegistryConstants.ATT_MNEMONIC); >+ } >+ >+ static String getTooltip(IConfigurationElement element) { >+ return element.getAttribute(IWorkbenchRegistryConstants.ATT_TOOLTIP); >+ } >+ >+ static String getIconPath(IConfigurationElement element) { >+ return element.getAttribute(IWorkbenchRegistryConstants.ATT_ICON); >+ } >+ >+ static String getDisabledIconPath(IConfigurationElement element) { >+ return element.getAttribute(IWorkbenchRegistryConstants.ATT_DISABLEDICON); >+ } >+ >+ static String getHoverIconPath(IConfigurationElement element) { >+ return element.getAttribute(IWorkbenchRegistryConstants.ATT_HOVERICON); >+ } >+ >+ static String getIconUrl(IConfigurationElement element, String attr) { >+ String extendingPluginId = element.getDeclaringExtension().getContributor().getName(); >+ >+ String iconPath = element.getAttribute(attr); >+ if (iconPath == null) { >+ return null; >+ } >+ if (!iconPath.startsWith("platform:")) { //$NON-NLS-1$ >+ iconPath = "platform:/plugin/" + extendingPluginId + "/" + iconPath; //$NON-NLS-1$//$NON-NLS-2$ >+ } >+ URL url = null; >+ try { >+ url = FileLocator.find(new URL(iconPath)); >+ } catch (MalformedURLException e) { >+ // TODO Auto-generated catch block >+ e.printStackTrace(); >+ } >+ return url == null ? null : url.toString(); >+ } >+ >+ static String getHelpContextId(IConfigurationElement element) { >+ return element.getAttribute(IWorkbenchRegistryConstants.ATT_HELP_CONTEXT_ID); >+ } >+ >+ public static boolean isSeparatorVisible(IConfigurationElement element) { >+ String val = element.getAttribute(IWorkbenchRegistryConstants.ATT_VISIBLE); >+ return Boolean.valueOf(val).booleanValue(); >+ } >+ >+ public static String getClassSpec(IConfigurationElement element) { >+ return element.getAttribute(IWorkbenchRegistryConstants.ATT_CLASS); >+ } >+ >+ public static String getCommandId(IConfigurationElement element) { >+ return element.getAttribute(IWorkbenchRegistryConstants.ATT_COMMAND_ID); >+ } >+ >+ public static ItemType getStyle(IConfigurationElement element) { >+ String style = element.getAttribute(IWorkbenchRegistryConstants.ATT_STYLE); >+ if (style == null || style.length() == 0) { >+ return ItemType.PUSH; >+ } >+ if (IWorkbenchRegistryConstants.STYLE_TOGGLE.equals(style)) { >+ return ItemType.CHECK; >+ } >+ if (IWorkbenchRegistryConstants.STYLE_RADIO.equals(style)) { >+ return ItemType.RADIO; >+ } >+ if (IWorkbenchRegistryConstants.STYLE_PULLDOWN.equals(style)) { >+ E4Util.unsupported("Failed to get style for " + IWorkbenchRegistryConstants.STYLE_PULLDOWN); //$NON-NLS-1$ >+ // return CommandContributionItem.STYLE_PULLDOWN; >+ } >+ return ItemType.PUSH; >+ } >+ >+ public static boolean getRetarget(IConfigurationElement element) { >+ String r = element.getAttribute(IWorkbenchRegistryConstants.ATT_RETARGET); >+ return Boolean.valueOf(r); >+ } >+ >+ public static String getDefinitionId(IConfigurationElement element) { >+ return element.getAttribute(IWorkbenchRegistryConstants.ATT_DEFINITION_ID); >+ } >+ >+ public static Map<String, String> getParameters(IConfigurationElement element) { >+ HashMap<String, String> map = new HashMap<String, String>(); >+ IConfigurationElement[] parameters = element >+ .getChildren(IWorkbenchRegistryConstants.TAG_PARAMETER); >+ for (int i = 0; i < parameters.length; i++) { >+ String name = parameters[i].getAttribute(IWorkbenchRegistryConstants.ATT_NAME); >+ String value = parameters[i].getAttribute(IWorkbenchRegistryConstants.ATT_VALUE); >+ if (name != null && value != null) { >+ map.put(name, value); >+ } >+ } >+ return map; >+ } >+ >+ public static MMenu createMenuAddition(IConfigurationElement menuAddition) { >+ MMenu element = MenuFactoryImpl.eINSTANCE.createMenu(); >+ String id = MenuHelper.getId(menuAddition); >+ element.setElementId(id); >+ String text = MenuHelper.getLabel(menuAddition); >+ String mnemonic = MenuHelper.getMnemonic(menuAddition); >+ if (text != null && mnemonic != null) { >+ E4Util.unsupported("mnemonic processing in menus: " + id + ": " + text); //$NON-NLS-1$//$NON-NLS-2$ >+ int idx = text.indexOf(mnemonic); >+ if (idx != -1) { >+ text = text.substring(0, idx) + '&' + text.substring(idx); >+ } >+ } >+ element.setIconURI(MenuHelper >+ .getIconUrl(menuAddition, IWorkbenchRegistryConstants.ATT_ICON)); >+ element.setLabel(Util.safeString(text)); >+ >+ return element; >+ } >+} >Index: Eclipse UI/org/eclipse/ui/internal/menus/MenuPersistence.java >=================================================================== >RCS file: /cvsroot/eclipse/e4/org.eclipse.e4.compatibility/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/menus/MenuPersistence.java,v >retrieving revision 1.3 >diff -u -r1.3 MenuPersistence.java >--- Eclipse UI/org/eclipse/ui/internal/menus/MenuPersistence.java 9 Jun 2010 18:31:31 -0000 1.3 >+++ Eclipse UI/org/eclipse/ui/internal/menus/MenuPersistence.java 15 Jun 2010 00:28:31 -0000 >@@ -12,6 +12,7 @@ > package org.eclipse.ui.internal.menus; > > import java.util.ArrayList; >+import java.util.Arrays; > import java.util.Collections; > import java.util.Comparator; > import java.util.Iterator; >@@ -43,6 +44,7 @@ > private MApplication application; > private IEclipseContext appContext; > private ArrayList<MenuAdditionCacheEntry> contributions = new ArrayList<MenuAdditionCacheEntry>(); >+ private ArrayList<ActionSet> actionContributions = new ArrayList<ActionSet>(); > > /** > * Constructs a new instance of {@link MenuPersistence}. >@@ -63,6 +65,10 @@ > mc.dispose(); > } > contributions.clear(); >+ for (ActionSet as : actionContributions) { >+ as.dispose(); >+ } >+ actionContributions.clear(); > super.dispose(); > } > >@@ -101,6 +107,9 @@ > > // read the 3.3 menu additions > readAdditions(); >+ >+ // convert actionSets to MenuContributions >+ readActionSets(); > } > > // >@@ -167,7 +176,7 @@ > > public void readAdditions() { > final IExtensionRegistry registry = Platform.getExtensionRegistry(); >- ArrayList configElements = new ArrayList(); >+ ArrayList<IConfigurationElement> configElements = new ArrayList<IConfigurationElement>(); > > final IConfigurationElement[] menusExtensionPoint = registry > .getConfigurationElementsFor(EXTENSION_MENUS); >@@ -178,22 +187,17 @@ > configElements.add(menusExtensionPoint[i]); > } > } >- Comparator comparer = new Comparator() { >- public int compare(Object o1, Object o2) { >- IConfigurationElement c1 = (IConfigurationElement) o1; >- IConfigurationElement c2 = (IConfigurationElement) o2; >- return c1.getNamespaceIdentifier().compareToIgnoreCase( >- c2.getNamespaceIdentifier()); >+ Comparator<IConfigurationElement> comparer = new Comparator<IConfigurationElement>() { >+ public int compare(IConfigurationElement c1, IConfigurationElement c2) { >+ return c1.getNamespaceIdentifier().compareToIgnoreCase(c2.getNamespaceIdentifier()); > } > }; > Collections.sort(configElements, comparer); > >- Iterator i = configElements.iterator(); >+ Iterator<IConfigurationElement> i = configElements.iterator(); > while (i.hasNext()) { >- final IConfigurationElement configElement = (IConfigurationElement) i >- .next(); >- >- >+ final IConfigurationElement configElement = i.next(); >+ > if (isProgramaticContribution(configElement)) { > // newFactory = new ProxyMenuAdditionCacheEntry( > // configElement >@@ -202,10 +206,9 @@ > E4Util.unsupported("Programmatic Contribution Factories not supported"); //$NON-NLS-1$ > > } else { >- MenuAdditionCacheEntry menuContribution = new MenuAdditionCacheEntry(application, appContext, >- configElement, >- configElement >- .getAttribute(IWorkbenchRegistryConstants.TAG_LOCATION_URI), >+ MenuAdditionCacheEntry menuContribution = new MenuAdditionCacheEntry(application, >+ appContext, configElement, >+ configElement.getAttribute(IWorkbenchRegistryConstants.TAG_LOCATION_URI), > configElement.getNamespaceIdentifier()); > contributions.add(menuContribution); > menuContribution.addToModel(); >@@ -223,4 +226,25 @@ > private boolean isProgramaticContribution(IConfigurationElement menuAddition) { > return menuAddition.getAttribute(IWorkbenchRegistryConstants.ATT_CLASS) != null; > } >+ >+ private void readActionSets() { >+ final IExtensionRegistry registry = Platform.getExtensionRegistry(); >+ ArrayList<IConfigurationElement> configElements = new ArrayList<IConfigurationElement>(); >+ >+ configElements.addAll(Arrays.asList(registry >+ .getConfigurationElementsFor(IWorkbenchRegistryConstants.EXTENSION_ACTION_SETS))); >+ >+ Comparator<IConfigurationElement> comparer = new Comparator<IConfigurationElement>() { >+ public int compare(IConfigurationElement c1, IConfigurationElement c2) { >+ return c1.getNamespaceIdentifier().compareToIgnoreCase(c2.getNamespaceIdentifier()); >+ } >+ }; >+ Collections.sort(configElements, comparer); >+ >+ for (IConfigurationElement element : configElements) { >+ ActionSet actionSet = new ActionSet(application, appContext, element); >+ actionContributions.add(actionSet); >+ actionSet.addToModel(); >+ } >+ } > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 316303
:
171886
|
172005
|
172179
|
172665
|
172806
|
172855