aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Elder2013-09-25 10:03:16 (EDT)
committerGerrit Code Review @ Eclipse.org2013-10-01 13:59:08 (EDT)
commit5ed832dc05852503be51f3ab7cb9629c409123eb (patch)
treee2b40d3191214e9775594b2575ed7fd09c8a2ef1
parentc709c69a1d36db1e781dcf3a6545986c9d403ffc (diff)
downloadeclipse.platform.ui-5ed832dc05852503be51f3ab7cb9629c409123eb.zip
eclipse.platform.ui-5ed832dc05852503be51f3ab7cb9629c409123eb.tar.gz
eclipse.platform.ui-5ed832dc05852503be51f3ab7cb9629c409123eb.tar.bz2
Bug 417762 - [Commands] ExecutionException 'No targetId specified' whenrefs/changes/76/16776/2
programmatically invoking ShowInHandler Change-Id: I0718bc94b198a9d5cd9a9f800c8e3c59b2d924d0
-rw-r--r--bundles/org.eclipse.e4.core.commands/src/org/eclipse/e4/core/commands/CommandServiceAddon.java6
-rw-r--r--bundles/org.eclipse.e4.core.commands/src/org/eclipse/e4/core/commands/internal/HandlerServiceHandler.java18
-rw-r--r--bundles/org.eclipse.e4.core.commands/src/org/eclipse/e4/core/commands/internal/HandlerServiceImpl.java2
-rw-r--r--tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/commands/Bug417762Test.java156
4 files changed, 178 insertions, 4 deletions
diff --git a/bundles/org.eclipse.e4.core.commands/src/org/eclipse/e4/core/commands/CommandServiceAddon.java b/bundles/org.eclipse.e4.core.commands/src/org/eclipse/e4/core/commands/CommandServiceAddon.java
index 77b4b6c..f581054 100644
--- a/bundles/org.eclipse.e4.core.commands/src/org/eclipse/e4/core/commands/CommandServiceAddon.java
+++ b/bundles/org.eclipse.e4.core.commands/src/org/eclipse/e4/core/commands/CommandServiceAddon.java
@@ -13,6 +13,7 @@ package org.eclipse.e4.core.commands;
import java.lang.reflect.Field;
import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
import org.eclipse.core.commands.CommandManager;
import org.eclipse.e4.core.commands.internal.CommandServiceImpl;
import org.eclipse.e4.core.commands.internal.HandlerServiceCreationFunction;
@@ -47,6 +48,11 @@ public class CommandServiceAddon {
HandlerServiceImpl.push(context, null);
}
+ @PreDestroy
+ public void cleanup() {
+ HandlerServiceImpl.pop();
+ }
+
/**
* @param manager
* @param b
diff --git a/bundles/org.eclipse.e4.core.commands/src/org/eclipse/e4/core/commands/internal/HandlerServiceHandler.java b/bundles/org.eclipse.e4.core.commands/src/org/eclipse/e4/core/commands/internal/HandlerServiceHandler.java
index 9a09858..a09b6ce 100644
--- a/bundles/org.eclipse.e4.core.commands/src/org/eclipse/e4/core/commands/internal/HandlerServiceHandler.java
+++ b/bundles/org.eclipse.e4.core.commands/src/org/eclipse/e4/core/commands/internal/HandlerServiceHandler.java
@@ -148,13 +148,25 @@ public class HandlerServiceHandler extends AbstractHandler {
new NotHandledException(FAILED_TO_FIND_HANDLER_DURING_EXECUTION));
}
- IEclipseContext staticContext = getStaticContext(executionContext);
Object handler = HandlerServiceImpl.lookUpHandler(executionContext, commandId);
if (handler == null) {
return null;
}
- return ContextInjectionFactory.invoke(handler, Execute.class, executionContext,
- staticContext, null);
+ IEclipseContext staticContext = getStaticContext(executionContext);
+ IEclipseContext localStaticContext = null;
+ try {
+ if (staticContext == null) {
+ staticContext = localStaticContext = EclipseContextFactory
+ .create(HandlerServiceImpl.TMP_STATIC_CONTEXT);
+ staticContext.set(HandlerServiceImpl.PARM_MAP, event.getParameters());
+ }
+ return ContextInjectionFactory.invoke(handler, Execute.class, executionContext,
+ staticContext, null);
+ } finally {
+ if (localStaticContext != null) {
+ localStaticContext.dispose();
+ }
+ }
}
/*
diff --git a/bundles/org.eclipse.e4.core.commands/src/org/eclipse/e4/core/commands/internal/HandlerServiceImpl.java b/bundles/org.eclipse.e4.core.commands/src/org/eclipse/e4/core/commands/internal/HandlerServiceImpl.java
index 61cab22..cc38ff1 100644
--- a/bundles/org.eclipse.e4.core.commands/src/org/eclipse/e4/core/commands/internal/HandlerServiceImpl.java
+++ b/bundles/org.eclipse.e4.core.commands/src/org/eclipse/e4/core/commands/internal/HandlerServiceImpl.java
@@ -74,7 +74,7 @@ public class HandlerServiceImpl implements EHandlerService {
getContextStack().addFirst(new ExecutionContexts(ctx, staticCtx));
}
- static ExecutionContexts pop() {
+ public static ExecutionContexts pop() {
return getContextStack().poll();
}
diff --git a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/commands/Bug417762Test.java b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/commands/Bug417762Test.java
new file mode 100644
index 0000000..96fe9f9
--- /dev/null
+++ b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/commands/Bug417762Test.java
@@ -0,0 +1,156 @@
+/*******************************************************************************
+ * Copyright (c) 2013 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.tests.commands;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.core.commands.Command;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.NotEnabledException;
+import org.eclipse.core.commands.NotHandledException;
+import org.eclipse.core.commands.ParameterizedCommand;
+import org.eclipse.core.commands.common.NotDefinedException;
+import org.eclipse.core.expressions.IEvaluationContext;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchCommandConstants;
+import org.eclipse.ui.commands.ICommandService;
+import org.eclipse.ui.handlers.IHandlerService;
+import org.eclipse.ui.tests.harness.util.UITestCase;
+import org.junit.Test;
+
+/**
+ * @since 3.5
+ *
+ */
+public class Bug417762Test extends UITestCase {
+
+ /**
+ * @param testName
+ */
+ public Bug417762Test(String testName) {
+ super(testName);
+ }
+
+ @Test
+ public void testAsReported() throws ExecutionException,
+ NotDefinedException, NotEnabledException, NotHandledException {
+ IWorkbench workbench = getWorkbench();
+ ICommandService commandService = (ICommandService) workbench
+ .getService(ICommandService.class);
+ IHandlerService handlerService = (IHandlerService) workbench
+ .getService(IHandlerService.class);
+ Command showInCommand = commandService
+ .getCommand(IWorkbenchCommandConstants.NAVIGATE_SHOW_IN);
+ Map<String, String> parameters = new HashMap<String, String>();
+ parameters.put(IWorkbenchCommandConstants.NAVIGATE_SHOW_IN_PARM_TARGET,
+ "my.view.id");
+ IEvaluationContext contextSnapshot = handlerService
+ .createContextSnapshot(true);
+ ExecutionEvent event = new ExecutionEvent(showInCommand, parameters,
+ null, contextSnapshot);
+ showInCommand.executeWithChecks(event);
+ }
+
+ @Test
+ public void testSuggestionUseExecuteCommand() throws ExecutionException,
+ NotDefinedException, NotEnabledException, NotHandledException {
+ IWorkbench workbench = getWorkbench();
+ ICommandService commandService = (ICommandService) workbench
+ .getService(ICommandService.class);
+ IHandlerService handlerService = (IHandlerService) workbench
+ .getService(IHandlerService.class);
+ Command showInCommand = commandService
+ .getCommand(IWorkbenchCommandConstants.NAVIGATE_SHOW_IN);
+// Map<String, String> parameters = new HashMap<String, String>();
+// parameters.put(IWorkbenchCommandConstants.NAVIGATE_SHOW_IN_PARM_TARGET,
+// "my.view.id");
+// IEvaluationContext contextSnapshot = handlerService
+// .createContextSnapshot(true);
+// ExecutionEvent event = new ExecutionEvent(showInCommand, parameters,
+// null, contextSnapshot);
+// showInCommand.executeWithChecks(event);
+
+ handlerService
+ .executeCommand(
+ ParameterizedCommand.generateCommand(
+ showInCommand,
+ Collections
+ .singletonMap(
+ IWorkbenchCommandConstants.NAVIGATE_SHOW_IN_PARM_TARGET,
+ "my.view.id")), null);
+ }
+
+ @Test
+ public void testSuggestionUseExecuteCommandInContext() throws ExecutionException,
+ NotDefinedException, NotEnabledException, NotHandledException {
+ IWorkbench workbench = getWorkbench();
+ ICommandService commandService = (ICommandService) workbench
+ .getService(ICommandService.class);
+ IHandlerService handlerService = (IHandlerService) workbench
+ .getService(IHandlerService.class);
+ Command showInCommand = commandService
+ .getCommand(IWorkbenchCommandConstants.NAVIGATE_SHOW_IN);
+// Map<String, String> parameters = new HashMap<String, String>();
+// parameters.put(IWorkbenchCommandConstants.NAVIGATE_SHOW_IN_PARM_TARGET,
+// "my.view.id");
+ IEvaluationContext contextSnapshot = handlerService
+ .createContextSnapshot(true);
+// ExecutionEvent event = new ExecutionEvent(showInCommand, parameters,
+// null, contextSnapshot);
+// showInCommand.executeWithChecks(event);
+
+ handlerService
+ .executeCommandInContext(
+ ParameterizedCommand.generateCommand(
+ showInCommand,
+ Collections
+ .singletonMap(
+ IWorkbenchCommandConstants.NAVIGATE_SHOW_IN_PARM_TARGET,
+ "my.view.id")), null, contextSnapshot);
+ }
+
+ @Test
+ public void testSuggestionUseParameterizedCommandExecuteWithChecks() throws ExecutionException,
+ NotDefinedException, NotEnabledException, NotHandledException {
+ IWorkbench workbench = getWorkbench();
+ ICommandService commandService = (ICommandService) workbench
+ .getService(ICommandService.class);
+ IHandlerService handlerService = (IHandlerService) workbench
+ .getService(IHandlerService.class);
+ Command showInCommand = commandService
+ .getCommand(IWorkbenchCommandConstants.NAVIGATE_SHOW_IN);
+// Map<String, String> parameters = new HashMap<String, String>();
+// parameters.put(IWorkbenchCommandConstants.NAVIGATE_SHOW_IN_PARM_TARGET,
+// "my.view.id");
+ IEvaluationContext contextSnapshot = handlerService
+ .createContextSnapshot(true);
+// ExecutionEvent event = new ExecutionEvent(showInCommand, parameters,
+// null, contextSnapshot);
+// showInCommand.executeWithChecks(event);
+
+ final ParameterizedCommand pc = ParameterizedCommand.generateCommand(
+ showInCommand,
+ Collections
+ .singletonMap(
+ IWorkbenchCommandConstants.NAVIGATE_SHOW_IN_PARM_TARGET,
+ "my.view.id"));
+ pc.executeWithChecks(null, contextSnapshot);
+// handlerService
+// .executeCommandInContext(
+// pc, null, contextSnapshot);
+ }
+
+
+}