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 172665 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.
actionSet visibleWhen v03
as-v03.txt (text/plain), 15.62 KB, created by
Paul Webster
on 2010-06-24 14:50:28 EDT
(
hide
)
Description:
actionSet visibleWhen v03
Filename:
MIME Type:
Creator:
Paul Webster
Created:
2010-06-24 14:50:28 EDT
Size:
15.62 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.ui.workbench >Index: Eclipse UI/org/eclipse/ui/internal/WorkbenchPage.java >=================================================================== >RCS file: /cvsroot/eclipse/e4/org.eclipse.e4.compatibility/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchPage.java,v >retrieving revision 1.55 >diff -u -r1.55 WorkbenchPage.java >--- Eclipse UI/org/eclipse/ui/internal/WorkbenchPage.java 24 Jun 2010 17:53:51 -0000 1.55 >+++ Eclipse UI/org/eclipse/ui/internal/WorkbenchPage.java 24 Jun 2010 18:49:38 -0000 >@@ -32,6 +32,7 @@ > import org.eclipse.e4.ui.model.application.MApplication; > import org.eclipse.e4.ui.model.application.descriptor.basic.MPartDescriptor; > import org.eclipse.e4.ui.model.application.ui.MElementContainer; >+import org.eclipse.e4.ui.model.application.ui.MUIElement; > import org.eclipse.e4.ui.model.application.ui.advanced.MPerspective; > import org.eclipse.e4.ui.model.application.ui.advanced.MPerspectiveStack; > import org.eclipse.e4.ui.model.application.ui.advanced.MPlaceholder; >@@ -40,6 +41,7 @@ > import org.eclipse.e4.ui.model.application.ui.basic.MPartStack; > import org.eclipse.e4.ui.model.application.ui.basic.MWindow; > import org.eclipse.e4.ui.model.application.ui.basic.MWindowElement; >+import org.eclipse.e4.ui.services.EContextService; > import org.eclipse.e4.ui.workbench.UIEvents; > import org.eclipse.e4.ui.workbench.modeling.EModelService; > import org.eclipse.e4.ui.workbench.modeling.EPartService; >@@ -304,7 +306,6 @@ > private ListenerList partListenerList = new ListenerList(); > private ListenerList partListener2List = new ListenerList(); > private IPerspectiveDescriptor perspective; >- private ModeledPageLayout modelLayout; > > > private E4PartListener e4PartListener = new E4PartListener(); >@@ -1736,8 +1737,46 @@ > } > } > } >+ >+ IEventBroker broker = window.getContext().get(IEventBroker.class); >+ broker.subscribe(UIEvents.buildTopic(UIEvents.ElementContainer.TOPIC, >+ UIEvents.ElementContainer.SELECTEDELEMENT), selectionHandler); >+ if (getPerspectiveStack() != null) { >+ MPerspective persp = getPerspectiveStack().getSelectedElement(); >+ List<String> newIds = ModeledPageLayout.getIds(persp, ModeledPageLayout.ACTION_SET_TAG); >+ EContextService contextService = window.getContext().get(EContextService.class); >+ for (String id : newIds) { >+ contextService.activateContext(id); >+ } >+ } > } > >+ private EventHandler selectionHandler = new EventHandler() { >+ public void handleEvent(Event event) { >+ MUIElement changedElement = (MUIElement) event.getProperty(UIEvents.EventTags.ELEMENT); >+ >+ if (changedElement != getPerspectiveStack()) { >+ return; >+ } >+ >+ EContextService contextService = window.getContext().get(EContextService.class); >+ MPerspective oldPersp = (MPerspective) event.getProperty(UIEvents.EventTags.OLD_VALUE); >+ List<String> oldIds = ModeledPageLayout.getIds(oldPersp, >+ ModeledPageLayout.ACTION_SET_TAG); >+ MPerspective newPersp = (MPerspective) event.getProperty(UIEvents.EventTags.NEW_VALUE); >+ List<String> newIds = ModeledPageLayout.getIds(newPersp, >+ ModeledPageLayout.ACTION_SET_TAG); >+ >+ oldIds.removeAll(newIds); >+ for (String id : oldIds) { >+ contextService.deactivateContext(id); >+ } >+ for (String id : newIds) { >+ contextService.activateContext(id); >+ } >+ } >+ }; >+ > /** > * See IWorkbenchPage. > */ >@@ -2141,13 +2180,16 @@ > MPerspectiveStack perspectives = getPerspectiveStack(); > for (MPerspective mperspective : perspectives.getChildren()) { > if (mperspective.getElementId().equals(perspective.getId())) { >- // instantiate the perspective >- IPerspectiveFactory factory = ((PerspectiveDescriptor) perspective).createFactory(); >- // use a new perspective since we're only interested in >- // shortcuts here, see bug 305918 >- modelLayout = new ModeledPageLayout(window, modelService, partService, >- AdvancedFactoryImpl.eINSTANCE.createPerspective(), perspective, this, false); >- factory.createInitialLayout(modelLayout); >+ // // instantiate the perspective >+ // IPerspectiveFactory factory = ((PerspectiveDescriptor) >+ // perspective).createFactory(); >+ // // use a new perspective since we're only interested in >+ // // shortcuts here, see bug 305918 >+ // modelLayout = new ModeledPageLayout(window, modelService, >+ // partService, >+ // AdvancedFactoryImpl.eINSTANCE.createPerspective(), >+ // perspective, this, false); >+ // factory.createInitialLayout(modelLayout); > > if (lastPerspective != null) { > legacyWindow.firePerspectiveDeactivated(this, lastPerspective); >@@ -2169,7 +2211,7 @@ > > // instantiate the perspective > IPerspectiveFactory factory = ((PerspectiveDescriptor) perspective).createFactory(); >- modelLayout = new ModeledPageLayout(window, modelService, partService, >+ ModeledPageLayout modelLayout = new ModeledPageLayout(window, modelService, partService, > modelPerspective, > perspective, this, true); > factory.createInitialLayout(modelLayout); >@@ -2462,14 +2504,27 @@ > return tracker; > } > >+ private final static String[] EMPTY_STRING_ARRAY = new String[0]; >+ >+ private String[] getArrayForTag(String tagPrefix) { >+ MPerspective perspective = getPerspectiveStack().getSelectedElement(); >+ if (perspective == null) { >+ return EMPTY_STRING_ARRAY; >+ } >+ List<String> id = ModeledPageLayout.getIds(perspective, tagPrefix); >+ if (id.size() == 0) { >+ return EMPTY_STRING_ARRAY; >+ } >+ return id.toArray(new String[id.size()]); >+ } >+ > /* > * (non-Javadoc) > * > * @see org.eclipse.ui.IWorkbenchPage#getNewWizardShortcuts() > */ > public String[] getNewWizardShortcuts() { >- ArrayList shortcuts = modelLayout.getNewWizardShortcuts(); >- return (String[]) shortcuts.toArray(new String[shortcuts.size()]); >+ return getArrayForTag(ModeledPageLayout.NEW_WIZARD_TAG); > } > > /* >@@ -2478,8 +2533,7 @@ > * @see org.eclipse.ui.IWorkbenchPage#getPerspectiveShortcuts() > */ > public String[] getPerspectiveShortcuts() { >- ArrayList shortcuts = modelLayout.getPerspectiveShortcuts(); >- return (String[]) shortcuts.toArray(new String[shortcuts.size()]); >+ return getArrayForTag(ModeledPageLayout.PERSP_SHORTCUT_TAG); > } > > /* >@@ -2488,8 +2542,7 @@ > * @see org.eclipse.ui.IWorkbenchPage#getShowViewShortcuts() > */ > public String[] getShowViewShortcuts() { >- ArrayList shortcuts = modelLayout.getShowViewShortcuts(); >- return (String[]) shortcuts.toArray(new String[shortcuts.size()]); >+ return getArrayForTag(ModeledPageLayout.SHOW_VIEW_TAG); > } > > >Index: Eclipse UI/org/eclipse/ui/internal/e4/compatibility/ModeledPageLayout.java >=================================================================== >RCS file: /cvsroot/eclipse/e4/org.eclipse.e4.compatibility/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/e4/compatibility/ModeledPageLayout.java,v >retrieving revision 1.20 >diff -u -r1.20 ModeledPageLayout.java >--- Eclipse UI/org/eclipse/ui/internal/e4/compatibility/ModeledPageLayout.java 4 Jun 2010 20:22:16 -0000 1.20 >+++ Eclipse UI/org/eclipse/ui/internal/e4/compatibility/ModeledPageLayout.java 24 Jun 2010 18:49:38 -0000 >@@ -11,10 +11,8 @@ > > package org.eclipse.ui.internal.e4.compatibility; > >-import org.eclipse.e4.ui.workbench.modeling.EModelService; >-import org.eclipse.e4.ui.workbench.modeling.EPartService; >- > import java.util.ArrayList; >+import java.util.Collections; > import java.util.List; > import org.eclipse.e4.ui.model.application.MApplication; > import org.eclipse.e4.ui.model.application.descriptor.basic.MPartDescriptor; >@@ -30,6 +28,8 @@ > import org.eclipse.e4.ui.model.application.ui.basic.MStackElement; > import org.eclipse.e4.ui.model.application.ui.basic.MWindow; > import org.eclipse.e4.ui.model.application.ui.basic.impl.BasicFactoryImpl; >+import org.eclipse.e4.ui.workbench.modeling.EModelService; >+import org.eclipse.e4.ui.workbench.modeling.EPartService; > import org.eclipse.swt.SWT; > import org.eclipse.ui.IFolderLayout; > import org.eclipse.ui.IPageLayout; >@@ -40,6 +40,25 @@ > > public class ModeledPageLayout implements IPageLayout { > >+ public static final String ACTION_SET_TAG = "persp.actionSet:"; //$NON-NLS-1$ >+ public static final String NEW_WIZARD_TAG = "persp.newWizSC:"; //$NON-NLS-1$ >+ public static final String PERSP_SHORTCUT_TAG = "persp.perspSC:"; //$NON-NLS-1$ >+ public static final String SHOW_IN_PART_TAG = "persp.showIn:"; //$NON-NLS-1$ >+ public static final String SHOW_VIEW_TAG = "persp.viewSC:"; //$NON-NLS-1$ >+ >+ public static List<String> getIds(MPerspective model, String tagPrefix) { >+ if (model == null) { >+ return Collections.EMPTY_LIST; >+ } >+ ArrayList<String> result = new ArrayList<String>(); >+ for (String tag : model.getTags()) { >+ if (tag.startsWith(tagPrefix)) { >+ result.add(tag.substring(tagPrefix.length())); >+ } >+ } >+ return result; >+ } >+ > private MApplication application; > private EModelService modelService; > >@@ -50,12 +69,6 @@ > > private MPartStack editorStack; > >- private ArrayList newWizardShortcuts = new ArrayList(); >- private ArrayList perspectiveShortcut = new ArrayList(); >- private ArrayList showInPart = new ArrayList(); >- private ArrayList showViewShortcut = new ArrayList(); >- private ArrayList actionSet = new ArrayList(); >- > boolean createReferences; > > public ModeledPageLayout(MWindow window, EModelService modelService, >@@ -110,7 +123,7 @@ > } > > public void addActionSet(String actionSetId) { >- actionSet.add(actionSetId); >+ perspModel.getTags().add(ACTION_SET_TAG + actionSetId); > } > > public void addFastView(String viewId) { >@@ -120,11 +133,11 @@ > } > > public void addNewWizardShortcut(String id) { >- newWizardShortcuts.add(id); >+ perspModel.getTags().add(NEW_WIZARD_TAG + id); > } > > public void addPerspectiveShortcut(String id) { >- perspectiveShortcut.add(id); >+ perspModel.getTags().add(PERSP_SHORTCUT_TAG + id); > } > > public void addPlaceholder(String viewId, int relationship, float ratio, >@@ -133,11 +146,11 @@ > } > > public void addShowInPart(String id) { >- showInPart.add(id); >+ perspModel.getTags().add(SHOW_IN_PART_TAG + id); > } > > public void addShowViewShortcut(String id) { >- showViewShortcut.add(id); >+ perspModel.getTags().add(SHOW_VIEW_TAG + id); > } > > public void addStandaloneView(String viewId, boolean showTitle, >@@ -466,32 +479,4 @@ > MUIElement element = modelService.find(id, toSearch); > return element instanceof MPart ? (MPart) element : null; > } >- >- /** >- * @return >- */ >- public ArrayList getNewWizardShortcuts() { >- return newWizardShortcuts; >- } >- >- /** >- * @return >- */ >- public ArrayList getShowViewShortcuts() { >- return showViewShortcut; >- } >- >- /** >- * @return >- */ >- public ArrayList getPerspectiveShortcuts() { >- return perspectiveShortcut; >- } >- >- /** >- * @return >- */ >- public ArrayList getShowInPartIds() { >- return showInPart; >- } > } >Index: Eclipse UI/org/eclipse/ui/internal/menus/ActionSet.java >=================================================================== >RCS file: /cvsroot/eclipse/e4/org.eclipse.e4.compatibility/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/menus/ActionSet.java,v >retrieving revision 1.2 >diff -u -r1.2 ActionSet.java >--- Eclipse UI/org/eclipse/ui/internal/menus/ActionSet.java 18 Jun 2010 16:08:28 -0000 1.2 >+++ Eclipse UI/org/eclipse/ui/internal/menus/ActionSet.java 24 Jun 2010 18:49:38 -0000 >@@ -12,16 +12,27 @@ > package org.eclipse.ui.internal.menus; > > import java.util.ArrayList; >+import java.util.Collection; >+import org.eclipse.core.commands.contexts.Context; >+import org.eclipse.core.expressions.EvaluationResult; >+import org.eclipse.core.expressions.Expression; >+import org.eclipse.core.expressions.ExpressionInfo; >+import org.eclipse.core.expressions.IEvaluationContext; >+import org.eclipse.core.runtime.CoreException; > 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.MCoreExpression; > import org.eclipse.e4.ui.model.application.ui.MElementContainer; >+import org.eclipse.e4.ui.model.application.ui.impl.UiFactoryImpl; > 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.services.EContextService; > import org.eclipse.e4.ui.workbench.swt.modeling.MenuServiceFilter; >+import org.eclipse.ui.ISources; > import org.eclipse.ui.IWorkbenchActionConstants; > import org.eclipse.ui.internal.e4.compatibility.E4Util; > import org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants; >@@ -36,6 +47,8 @@ > > private MApplication application; > >+ private ActiveContextExpression visibleWhen; >+ > public ActionSet(MApplication application, IEclipseContext appContext, > IConfigurationElement element) { > this.application = application; >@@ -45,6 +58,15 @@ > public void addToModel(ArrayList<MMenuContribution> contributions) { > > String idContrib = MenuHelper.getId(configElement); >+ visibleWhen = new ActiveContextExpression(idContrib); >+ >+ EContextService contextService = application.getContext().get(EContextService.class); >+ Context actionSetContext = contextService.getContext(idContrib); >+ if (!actionSetContext.isDefined()) { >+ actionSetContext.define(MenuHelper.getLabel(configElement), >+ MenuHelper.getDescription(configElement), "org.eclipse.ui.contexts.actionSet"); //$NON-NLS-1$ >+ } >+ > IConfigurationElement[] menus = configElement > .getChildren(IWorkbenchRegistryConstants.TAG_MENU); > for (IConfigurationElement element : menus) { >@@ -61,9 +83,52 @@ > // printContributions(contributions); > } > >+ static class ActiveContextExpression extends Expression { >+ private String id; >+ >+ public ActiveContextExpression(String id) { >+ this.id = id; >+ } >+ >+ @Override >+ public void collectExpressionInfo(ExpressionInfo info) { >+ info.addVariableNameAccess(ISources.ACTIVE_CONTEXT_NAME); >+ } >+ >+ @Override >+ public EvaluationResult evaluate(IEvaluationContext context) throws CoreException { >+ Object obj = context.getVariable(ISources.ACTIVE_CONTEXT_NAME); >+ if (obj instanceof Collection<?>) { >+ return EvaluationResult.valueOf(((Collection) obj).contains(id)); >+ } >+ return EvaluationResult.FALSE; >+ } >+ >+ @Override >+ public boolean equals(Object obj) { >+ if (!(obj instanceof ActiveContextExpression)) { >+ return false; >+ } >+ return id.equals(((ActiveContextExpression) obj).id); >+ } >+ >+ @Override >+ public int hashCode() { >+ return id.hashCode(); >+ } >+ } >+ >+ private MCoreExpression createVisibleWhen() { >+ MCoreExpression exp = UiFactoryImpl.eINSTANCE.createCoreExpression(); >+ exp.setCoreExpressionId("programmatic." + MenuHelper.getId(configElement)); //$NON-NLS-1$ >+ exp.setCoreExpression(visibleWhen); >+ return exp; >+ } >+ > private void addContribution(String idContrib, ArrayList<MMenuContribution> contributions, > IConfigurationElement element, boolean isMenu) { > MMenuContribution menuContribution = MenuFactoryImpl.eINSTANCE.createMenuContribution(); >+ menuContribution.setVisibleWhen(createVisibleWhen()); > menuContribution.getTags().add(MenuServiceFilter.MC_MENU); > final String elementId = MenuHelper.getId(element); > if (idContrib != null && idContrib.length() > 0) { >@@ -114,6 +179,7 @@ > private void processGroups(String idContrib, ArrayList<MMenuContribution> contributions, > IConfigurationElement element) { > MMenuContribution menuContribution = MenuFactoryImpl.eINSTANCE.createMenuContribution(); >+ menuContribution.setVisibleWhen(createVisibleWhen()); > menuContribution.getTags().add(MenuServiceFilter.MC_MENU); > final String elementId = MenuHelper.getId(element); > if (idContrib != null && idContrib.length() > 0) {
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 Raw
Actions:
View
Attachments on
bug 316303
:
171886
|
172005
|
172179
| 172665 |
172806
|
172855