|
Link Here
|
| 12 |
package org.eclipse.ui.internal.menus; |
12 |
package org.eclipse.ui.internal.menus; |
| 13 |
|
13 |
|
| 14 |
import java.util.ArrayList; |
14 |
import java.util.ArrayList; |
|
|
15 |
import java.util.Collection; |
| 16 |
import org.eclipse.core.commands.contexts.Context; |
| 17 |
import org.eclipse.core.expressions.EvaluationResult; |
| 18 |
import org.eclipse.core.expressions.Expression; |
| 19 |
import org.eclipse.core.expressions.ExpressionInfo; |
| 20 |
import org.eclipse.core.expressions.IEvaluationContext; |
| 21 |
import org.eclipse.core.runtime.CoreException; |
| 15 |
import org.eclipse.core.runtime.IConfigurationElement; |
22 |
import org.eclipse.core.runtime.IConfigurationElement; |
| 16 |
import org.eclipse.core.runtime.Path; |
23 |
import org.eclipse.core.runtime.Path; |
| 17 |
import org.eclipse.e4.core.contexts.IEclipseContext; |
24 |
import org.eclipse.e4.core.contexts.IEclipseContext; |
| 18 |
import org.eclipse.e4.ui.model.application.MApplication; |
25 |
import org.eclipse.e4.ui.model.application.MApplication; |
|
|
26 |
import org.eclipse.e4.ui.model.application.ui.MCoreExpression; |
| 19 |
import org.eclipse.e4.ui.model.application.ui.MElementContainer; |
27 |
import org.eclipse.e4.ui.model.application.ui.MElementContainer; |
|
|
28 |
import org.eclipse.e4.ui.model.application.ui.impl.UiFactoryImpl; |
| 20 |
import org.eclipse.e4.ui.model.application.ui.menu.MMenu; |
29 |
import org.eclipse.e4.ui.model.application.ui.menu.MMenu; |
| 21 |
import org.eclipse.e4.ui.model.application.ui.menu.MMenuContribution; |
30 |
import org.eclipse.e4.ui.model.application.ui.menu.MMenuContribution; |
| 22 |
import org.eclipse.e4.ui.model.application.ui.menu.MMenuElement; |
31 |
import org.eclipse.e4.ui.model.application.ui.menu.MMenuElement; |
| 23 |
import org.eclipse.e4.ui.model.application.ui.menu.impl.MenuFactoryImpl; |
32 |
import org.eclipse.e4.ui.model.application.ui.menu.impl.MenuFactoryImpl; |
|
|
33 |
import org.eclipse.e4.ui.services.EContextService; |
| 24 |
import org.eclipse.e4.ui.workbench.swt.modeling.MenuServiceFilter; |
34 |
import org.eclipse.e4.ui.workbench.swt.modeling.MenuServiceFilter; |
|
|
35 |
import org.eclipse.ui.ISources; |
| 25 |
import org.eclipse.ui.IWorkbenchActionConstants; |
36 |
import org.eclipse.ui.IWorkbenchActionConstants; |
| 26 |
import org.eclipse.ui.internal.e4.compatibility.E4Util; |
37 |
import org.eclipse.ui.internal.e4.compatibility.E4Util; |
| 27 |
import org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants; |
38 |
import org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants; |
|
Link Here
|
| 36 |
|
47 |
|
| 37 |
private MApplication application; |
48 |
private MApplication application; |
| 38 |
|
49 |
|
|
|
50 |
private ActiveContextExpression visibleWhen; |
| 51 |
|
| 39 |
public ActionSet(MApplication application, IEclipseContext appContext, |
52 |
public ActionSet(MApplication application, IEclipseContext appContext, |
| 40 |
IConfigurationElement element) { |
53 |
IConfigurationElement element) { |
| 41 |
this.application = application; |
54 |
this.application = application; |
|
Link Here
|
| 45 |
public void addToModel(ArrayList<MMenuContribution> contributions) { |
58 |
public void addToModel(ArrayList<MMenuContribution> contributions) { |
| 46 |
|
59 |
|
| 47 |
String idContrib = MenuHelper.getId(configElement); |
60 |
String idContrib = MenuHelper.getId(configElement); |
|
|
61 |
visibleWhen = new ActiveContextExpression(idContrib); |
| 62 |
|
| 63 |
EContextService contextService = application.getContext().get(EContextService.class); |
| 64 |
Context actionSetContext = contextService.getContext(idContrib); |
| 65 |
if (!actionSetContext.isDefined()) { |
| 66 |
actionSetContext.define(MenuHelper.getLabel(configElement), |
| 67 |
MenuHelper.getDescription(configElement), "org.eclipse.ui.contexts.actionSet"); //$NON-NLS-1$ |
| 68 |
} |
| 69 |
|
| 48 |
IConfigurationElement[] menus = configElement |
70 |
IConfigurationElement[] menus = configElement |
| 49 |
.getChildren(IWorkbenchRegistryConstants.TAG_MENU); |
71 |
.getChildren(IWorkbenchRegistryConstants.TAG_MENU); |
| 50 |
for (IConfigurationElement element : menus) { |
72 |
for (IConfigurationElement element : menus) { |
|
Link Here
|
| 61 |
// printContributions(contributions); |
83 |
// printContributions(contributions); |
| 62 |
} |
84 |
} |
| 63 |
|
85 |
|
|
|
86 |
static class ActiveContextExpression extends Expression { |
| 87 |
private String id; |
| 88 |
|
| 89 |
public ActiveContextExpression(String id) { |
| 90 |
this.id = id; |
| 91 |
} |
| 92 |
|
| 93 |
@Override |
| 94 |
public void collectExpressionInfo(ExpressionInfo info) { |
| 95 |
info.addVariableNameAccess(ISources.ACTIVE_CONTEXT_NAME); |
| 96 |
} |
| 97 |
|
| 98 |
@Override |
| 99 |
public EvaluationResult evaluate(IEvaluationContext context) throws CoreException { |
| 100 |
Object obj = context.getVariable(ISources.ACTIVE_CONTEXT_NAME); |
| 101 |
if (obj instanceof Collection<?>) { |
| 102 |
return EvaluationResult.valueOf(((Collection) obj).contains(id)); |
| 103 |
} |
| 104 |
return EvaluationResult.FALSE; |
| 105 |
} |
| 106 |
|
| 107 |
@Override |
| 108 |
public boolean equals(Object obj) { |
| 109 |
if (!(obj instanceof ActiveContextExpression)) { |
| 110 |
return false; |
| 111 |
} |
| 112 |
return id.equals(((ActiveContextExpression) obj).id); |
| 113 |
} |
| 114 |
|
| 115 |
@Override |
| 116 |
public int hashCode() { |
| 117 |
return id.hashCode(); |
| 118 |
} |
| 119 |
} |
| 120 |
|
| 121 |
private MCoreExpression createVisibleWhen() { |
| 122 |
MCoreExpression exp = UiFactoryImpl.eINSTANCE.createCoreExpression(); |
| 123 |
exp.setCoreExpressionId("programmatic." + MenuHelper.getId(configElement)); //$NON-NLS-1$ |
| 124 |
exp.setCoreExpression(visibleWhen); |
| 125 |
return exp; |
| 126 |
} |
| 127 |
|
| 64 |
private void addContribution(String idContrib, ArrayList<MMenuContribution> contributions, |
128 |
private void addContribution(String idContrib, ArrayList<MMenuContribution> contributions, |
| 65 |
IConfigurationElement element, boolean isMenu) { |
129 |
IConfigurationElement element, boolean isMenu) { |
| 66 |
MMenuContribution menuContribution = MenuFactoryImpl.eINSTANCE.createMenuContribution(); |
130 |
MMenuContribution menuContribution = MenuFactoryImpl.eINSTANCE.createMenuContribution(); |
|
|
131 |
menuContribution.setVisibleWhen(createVisibleWhen()); |
| 67 |
menuContribution.getTags().add(MenuServiceFilter.MC_MENU); |
132 |
menuContribution.getTags().add(MenuServiceFilter.MC_MENU); |
| 68 |
final String elementId = MenuHelper.getId(element); |
133 |
final String elementId = MenuHelper.getId(element); |
| 69 |
if (idContrib != null && idContrib.length() > 0) { |
134 |
if (idContrib != null && idContrib.length() > 0) { |
|
Link Here
|
| 114 |
private void processGroups(String idContrib, ArrayList<MMenuContribution> contributions, |
179 |
private void processGroups(String idContrib, ArrayList<MMenuContribution> contributions, |
| 115 |
IConfigurationElement element) { |
180 |
IConfigurationElement element) { |
| 116 |
MMenuContribution menuContribution = MenuFactoryImpl.eINSTANCE.createMenuContribution(); |
181 |
MMenuContribution menuContribution = MenuFactoryImpl.eINSTANCE.createMenuContribution(); |
|
|
182 |
menuContribution.setVisibleWhen(createVisibleWhen()); |
| 117 |
menuContribution.getTags().add(MenuServiceFilter.MC_MENU); |
183 |
menuContribution.getTags().add(MenuServiceFilter.MC_MENU); |
| 118 |
final String elementId = MenuHelper.getId(element); |
184 |
final String elementId = MenuHelper.getId(element); |
| 119 |
if (idContrib != null && idContrib.length() > 0) { |
185 |
if (idContrib != null && idContrib.length() > 0) { |