Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Webster2012-09-05 15:25:24 +0000
committerPaul Webster2012-09-05 18:34:11 +0000
commite74da6e100666157419095f7a6249c2838c00bf6 (patch)
treebaf647c26b67d7e585f2ebc6d0fd9f757a0b6fdf
parent7cf4116ca4a574a5c536164bda4103c49f52c96d (diff)
downloadeclipse.platform.ui-e74da6e100666157419095f7a6249c2838c00bf6.tar.gz
eclipse.platform.ui-e74da6e100666157419095f7a6249c2838c00bf6.tar.xz
eclipse.platform.ui-e74da6e100666157419095f7a6249c2838c00bf6.zip
Bug 384545 - Wrong selection used to find the handlerv20120905-183411M20120905-1500
Make the snapshot IEvaluationContext variables available to IEclipseContext hierarch for lookup and evaluation.
-rw-r--r--bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/handlers/LegacyHandlerService.java79
-rw-r--r--bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/services/EvaluationService.java8
2 files changed, 74 insertions, 13 deletions
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/handlers/LegacyHandlerService.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/handlers/LegacyHandlerService.java
index 33699124254..8f7e298047c 100644
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/handlers/LegacyHandlerService.java
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/handlers/LegacyHandlerService.java
@@ -11,10 +11,12 @@
package org.eclipse.ui.internal.handlers;
+import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.inject.Named;
@@ -60,6 +62,7 @@ import org.eclipse.ui.internal.e4.compatibility.E4Util;
import org.eclipse.ui.internal.expressions.AndExpression;
import org.eclipse.ui.internal.expressions.WorkbenchWindowExpression;
import org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants;
+import org.eclipse.ui.internal.services.EvaluationService;
import org.eclipse.ui.services.IEvaluationService;
import org.eclipse.ui.services.ISourceProviderService;
@@ -138,12 +141,7 @@ public class LegacyHandlerService implements IHandlerService {
return bestActivation.proxy;
}
- // "super call"
- IEclipseContext parent = context.getParent();
- if (parent == null) {
- return null;
- }
- return parent.get(HandlerServiceImpl.H_ID + commandId);
+ return null;
}
}
@@ -535,21 +533,30 @@ public class LegacyHandlerService implements IHandlerService {
public Object executeCommandInContext(ParameterizedCommand command, Event event,
IEvaluationContext context) throws ExecutionException, NotDefinedException,
NotEnabledException, NotHandledException {
+
IEclipseContext staticContext = null;
- boolean disposeContext = false;
+ Object defaultVar = null;
if (context instanceof ExpressionContext) {
// create a child context so that the primary context doesn't get
// populated by parameters by the EHS
staticContext = ((ExpressionContext) context).eclipseContext.createChild();
} else {
- staticContext = EclipseContextFactory.create();
- disposeContext = true;
+ staticContext = eclipseContext.createChild("snapshotContext"); //$NON-NLS-1$
if (event != null) {
staticContext.set(Event.class, event);
}
staticContext.set(IEvaluationContext.class, context);
+ defaultVar = context.getDefaultVariable();
+ if (defaultVar != null && defaultVar != IEvaluationContext.UNDEFINED_VARIABLE) {
+ staticContext.set(EvaluationService.DEFAULT_VAR, defaultVar);
+ }
}
- EHandlerService hs = eclipseContext.get(EHandlerService.class);
+ IEclipseContext lookupContext = staticContext;
+ // the IEvaluationContext snapshot is not part of our runtime
+ // IEclipseContext hierarchy. In order to work. we need the variables
+ // from the snapshot available in the static context.
+ populateSnapshot(context, staticContext);
+ EHandlerService hs = lookupContext.get(EHandlerService.class);
try {
final Object rc = hs.executeHandler(command, staticContext);
if (staticContext.get(HandlerServiceImpl.NOT_HANDLED) == Boolean.TRUE) {
@@ -572,10 +579,58 @@ public class LegacyHandlerService implements IHandlerService {
rethrow(e);
throw e;
} finally {
- if (disposeContext) {
- staticContext.dispose();
+ staticContext.dispose();
+ }
+ }
+
+ /**
+ * @param context
+ * @param staticContext
+ */
+ private void populateSnapshot(IEvaluationContext context, IEclipseContext staticContext) {
+ IEvaluationContext ctxPtr = context;
+ while (ctxPtr != null && !(ctxPtr instanceof ExpressionContext)) {
+ Map vars = getVariables(ctxPtr);
+ if (vars != null) {
+ Iterator i = vars.entrySet().iterator();
+ while (i.hasNext()) {
+ Map.Entry entry = (Map.Entry) i.next();
+ if (staticContext.getLocal(entry.getKey().toString()) == null) {
+ staticContext.set(entry.getKey().toString(), entry.getValue());
+ }
+ }
+ }
+ ctxPtr = ctxPtr.getParent();
+ }
+ }
+
+ private Map getVariables(IEvaluationContext ctx) {
+ Field vars = getContextVariablesField();
+ if (vars != null) {
+ try {
+ return (Map) vars.get(ctx);
+ } catch (IllegalArgumentException e) {
+
+ } catch (IllegalAccessException e) {
+
+ }
+ }
+ return null;
+ }
+
+ private static Field contextFVariables = null;
+
+ private static Field getContextVariablesField() {
+ if (contextFVariables == null) {
+ try {
+ contextFVariables = EvaluationContext.class.getField("fVariables"); //$NON-NLS-1$
+ } catch (SecurityException e) {
+
+ } catch (NoSuchFieldException e) {
+
}
}
+ return contextFVariables;
}
/**
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/services/EvaluationService.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/services/EvaluationService.java
index 033f492b8dc..c225ace39aa 100644
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/services/EvaluationService.java
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/services/EvaluationService.java
@@ -46,6 +46,7 @@ import org.eclipse.ui.services.IEvaluationService;
*
*/
public final class EvaluationService implements IEvaluationService {
+ public static final String DEFAULT_VAR = "org.eclipse.ui.internal.services.EvaluationService.default_var"; //$NON-NLS-1$
private static final String RE_EVAL = "org.eclipse.ui.internal.services.EvaluationService.evaluate"; //$NON-NLS-1$
private boolean evaluate = false;
private ExpressionContext legacyContext;
@@ -85,7 +86,12 @@ public final class EvaluationService implements IEvaluationService {
ExpressionContext.defaultVariableConverter = new ContextFunction() {
@Override
public Object compute(IEclipseContext context) {
- Object defaultVariable = context.getActive(IServiceConstants.ACTIVE_SELECTION);
+ Object defaultVariable = context.getLocal(DEFAULT_VAR);
+ if (defaultVariable != null
+ && defaultVariable != IEvaluationContext.UNDEFINED_VARIABLE) {
+ return defaultVariable;
+ }
+ defaultVariable = context.getActive(IServiceConstants.ACTIVE_SELECTION);
if (defaultVariable instanceof IStructuredSelection) {
final IStructuredSelection selection = (IStructuredSelection) defaultVariable;
return selection.toList();

Back to the top