Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Webster2012-04-20 14:53:58 +0000
committerPaul Webster2012-04-20 15:11:13 +0000
commit75b49e68802d846d8ae53c49c4e343a369e567c8 (patch)
tree92becf507d7519d25290fe8bb95798d0f69d8986 /bundles/org.eclipse.e4.core.commands
parente5f579ebaddbd5b2148f66217dfe4e447110ec9d (diff)
downloadeclipse.platform.ui-75b49e68802d846d8ae53c49c4e343a369e567c8.tar.gz
eclipse.platform.ui-75b49e68802d846d8ae53c49c4e343a369e567c8.tar.xz
eclipse.platform.ui-75b49e68802d846d8ae53c49c4e343a369e567c8.zip
Bug 369159 - [Compatibility] ICommandService/IExecutionListener notv20120420-1511
fired Fire all events through the command, so that both Command and ICommandService listeners are notified Bug: 369159
Diffstat (limited to 'bundles/org.eclipse.e4.core.commands')
-rw-r--r--bundles/org.eclipse.e4.core.commands/src/org/eclipse/e4/core/commands/CommandServiceAddon.java26
-rw-r--r--bundles/org.eclipse.e4.core.commands/src/org/eclipse/e4/core/commands/internal/HandlerServiceImpl.java20
2 files changed, 41 insertions, 5 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 1528fdaf996..5cdb070f2d6 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
@@ -11,6 +11,7 @@
package org.eclipse.e4.core.commands;
+import java.lang.reflect.Field;
import javax.annotation.PostConstruct;
import org.eclipse.core.commands.CommandManager;
import org.eclipse.e4.core.commands.internal.CommandServiceImpl;
@@ -27,6 +28,7 @@ public class CommandServiceAddon {
public void init(IEclipseContext context) {
// global command service. There can be only one ... per application :-)
CommandManager manager = new CommandManager();
+ setCommandFireEvents(manager, false);
context.set(CommandManager.class, manager);
CommandServiceImpl service = ContextInjectionFactory
.make(CommandServiceImpl.class, context);
@@ -35,4 +37,28 @@ public class CommandServiceAddon {
// handler service - a mediator service
context.set(EHandlerService.class.getName(), new HandlerServiceCreationFunction());
}
+
+ /**
+ * @param manager
+ * @param b
+ */
+ private void setCommandFireEvents(CommandManager manager, boolean b) {
+ try {
+ Field f = CommandManager.class.getDeclaredField("shouldCommandFireEvents"); //$NON-NLS-1$
+ f.setAccessible(true);
+ f.set(manager, Boolean.valueOf(b));
+ } 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();
+ }
+ }
}
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 e03968e2820..f489e5545b9 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
@@ -29,12 +29,11 @@ import org.eclipse.e4.core.services.log.Logger;
*
*/
public class HandlerServiceImpl implements EHandlerService {
- /**
- *
- */
private static final String TMP_STATIC_CONTEXT = "tmp-staticContext"; //$NON-NLS-1$
public final static String H_ID = "handler::"; //$NON-NLS-1$
public final static String PARM_MAP = "parmMap::"; //$NON-NLS-1$
+ public final static String CAN_EXECUTE = "HandlerServiceImpl.canExecute"; //$NON-NLS-1$
+ public final static String NOT_HANDLED = "HandlerServiceImpl.notHandled"; //$NON-NLS-1$
/**
* @param context
@@ -52,6 +51,8 @@ public class HandlerServiceImpl implements EHandlerService {
@Optional
private Logger logger;
+ public Object preExecute = null;
+
/*
* (non-Javadoc)
*
@@ -77,6 +78,7 @@ public class HandlerServiceImpl implements EHandlerService {
staticContext.set((String) entry.getKey(), entry.getValue());
}
staticContext.set(PARM_MAP, parms);
+ staticContext.set(ParameterizedCommand.class, command);
}
/*
@@ -107,6 +109,7 @@ public class HandlerServiceImpl implements EHandlerService {
try {
Boolean result = ((Boolean) ContextInjectionFactory.invoke(handler, CanExecute.class,
executionContext, staticContext, Boolean.TRUE));
+ staticContext.set(CAN_EXECUTE, result);
return result.booleanValue();
} catch (Exception e) {
if (Command.DEBUG_HANDLERS && logger != null) {
@@ -147,15 +150,22 @@ public class HandlerServiceImpl implements EHandlerService {
public Object executeHandler(ParameterizedCommand command, IEclipseContext staticContext) {
String commandId = command.getId();
+ final IEclipseContext executionContext = getExecutionContext();
+ addParms(command, staticContext);
+ if (preExecute != null) {
+ ContextInjectionFactory.invoke(preExecute, Execute.class, executionContext,
+ staticContext, null);
+ }
Object handler = lookUpHandler(context, commandId);
if (handler == null) {
+ staticContext.set(NOT_HANDLED, Boolean.TRUE);
return null;
}
+ staticContext.remove(NOT_HANDLED);
- final IEclipseContext executionContext = getExecutionContext();
- addParms(command, staticContext);
Object rc = ContextInjectionFactory.invoke(handler, CanExecute.class, executionContext,
staticContext, Boolean.TRUE);
+ staticContext.set(CAN_EXECUTE, rc);
if (Boolean.FALSE.equals(rc))
return null;
return ContextInjectionFactory.invoke(handler, Execute.class, executionContext,

Back to the top