Bug 382839 - [Compatibility] 'Line Up' and 'Line Down' no longer work in content assist pop-up Restructure how the Eclipse4 commands work with the regular Command object. Work in progress.
diff --git a/bundles/org.eclipse.e4.core.commands/META-INF/MANIFEST.MF b/bundles/org.eclipse.e4.core.commands/META-INF/MANIFEST.MF index 6dfce3c..678baf9 100644 --- a/bundles/org.eclipse.e4.core.commands/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.e4.core.commands/META-INF/MANIFEST.MF
@@ -4,7 +4,7 @@ Bundle-Name: %pluginName Bundle-Vendor: %providerName Bundle-Localization: plugin -Bundle-Version: 0.10.1.qualifier +Bundle-Version: 0.10.2.qualifier Bundle-Activator: org.eclipse.e4.core.commands.internal.Activator Bundle-RequiredExecutionEnvironment: J2SE-1.5 Bundle-ActivationPolicy: lazy @@ -12,6 +12,7 @@ javax.inject;version="1.0.0", org.eclipse.core.commands, org.eclipse.core.commands.common, + org.eclipse.core.expressions, org.eclipse.e4.core.contexts, org.eclipse.e4.core.services.log, org.eclipse.e4.core.services.util,
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 11242cc..6bba4d5 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
@@ -16,6 +16,7 @@ import org.eclipse.core.commands.CommandManager; import org.eclipse.e4.core.commands.internal.CommandServiceImpl; import org.eclipse.e4.core.commands.internal.HandlerServiceCreationFunction; +import org.eclipse.e4.core.commands.internal.HandlerServiceImpl; import org.eclipse.e4.core.contexts.ContextInjectionFactory; import org.eclipse.e4.core.contexts.IEclipseContext; @@ -30,7 +31,7 @@ CommandManager manager = context.get(CommandManager.class); if (manager == null) { manager = new CommandManager(); - setCommandFireEvents(manager, false); + // setCommandFireEvents(manager, false); context.set(CommandManager.class, manager); } @@ -40,13 +41,15 @@ // handler service - a mediator service context.set(EHandlerService.class.getName(), new HandlerServiceCreationFunction()); + // provide the initial application context, just in case. + HandlerServiceImpl.push(context); } /** * @param manager * @param b */ - private void setCommandFireEvents(CommandManager manager, boolean b) { + void setCommandFireEvents(CommandManager manager, boolean b) { try { Field f = CommandManager.class.getDeclaredField("shouldCommandFireEvents"); //$NON-NLS-1$ f.setAccessible(true);
diff --git a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/workbench/modeling/ExpressionContext.java b/bundles/org.eclipse.e4.core.commands/src/org/eclipse/e4/core/commands/ExpressionContext.java similarity index 89% rename from bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/workbench/modeling/ExpressionContext.java rename to bundles/org.eclipse.e4.core.commands/src/org/eclipse/e4/core/commands/ExpressionContext.java index c6ed322..9b57271 100644 --- a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/workbench/modeling/ExpressionContext.java +++ b/bundles/org.eclipse.e4.core.commands/src/org/eclipse/e4/core/commands/ExpressionContext.java
@@ -9,20 +9,24 @@ * IBM Corporation - initial API and implementation ******************************************************************************/ -package org.eclipse.e4.ui.workbench.modeling; +package org.eclipse.e4.core.commands; import java.util.Collections; import org.eclipse.core.expressions.IEvaluationContext; import org.eclipse.core.runtime.CoreException; import org.eclipse.e4.core.contexts.IContextFunction; import org.eclipse.e4.core.contexts.IEclipseContext; -import org.eclipse.e4.ui.services.IServiceConstants; /** * */ public class ExpressionContext implements IEvaluationContext { - public static final String ALLOW_ACTIVATION = "org.eclipse.e4.ui.workbench.modeling.ExpressionContext.allowActivation"; //$NON-NLS-1$ + /** + * See org.eclipse.e4.ui.services.IServiceConstants.ACTIVE_SELECTION + */ + private static final String ORG_ECLIPSE_UI_SELECTION = "org.eclipse.ui.selection"; //$NON-NLS-1$ + + public static final String ALLOW_ACTIVATION = "org.eclipse.e4.core.commands.ExpressionContext.allowActivation"; //$NON-NLS-1$ public IEclipseContext eclipseContext; public static IContextFunction defaultVariableConverter = null; @@ -88,7 +92,7 @@ if (defaultVariableConverter != null) { sel = defaultVariableConverter.compute(eclipseContext); } else { - sel = eclipseContext.getActive(IServiceConstants.ACTIVE_SELECTION); + sel = eclipseContext.getActive(ORG_ECLIPSE_UI_SELECTION); } return sel == null ? Collections.EMPTY_LIST : sel; }
diff --git a/bundles/org.eclipse.e4.core.commands/src/org/eclipse/e4/core/commands/internal/CommandServiceImpl.java b/bundles/org.eclipse.e4.core.commands/src/org/eclipse/e4/core/commands/internal/CommandServiceImpl.java index efec694..3adf11f 100644 --- a/bundles/org.eclipse.e4.core.commands/src/org/eclipse/e4/core/commands/internal/CommandServiceImpl.java +++ b/bundles/org.eclipse.e4.core.commands/src/org/eclipse/e4/core/commands/internal/CommandServiceImpl.java
@@ -72,6 +72,7 @@ Command cmd = commandManager.getCommand(id); if (!cmd.isDefined()) { cmd.define(name, description, category, parameters); + cmd.setHandler(HandlerServiceImpl.getHandler(id)); } return cmd; }
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 new file mode 100644 index 0000000..9190068 --- /dev/null +++ b/bundles/org.eclipse.e4.core.commands/src/org/eclipse/e4/core/commands/internal/HandlerServiceHandler.java
@@ -0,0 +1,116 @@ +/******************************************************************************* + * 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.e4.core.commands.internal; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.commands.NotHandledException; +import org.eclipse.core.expressions.IEvaluationContext; +import org.eclipse.e4.core.commands.ExpressionContext; +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.di.annotations.CanExecute; +import org.eclipse.e4.core.di.annotations.Execute; + +/** + * Provide an IHandler to delegate calls to. + */ +public class HandlerServiceHandler extends AbstractHandler { + + private static final String FAILED_TO_FIND_HANDLER_DURING_EXECUTION = "Failed to find handler during execution"; //$NON-NLS-1$ + private String commandId; + + public HandlerServiceHandler(String commandId) { + this.commandId = commandId; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.core.commands.AbstractHandler#setEnabled(java.lang.Object) + */ + @Override + public void setEnabled(Object evaluationContext) { + IEclipseContext executionContext = getExecutionContext(evaluationContext); + if (executionContext == null) { + return; + } + + IEclipseContext staticContext = (IEclipseContext) executionContext + .get(HandlerServiceImpl.STATIC_CONTEXT); + Object handler = HandlerServiceImpl.lookUpHandler(executionContext, commandId); + if (handler == null) { + setBaseEnabled(false); + return; + } + try { + Boolean result = ((Boolean) ContextInjectionFactory.invoke(handler, CanExecute.class, + executionContext, staticContext, Boolean.TRUE)); + setBaseEnabled(result.booleanValue()); + } catch (Exception e) { + e.printStackTrace(); + } + } + + IEclipseContext getExecutionContext(Object evalObj) { + if (evalObj instanceof IEclipseContext) { + return (IEclipseContext) evalObj; + } + if (evalObj instanceof ExpressionContext) { + return ((ExpressionContext) evalObj).eclipseContext; + } + if (evalObj instanceof IEvaluationContext) { + return getExecutionContext(((IEvaluationContext) evalObj).getParent()); + } + return null; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.core.commands.AbstractHandler#isHandled() + */ + @Override + public boolean isHandled() { + IEclipseContext executionContext = HandlerServiceImpl.peek(); + if (executionContext != null) { + Object handler = HandlerServiceImpl.lookUpHandler(executionContext, commandId); + return handler != null; + + } + return false; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent) + */ + public Object execute(ExecutionEvent event) throws ExecutionException { + IEclipseContext executionContext = getExecutionContext(event.getApplicationContext()); + if (executionContext == null) { + throw new ExecutionException(FAILED_TO_FIND_HANDLER_DURING_EXECUTION, + new NotHandledException(FAILED_TO_FIND_HANDLER_DURING_EXECUTION)); + } + + IEclipseContext staticContext = (IEclipseContext) executionContext + .get(HandlerServiceImpl.STATIC_CONTEXT); + Object handler = HandlerServiceImpl.lookUpHandler(executionContext, commandId); + if (handler == null) { + return null; + } + return ContextInjectionFactory.invoke(handler, Execute.class, executionContext, + staticContext, null); + } + +}
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 e8b565f..7e44580 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
@@ -12,10 +12,16 @@ package org.eclipse.e4.core.commands.internal; import java.util.Iterator; +import java.util.LinkedList; import java.util.Map; import javax.inject.Inject; import org.eclipse.core.commands.Command; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.commands.IHandler; +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.e4.core.commands.EHandlerService; import org.eclipse.e4.core.contexts.ContextInjectionFactory; import org.eclipse.e4.core.contexts.EclipseContextFactory; @@ -29,11 +35,34 @@ * */ public class HandlerServiceImpl implements EHandlerService { - private static final String TMP_STATIC_CONTEXT = "tmp-staticContext"; //$NON-NLS-1$ + 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$ + public final static String STATIC_CONTEXT = "HandlerServiceImpl.staticContext"; //$NON-NLS-1$ + + private static LinkedList<IEclipseContext> contextStack = new LinkedList<IEclipseContext>(); + + public static IHandler getHandler(String commandId) { + return new HandlerServiceHandler(commandId); + } + + static LinkedList<IEclipseContext> getContextStack() { + return contextStack; + } + + public static void push(IEclipseContext ctx) { + getContextStack().addFirst(ctx); + } + + static IEclipseContext pop() { + return getContextStack().poll(); + } + + static IEclipseContext peek() { + return getContextStack().peek(); + } /** * @param context @@ -45,11 +74,28 @@ return context.getActiveLeaf().get(H_ID + commandId); } + /** + * Fill in a temporary static context for execution. + * + * @param command + * @return a context not part of the normal hierarchy + */ + public static void addParms(ParameterizedCommand command, IEclipseContext staticContext) { + final Map parms = command.getParameterMap(); + Iterator i = parms.entrySet().iterator(); + while (i.hasNext()) { + Map.Entry entry = (Map.Entry) i.next(); + staticContext.set((String) entry.getKey(), entry.getValue()); + } + staticContext.set(PARM_MAP, parms); + staticContext.set(ParameterizedCommand.class, command); + } + private IEclipseContext context; @Inject @Optional - private Logger logger; + Logger logger; public static Object preExecute = null; @@ -64,29 +110,6 @@ context.set(handlerId, handler); } - /** - * Fill in a temporary static context for execution. - * - * @param command - * @return a context not part of the normal hierarchy - */ - private void addParms(ParameterizedCommand command, IEclipseContext staticContext) { - final Map parms = command.getParameterMap(); - Iterator i = parms.entrySet().iterator(); - while (i.hasNext()) { - Map.Entry entry = (Map.Entry) i.next(); - staticContext.set((String) entry.getKey(), entry.getValue()); - } - staticContext.set(PARM_MAP, parms); - staticContext.set(ParameterizedCommand.class, command); - } - - /* - * (non-Javadoc) - * - * @seeorg.eclipse.e4.core.commands.EHandlerService#canExecute(org.eclipse.core.commands. - * ParameterizedCommand) - */ public boolean canExecute(ParameterizedCommand command) { final IEclipseContext staticContext = EclipseContextFactory.create(TMP_STATIC_CONTEXT); try { @@ -97,6 +120,21 @@ } public boolean canExecute(ParameterizedCommand command, IEclipseContext staticContext) { + final IEclipseContext executionContext = getExecutionContext(); + addParms(command, staticContext); + executionContext.set(STATIC_CONTEXT, staticContext); + push(executionContext); + try { + Command cmd = command.getCommand(); + cmd.setEnabled(executionContext); + return cmd.isEnabled(); + } finally { + pop(); + executionContext.remove(STATIC_CONTEXT); + } + } + + public boolean old_canExecute(ParameterizedCommand command, IEclipseContext staticContext) { String commandId = command.getId(); Object handler = lookUpHandler(context, commandId); if (handler == null) { @@ -149,6 +187,33 @@ } public Object executeHandler(ParameterizedCommand command, IEclipseContext staticContext) { + final IEclipseContext executionContext = getExecutionContext(); + addParms(command, staticContext); + executionContext.set(STATIC_CONTEXT, staticContext); + push(executionContext); + try { + // Command cmd = command.getCommand(); + return command.executeWithChecks(null, executionContext); + } catch (ExecutionException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (NotDefinedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (NotEnabledException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (NotHandledException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } finally { + pop(); + executionContext.remove(STATIC_CONTEXT); + } + return null; + } + + public Object old_executeHandler(ParameterizedCommand command, IEclipseContext staticContext) { String commandId = command.getId(); final IEclipseContext executionContext = getExecutionContext(); addParms(command, staticContext);
diff --git a/bundles/org.eclipse.e4.ui.workbench.addons.swt/src/org/eclipse/e4/ui/workbench/addons/dndaddon/StackDropAgent.java b/bundles/org.eclipse.e4.ui.workbench.addons.swt/src/org/eclipse/e4/ui/workbench/addons/dndaddon/StackDropAgent.java index 7f897b1..aaeda80 100644 --- a/bundles/org.eclipse.e4.ui.workbench.addons.swt/src/org/eclipse/e4/ui/workbench/addons/dndaddon/StackDropAgent.java +++ b/bundles/org.eclipse.e4.ui.workbench.addons.swt/src/org/eclipse/e4/ui/workbench/addons/dndaddon/StackDropAgent.java
@@ -223,8 +223,7 @@ // 'dropIndex' is now the index of the CTabItem to put ourselves before // we need to adjust this to be a model index - int ctfItemCount = dropCTF.getItemCount(); - if (dropIndex < ctfItemCount) { + if (dropIndex < dropCTF.getItemCount()) { CTabItem item = dropCTF.getItem(dropIndex); MUIElement itemModel = (MUIElement) item.getData(AbstractPartRenderer.OWNING_ME); @@ -233,11 +232,6 @@ return; dropIndex = itemModel.getParent().getChildren().indexOf(itemModel); - // if the item is dropped at the last position, there is - // no existing item to put ourselves before - // so we'll just go to the end. - } else if (dropIndex == ctfItemCount) { - dropIndex = dropStack.getChildren().size(); } if (dragElement instanceof MStackElement) {
diff --git a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/ContributionRecord.java b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/ContributionRecord.java index bff5aaf..5d4bc12 100644 --- a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/ContributionRecord.java +++ b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/ContributionRecord.java
@@ -11,6 +11,8 @@ package org.eclipse.e4.ui.workbench.renderers.swt; +import org.eclipse.e4.core.commands.ExpressionContext; + import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -32,7 +34,6 @@ 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.MMenuSeparator; -import org.eclipse.e4.ui.workbench.modeling.ExpressionContext; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.util.EcoreUtil; import org.eclipse.jface.action.MenuManager;
diff --git a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/MenuItemRenderer.java b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/MenuItemRenderer.java index c05e05f..c7f3bf9 100644 --- a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/MenuItemRenderer.java +++ b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/MenuItemRenderer.java
@@ -10,6 +10,8 @@ *******************************************************************************/ package org.eclipse.e4.ui.workbench.renderers.swt; +import org.eclipse.e4.core.commands.ExpressionContext; + import java.util.HashMap; import javax.annotation.PostConstruct; import javax.annotation.PreDestroy; @@ -30,7 +32,6 @@ import org.eclipse.e4.ui.model.application.ui.menu.MItem; import org.eclipse.e4.ui.model.application.ui.menu.MMenuItem; import org.eclipse.e4.ui.workbench.UIEvents; -import org.eclipse.e4.ui.workbench.modeling.ExpressionContext; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.widgets.MenuItem;
diff --git a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/MenuManagerRenderer.java b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/MenuManagerRenderer.java index c5f3bef..d95a776 100644 --- a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/MenuManagerRenderer.java +++ b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/MenuManagerRenderer.java
@@ -11,6 +11,8 @@ *******************************************************************************/ package org.eclipse.e4.ui.workbench.renderers.swt; +import org.eclipse.e4.core.commands.ExpressionContext; + import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; @@ -52,7 +54,6 @@ import org.eclipse.e4.ui.model.application.ui.menu.impl.MenuFactoryImpl; import org.eclipse.e4.ui.workbench.IResourceUtilities; import org.eclipse.e4.ui.workbench.UIEvents; -import org.eclipse.e4.ui.workbench.modeling.ExpressionContext; import org.eclipse.e4.ui.workbench.swt.util.ISWTResourceUtilities; import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.EObject;
diff --git a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/MenuManagerRendererFilter.java b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/MenuManagerRendererFilter.java index 6855518..90fdd64 100644 --- a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/MenuManagerRendererFilter.java +++ b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/MenuManagerRendererFilter.java
@@ -10,6 +10,8 @@ *******************************************************************************/ package org.eclipse.e4.ui.workbench.renderers.swt; +import org.eclipse.e4.core.commands.ExpressionContext; + import java.util.HashMap; import java.util.HashSet; import javax.inject.Inject; @@ -36,7 +38,6 @@ import org.eclipse.e4.ui.model.application.ui.menu.MMenuElement; import org.eclipse.e4.ui.model.application.ui.menu.MPopupMenu; import org.eclipse.e4.ui.workbench.modeling.EModelService; -import org.eclipse.e4.ui.workbench.modeling.ExpressionContext; import org.eclipse.e4.ui.workbench.swt.factories.IRendererFactory; import org.eclipse.e4.ui.workbench.swt.modeling.MenuService; import org.eclipse.jface.action.MenuManager;
diff --git a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/MenuRenderer.java b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/MenuRenderer.java index e4e1b63..51b49d5 100644 --- a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/MenuRenderer.java +++ b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/MenuRenderer.java
@@ -10,6 +10,8 @@ *******************************************************************************/ package org.eclipse.e4.ui.workbench.renderers.swt; +import org.eclipse.e4.core.commands.ExpressionContext; + import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; @@ -24,7 +26,6 @@ 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.MMenuSeparator; -import org.eclipse.e4.ui.workbench.modeling.ExpressionContext; import org.eclipse.emf.ecore.EObject; import org.eclipse.swt.SWT; import org.eclipse.swt.events.DisposeEvent;
diff --git a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/RenderedToolBarRenderer.java b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/RenderedToolBarRenderer.java index 6e4a89b..064b8da 100644 --- a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/RenderedToolBarRenderer.java +++ b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/RenderedToolBarRenderer.java
@@ -10,6 +10,8 @@ *******************************************************************************/ package org.eclipse.e4.ui.workbench.renderers.swt; +import org.eclipse.e4.core.commands.ExpressionContext; + import java.util.ArrayList; import java.util.HashMap; import javax.inject.Inject; @@ -26,7 +28,6 @@ import org.eclipse.e4.ui.model.application.ui.menu.MToolBarContribution; import org.eclipse.e4.ui.model.application.ui.menu.MToolBarElement; import org.eclipse.e4.ui.workbench.IPresentationEngine; -import org.eclipse.e4.ui.workbench.modeling.ExpressionContext; import org.eclipse.emf.ecore.EObject; import org.eclipse.jface.action.ToolBarManager; import org.eclipse.swt.SWT;
diff --git a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/ToolBarContributionRecord.java b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/ToolBarContributionRecord.java index f320b51..96e4f67 100644 --- a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/ToolBarContributionRecord.java +++ b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/ToolBarContributionRecord.java
@@ -11,6 +11,8 @@ package org.eclipse.e4.ui.workbench.renderers.swt; +import org.eclipse.e4.core.commands.ExpressionContext; + import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; @@ -26,7 +28,6 @@ import org.eclipse.e4.ui.model.application.ui.menu.MToolBarContribution; import org.eclipse.e4.ui.model.application.ui.menu.MToolBarElement; import org.eclipse.e4.ui.model.application.ui.menu.MToolBarSeparator; -import org.eclipse.e4.ui.workbench.modeling.ExpressionContext; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.util.EcoreUtil; import org.eclipse.jface.action.ToolBarManager;
diff --git a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/ToolBarRenderer.java b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/ToolBarRenderer.java index 1f5be66..cc68138 100644 --- a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/ToolBarRenderer.java +++ b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/ToolBarRenderer.java
@@ -10,6 +10,8 @@ *******************************************************************************/ package org.eclipse.e4.ui.workbench.renderers.swt; +import org.eclipse.e4.core.commands.ExpressionContext; + import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; @@ -26,7 +28,6 @@ import org.eclipse.e4.ui.model.application.ui.menu.MToolBarElement; import org.eclipse.e4.ui.model.application.ui.menu.MToolBarSeparator; import org.eclipse.e4.ui.model.application.ui.menu.MToolControl; -import org.eclipse.e4.ui.workbench.modeling.ExpressionContext; import org.eclipse.jface.layout.RowLayoutFactory; import org.eclipse.swt.SWT; import org.eclipse.swt.events.DisposeEvent;
diff --git a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/TrimBarRenderer.java b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/TrimBarRenderer.java index 69cadb9..b09ced1 100644 --- a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/TrimBarRenderer.java +++ b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/TrimBarRenderer.java
@@ -11,6 +11,8 @@ package org.eclipse.e4.ui.workbench.renderers.swt; +import org.eclipse.e4.core.commands.ExpressionContext; + import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; @@ -26,7 +28,6 @@ import org.eclipse.e4.ui.model.application.ui.basic.MTrimElement; import org.eclipse.e4.ui.model.application.ui.basic.MTrimmedWindow; import org.eclipse.e4.ui.model.application.ui.menu.MTrimContribution; -import org.eclipse.e4.ui.workbench.modeling.ExpressionContext; import org.eclipse.swt.SWT; import org.eclipse.swt.events.DisposeEvent; import org.eclipse.swt.events.DisposeListener;
diff --git a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ContributionsAnalyzer.java b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ContributionsAnalyzer.java index 9d3291e..f6fe735 100644 --- a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ContributionsAnalyzer.java +++ b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ContributionsAnalyzer.java
@@ -11,6 +11,8 @@ package org.eclipse.e4.ui.internal.workbench; +import org.eclipse.e4.core.commands.ExpressionContext; + import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; @@ -41,7 +43,6 @@ import org.eclipse.e4.ui.model.application.ui.menu.MToolBarElement; import org.eclipse.e4.ui.model.application.ui.menu.MToolBarSeparator; import org.eclipse.e4.ui.model.application.ui.menu.MTrimContribution; -import org.eclipse.e4.ui.workbench.modeling.ExpressionContext; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.util.EcoreUtil;
diff --git a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/E4Workbench.java b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/E4Workbench.java index ae30b84..124b7ce 100644 --- a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/E4Workbench.java +++ b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/E4Workbench.java
@@ -12,6 +12,7 @@ package org.eclipse.e4.ui.internal.workbench; import java.util.List; +import org.eclipse.e4.core.commands.ExpressionContext; import org.eclipse.e4.core.contexts.EclipseContextFactory; import org.eclipse.e4.core.contexts.IEclipseContext; import org.eclipse.e4.core.services.contributions.IContributionFactory; @@ -21,7 +22,6 @@ import org.eclipse.e4.ui.model.application.ui.MContext; import org.eclipse.e4.ui.workbench.IPresentationEngine; import org.eclipse.e4.ui.workbench.IWorkbench; -import org.eclipse.e4.ui.workbench.modeling.ExpressionContext; import org.eclipse.emf.common.notify.Notifier; public class E4Workbench implements IWorkbench {
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/CommandToModelProcessor.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/CommandToModelProcessor.java index 4138a28..3dd6bd1 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/CommandToModelProcessor.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/CommandToModelProcessor.java
@@ -51,7 +51,7 @@ CommandManager commandManager = context.get(CommandManager.class); if (commandManager == null) { commandManager = new CommandManager(); - setCommandFireEvents(commandManager, false); + // setCommandFireEvents(commandManager, false); context.set(CommandManager.class, commandManager); } @@ -128,7 +128,7 @@ } } - private void setCommandFireEvents(CommandManager manager, boolean b) { + void setCommandFireEvents(CommandManager manager, boolean b) { try { Field f = CommandManager.class.getDeclaredField("shouldCommandFireEvents"); //$NON-NLS-1$ f.setAccessible(true);
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/ShowInMenu.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/ShowInMenu.java index 174379c..64dd101 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/ShowInMenu.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/ShowInMenu.java
@@ -11,6 +11,8 @@ package org.eclipse.ui.internal; +import org.eclipse.e4.core.commands.ExpressionContext; + import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; @@ -25,7 +27,6 @@ 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.workbench.modeling.ExpressionContext; import org.eclipse.jface.action.ContributionItem; import org.eclipse.jface.action.IContributionItem; import org.eclipse.jface.action.IMenuListener;
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/Workbench.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/Workbench.java index a96c2c2..a2a2126 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/Workbench.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/Workbench.java
@@ -30,9 +30,7 @@ import java.util.Set; import org.eclipse.core.commands.Command; import org.eclipse.core.commands.CommandManager; -import org.eclipse.core.commands.CommandManagerEvent; import org.eclipse.core.commands.ExecutionException; -import org.eclipse.core.commands.ICommandManagerListener; import org.eclipse.core.commands.NotEnabledException; import org.eclipse.core.commands.NotHandledException; import org.eclipse.core.commands.common.EventManager; @@ -1874,21 +1872,6 @@ appContext.set(IUpdateService.class, service); service.readRegistry(); - Command[] cmds = commandManager.getAllCommands(); - for (int i = 0; i < cmds.length; i++) { - Command cmd = cmds[i]; - cmd.setHandler(new MakeHandlersGo(this, cmd.getId())); - } - - commandManager.addCommandManagerListener(new ICommandManagerListener() { - public void commandManagerChanged(CommandManagerEvent commandManagerEvent) { - if (commandManagerEvent.isCommandDefined()) { - Command cmd = commandManagerEvent.getCommandManager().getCommand( - commandManagerEvent.getCommandId()); - cmd.setHandler(new MakeHandlersGo(Workbench.this, cmd.getId())); - } - } - }); return service; }
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchWindow.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchWindow.java index e42b1f0..612f8c4 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchWindow.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchWindow.java
@@ -172,6 +172,7 @@ import org.eclipse.ui.services.IEvaluationService; import org.eclipse.ui.services.IServiceScopes; import org.eclipse.ui.views.IViewDescriptor; +import org.eclipse.ui.views.IViewRegistry; import org.osgi.service.event.Event; import org.osgi.service.event.EventHandler; @@ -1141,6 +1142,7 @@ // Setup internal flags to indicate window is in // progress of closing and no update should be done. + closing = true; updateDisabled = true; try { @@ -1165,7 +1167,6 @@ windowClosed = workbench.close(); } else { if (okToClose()) { - closing = true; windowClosed = hardClose(remove); } } @@ -1414,46 +1415,43 @@ return PlatformUI.getWorkbench(); } - private void hideNonRestorableViews() { - List<MPart> sharedPartsToRemove = new ArrayList<MPart>(); - List<MPlaceholder> phList = modelService - .findElements(model, null, MPlaceholder.class, null); - for (MPlaceholder ph : phList) { - if (!(ph.getRef() instanceof MPart)) - continue; - - String partId = ph.getElementId(); - - // If the id contains a ':' use the part before it as the - // descriptor id - int colonIndex = partId.indexOf(':'); - String descId = colonIndex == -1 ? partId : partId.substring(0, colonIndex); - String secondaryId = colonIndex == -1 ? null : partId.substring(colonIndex + 1); - IViewDescriptor regEntry = ((Workbench) workbench).getViewRegistry().find(descId); - if (regEntry != null && !regEntry.isRestorable() && !("*".equals(secondaryId))) { //$NON-NLS-1$ - MElementContainer<MUIElement> phParent = ph.getParent(); - if (colonIndex != -1) { - // if it's a multi-instance part remove it (and its MPart) - if (!sharedPartsToRemove.contains(ph.getRef())) - sharedPartsToRemove.add((MPart) ph.getRef()); - ph.getParent().getChildren().remove(ph); - } else if (ph.isToBeRendered()) { - // just hide it (so we remember where to open it again - ph.setToBeRendered(false); - } - - // We need to do our own cleanup here... - int vc = modelService.countRenderableChildren(phParent); - if (vc == 0) { - phParent.setToBeRendered(false); + private void hideNonRestorablePlaceholder(MPlaceholder placeholder) { + MElementContainer<MUIElement> parent = placeholder.getParent(); + // if this placeholder is currently the selected element, its parent + // needs to select something else + if (parent.getSelectedElement() == placeholder) { + // if nothing found just set it to null + MUIElement candidate = null; + // search for a valid candidate from the list of children + for (MUIElement element : parent.getChildren()) { + if (element.isVisible() && element.isToBeRendered() && element != placeholder) { + candidate = element; + break; } } + + parent.setSelectedElement(candidate); } - // Remove the actual shared Parts for any placeholder that was removed - List<MUIElement> seList = model.getSharedElements(); - for (MPart partToRemove : sharedPartsToRemove) { - seList.remove(partToRemove); + // this tag is only applied to editors technically speaking, but better + // safe than sorry + MUIElement ref = placeholder.getRef(); + if (ref != null && ref.getTags().contains(EPartService.REMOVE_ON_HIDE_TAG)) { + parent.getChildren().remove(placeholder); + } + + placeholder.setToBeRendered(false); + } + + private void hideNonRestorableViews() { + List<MPlaceholder> placeholders = modelService.findElements(model, null, + MPlaceholder.class, null); + IViewRegistry registry = getWorkbench().getViewRegistry(); + for (MPlaceholder placeholder : placeholders) { + IViewDescriptor descriptor = registry.find(placeholder.getElementId()); + if (descriptor != null && !descriptor.isRestorable()) { + hideNonRestorablePlaceholder(placeholder); + } } }
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/commands/CommandManagerLegacyWrapper.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/commands/CommandManagerLegacyWrapper.java index dc88e35..7034c58 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/commands/CommandManagerLegacyWrapper.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/commands/CommandManagerLegacyWrapper.java
@@ -22,6 +22,7 @@ import org.eclipse.core.commands.contexts.ContextManager; import org.eclipse.core.commands.contexts.ContextManagerEvent; import org.eclipse.core.commands.contexts.IContextManagerListener; +import org.eclipse.e4.core.commands.internal.HandlerServiceImpl; import org.eclipse.jface.bindings.Binding; import org.eclipse.jface.bindings.BindingManager; import org.eclipse.jface.bindings.BindingManagerEvent; @@ -29,14 +30,12 @@ import org.eclipse.jface.bindings.Scheme; import org.eclipse.jface.bindings.TriggerSequence; import org.eclipse.jface.bindings.keys.ParseException; -import org.eclipse.ui.PlatformUI; import org.eclipse.ui.commands.CommandManagerEvent; import org.eclipse.ui.commands.ICategory; import org.eclipse.ui.commands.ICommand; import org.eclipse.ui.commands.ICommandManager; import org.eclipse.ui.commands.ICommandManagerListener; import org.eclipse.ui.commands.IKeyConfiguration; -import org.eclipse.ui.internal.MakeHandlersGo; import org.eclipse.ui.internal.handlers.LegacyHandlerWrapper; import org.eclipse.ui.internal.keys.SchemeLegacyWrapper; import org.eclipse.ui.internal.util.Util; @@ -288,7 +287,7 @@ public ICommand getCommand(String commandId) { final Command command = commandManager.getCommand(commandId); if (!command.isDefined()) { - command.setHandler(new MakeHandlersGo(PlatformUI.getWorkbench(), commandId)); + command.setHandler(HandlerServiceImpl.getHandler(commandId)); } return new CommandLegacyWrapper(command, bindingManager); }
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/commands/CommandPersistence.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/commands/CommandPersistence.java index aa2ff02..1e4df0e 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/commands/CommandPersistence.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/commands/CommandPersistence.java
@@ -24,6 +24,7 @@ import org.eclipse.core.runtime.IExtensionRegistry; import org.eclipse.core.runtime.IRegistryChangeEvent; import org.eclipse.core.runtime.Platform; +import org.eclipse.e4.core.commands.internal.HandlerServiceImpl; import org.eclipse.e4.ui.internal.workbench.Parameter; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.internal.WorkbenchMessages; @@ -206,6 +207,7 @@ } if (!command.isDefined()) { command.define(name, description, category, parameters, returnType, helpContextId); + command.setHandler(HandlerServiceImpl.getHandler(commandId)); } readState(configurationElement, warningsToLog, command); }
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/contexts/ContextService.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/contexts/ContextService.java index f0810e4..abd26d4 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/contexts/ContextService.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/contexts/ContextService.java
@@ -10,6 +10,8 @@ *******************************************************************************/ package org.eclipse.ui.internal.contexts; +import org.eclipse.e4.core.commands.ExpressionContext; + import java.util.Collection; import java.util.HashMap; import java.util.Iterator; @@ -24,7 +26,6 @@ import org.eclipse.e4.core.contexts.RunAndTrack; import org.eclipse.e4.ui.di.UISynchronize; import org.eclipse.e4.ui.services.EContextService; -import org.eclipse.e4.ui.workbench.modeling.ExpressionContext; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.ISourceProvider; import org.eclipse.ui.ISources;
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/handlers/CommandProxy.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/handlers/CommandProxy.java index 853ae62..4e2c32e 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/handlers/CommandProxy.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/handlers/CommandProxy.java
@@ -24,6 +24,8 @@ * */ public class CommandProxy { + private static boolean disabled = true; + private static Method firePreExecute = null; private static Method getFirePreExecute() { @@ -44,6 +46,8 @@ } public static void firePreExecute(Command command, ExecutionEvent event) { + if (disabled) + return; try { getFirePreExecute().invoke(command, event); } catch (IllegalArgumentException e) { @@ -82,6 +86,8 @@ * @param e */ public static void fireNotHandled(Command command, NotHandledException e) { + if (disabled) + return; try { getFireNotHandled().invoke(command, e); } catch (IllegalArgumentException e1) { @@ -120,6 +126,8 @@ * @param exception */ public static void fireNotEnabled(Command command, NotEnabledException exception) { + if (disabled) + return; try { getFireNotEnabled().invoke(command, exception); } catch (IllegalArgumentException e) { @@ -158,6 +166,8 @@ * @param exception */ public static void firePostExecuteFailure(Command command, ExecutionException exception) { + if (disabled) + return; try { getFirePostExecuteFailure().invoke(command, exception); } catch (IllegalArgumentException e) { @@ -196,6 +206,8 @@ * @param returnValue */ public static void firePostExecuteSuccess(Command command, Object returnValue) { + if (disabled) + return; try { getFirePostExecuteSuccess().invoke(command, returnValue); } catch (IllegalArgumentException e) {
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/handlers/E4HandlerProxy.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/handlers/E4HandlerProxy.java index 7e08b32..ed66861 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/handlers/E4HandlerProxy.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/handlers/E4HandlerProxy.java
@@ -11,6 +11,7 @@ package org.eclipse.ui.internal.handlers; +import java.util.Collections; import java.util.Map; import javax.inject.Named; import org.eclipse.core.commands.Command; @@ -22,6 +23,7 @@ import org.eclipse.core.commands.IHandlerListener; import org.eclipse.core.commands.NotHandledException; import org.eclipse.core.expressions.IEvaluationContext; +import org.eclipse.e4.core.commands.ExpressionContext; import org.eclipse.e4.core.commands.internal.HandlerServiceImpl; import org.eclipse.e4.core.contexts.IEclipseContext; import org.eclipse.e4.core.di.annotations.CanExecute; @@ -29,7 +31,6 @@ import org.eclipse.e4.core.di.annotations.Optional; import org.eclipse.e4.ui.internal.workbench.Activator; import org.eclipse.e4.ui.internal.workbench.Policy; -import org.eclipse.e4.ui.workbench.modeling.ExpressionContext; import org.eclipse.swt.widgets.Event; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.internal.MakeHandlersGo; @@ -70,7 +71,8 @@ if (appContext == null) { appContext = new ExpressionContext(context); } - ExecutionEvent event = new ExecutionEvent(command, parms, trigger, appContext); + ExecutionEvent event = new ExecutionEvent(command, parms == null ? Collections.EMPTY_MAP + : parms, trigger, appContext); if (handler != null && handler.isHandled()) { try { final Object returnValue = handler.execute(event);
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 2e2a79f..95f96ca 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
@@ -23,7 +23,6 @@ import org.eclipse.core.commands.Command; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; -import org.eclipse.core.commands.HandlerEvent; import org.eclipse.core.commands.IHandler; import org.eclipse.core.commands.NotEnabledException; import org.eclipse.core.commands.NotHandledException; @@ -40,6 +39,7 @@ import org.eclipse.core.runtime.IExtensionRegistry; import org.eclipse.e4.core.commands.ECommandService; import org.eclipse.e4.core.commands.EHandlerService; +import org.eclipse.e4.core.commands.ExpressionContext; import org.eclipse.e4.core.commands.internal.HandlerServiceImpl; import org.eclipse.e4.core.contexts.ContextFunction; import org.eclipse.e4.core.contexts.EclipseContextFactory; @@ -49,15 +49,12 @@ import org.eclipse.e4.core.di.annotations.Optional; import org.eclipse.e4.ui.internal.workbench.Activator; import org.eclipse.e4.ui.internal.workbench.Policy; -import org.eclipse.e4.ui.workbench.modeling.ExpressionContext; import org.eclipse.swt.widgets.Event; import org.eclipse.ui.ISourceProvider; import org.eclipse.ui.ISources; -import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.handlers.IHandlerActivation; import org.eclipse.ui.handlers.IHandlerService; -import org.eclipse.ui.internal.MakeHandlersGo; import org.eclipse.ui.internal.WorkbenchPlugin; import org.eclipse.ui.internal.e4.compatibility.E4Util; import org.eclipse.ui.internal.expressions.AndExpression; @@ -148,93 +145,31 @@ private static IHandlerActivation systemHandlerActivation; - /* - * We are obligated to return a non-null IHandlerActivation from our - * activate calls. It is only used as a token, but must not return null from - * certain methods. This token represents passing the MakeHandlerGo handler - * back into the system. - */ - private static IHandlerActivation getSystemHandlerActivation(IEclipseContext context, final String cmdId) { - if (systemHandlerActivation == null) { - final IWorkbench wb = context.get(IWorkbench.class); - systemHandlerActivation = new IHandlerActivation() { - - public int compareTo(Object o) { - return -1; - } - - public void setResult(boolean result) { - } - - public int getSourcePriority() { - return 0; - } - - public Expression getExpression() { - return null; - } - - public boolean evaluate(IEvaluationContext context) { - return false; - } - - public void clearResult() { - } - - public boolean isActive(IEvaluationContext context) { - return false; - } - - public IHandlerService getHandlerService() { - return (IHandlerService) wb.getService(IHandlerService.class); - } - - public IHandler getHandler() { - return null; - } - - public int getDepth() { - return 0; - } - - public String getCommandId() { - return cmdId; - } - - public void clearActive() { - } - }; - } - return systemHandlerActivation; - } public static IHandlerActivation registerLegacyHandler(final IEclipseContext context, String id, final String cmdId, IHandler handler, Expression activeWhen) { - if (handler instanceof MakeHandlersGo) { - final String msg = "Invalid Handler MakeHandlerGo"; //$NON-NLS-1$ - WorkbenchPlugin.log(msg, new Exception(msg)); - return getSystemHandlerActivation(context, cmdId); - } + ECommandService cs = (ECommandService) context.get(ECommandService.class.getName()); Command command = cs.getCommand(cmdId); - boolean handled = command.isHandled(); - boolean enabled = command.isEnabled(); + // boolean handled = command.isHandled(); + // boolean enabled = command.isEnabled(); E4HandlerProxy handlerProxy = new E4HandlerProxy(command, handler); HandlerActivation activation = new HandlerActivation(context, cmdId, handler, handlerProxy, activeWhen); addHandlerActivation(activation); EHandlerService hs = context.get(EHandlerService.class); hs.activateHandler(cmdId, new HandlerSelectionFunction(cmdId)); - boolean handledChanged = handled != command.isHandled(); - boolean enabledChanged = enabled != command.isEnabled(); - if (handledChanged || enabledChanged) { - IHandler proxy = command.getHandler(); - if (proxy instanceof MakeHandlersGo) { - ((MakeHandlersGo) proxy).fireHandlerChanged(new HandlerEvent(proxy, enabledChanged, - handledChanged)); - } - } + // boolean handledChanged = handled != command.isHandled(); + // boolean enabledChanged = enabled != command.isEnabled(); + // if (handledChanged || enabledChanged) { + // IHandler proxy = command.getHandler(); + // if (proxy instanceof MakeHandlersGo) { + // ((MakeHandlersGo) proxy).fireHandlerChanged(new HandlerEvent(proxy, + // enabledChanged, + // handledChanged)); + // } + // } return activation; }
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/menus/WorkbenchMenuService.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/menus/WorkbenchMenuService.java index 3a511f5..ca1aaac 100755 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/menus/WorkbenchMenuService.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/menus/WorkbenchMenuService.java
@@ -11,6 +11,8 @@ package org.eclipse.ui.internal.menus; +import org.eclipse.e4.core.commands.ExpressionContext; + import java.util.HashMap; import java.util.Map; import java.util.Set; @@ -23,7 +25,6 @@ import org.eclipse.e4.ui.model.application.ui.menu.MMenuContribution; import org.eclipse.e4.ui.model.application.ui.menu.MToolBarContribution; import org.eclipse.e4.ui.model.application.ui.menu.impl.MenuFactoryImpl; -import org.eclipse.e4.ui.workbench.modeling.ExpressionContext; import org.eclipse.e4.ui.workbench.renderers.swt.ContributionRecord; import org.eclipse.e4.ui.workbench.renderers.swt.ToolBarContributionRecord; import org.eclipse.jface.action.ContributionManager;
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/quickaccess/CommandProvider.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/quickaccess/CommandProvider.java index 289bde5..3b9ebe6 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/quickaccess/CommandProvider.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/quickaccess/CommandProvider.java
@@ -18,7 +18,7 @@ import org.eclipse.core.commands.ParameterizedCommand; import org.eclipse.core.commands.common.NotDefinedException; import org.eclipse.core.expressions.IEvaluationContext; -import org.eclipse.e4.ui.workbench.modeling.ExpressionContext; +import org.eclipse.e4.core.commands.ExpressionContext; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.commands.ICommandService;
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/services/EvaluationReference.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/services/EvaluationReference.java index b9b4838..31460a1 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/services/EvaluationReference.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/services/EvaluationReference.java
@@ -11,6 +11,8 @@ package org.eclipse.ui.internal.services; +import org.eclipse.e4.core.commands.ExpressionContext; + import org.eclipse.core.expressions.EvaluationResult; import org.eclipse.core.expressions.Expression; import org.eclipse.core.expressions.IEvaluationContext; @@ -19,7 +21,6 @@ import org.eclipse.e4.core.contexts.RunAndTrack; import org.eclipse.e4.ui.internal.workbench.Activator; import org.eclipse.e4.ui.internal.workbench.Policy; -import org.eclipse.e4.ui.workbench.modeling.ExpressionContext; import org.eclipse.jface.util.IPropertyChangeListener; import org.eclipse.jface.util.PropertyChangeEvent; import org.eclipse.ui.services.IEvaluationReference;
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 c225ace..efa9a72 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
@@ -11,6 +11,8 @@ package org.eclipse.ui.internal.services; +import org.eclipse.e4.core.commands.ExpressionContext; + import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -29,7 +31,6 @@ import org.eclipse.e4.core.contexts.IEclipseContext; import org.eclipse.e4.core.contexts.RunAndTrack; import org.eclipse.e4.ui.services.IServiceConstants; -import org.eclipse.e4.ui.workbench.modeling.ExpressionContext; import org.eclipse.jface.util.IPropertyChangeListener; import org.eclipse.jface.util.PropertyChangeEvent; import org.eclipse.jface.viewers.ISelection;
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/part/MultiPageEditorPart.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/part/MultiPageEditorPart.java index 3e9cd72..4aab06f 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/part/MultiPageEditorPart.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/part/MultiPageEditorPart.java
@@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2013 IBM Corporation and others. + * Copyright (c) 2000, 2011 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 @@ -498,8 +498,6 @@ * Subclasses may extend. */ public void dispose() { - deactivateSite(true, false); - pageChangeListeners.clear(); for (int i = 0; i < nestedEditors.size(); ++i) { IEditorPart editor = (IEditorPart) nestedEditors.get(i);
diff --git a/tests/org.eclipse.e4.core.commands.tests/META-INF/MANIFEST.MF b/tests/org.eclipse.e4.core.commands.tests/META-INF/MANIFEST.MF index 27a5956..acec24c 100644 --- a/tests/org.eclipse.e4.core.commands.tests/META-INF/MANIFEST.MF +++ b/tests/org.eclipse.e4.core.commands.tests/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Bundle-ManifestVersion: 2 Bundle-Name: Core commands Tests (Incubation) Bundle-SymbolicName: org.eclipse.e4.core.commands.tests;singleton:=true -Bundle-Version: 0.9.0.qualifier +Bundle-Version: 0.10.2.qualifier Bundle-RequiredExecutionEnvironment: J2SE-1.5 Require-Bundle: org.eclipse.core.commands;bundle-version="3.5.0", org.eclipse.e4.core.commands;bundle-version="0.9.0",
diff --git a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/commands/HandlerActivationTest.java b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/commands/HandlerActivationTest.java index d9d0764..cda97d2 100644 --- a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/commands/HandlerActivationTest.java +++ b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/commands/HandlerActivationTest.java
@@ -26,6 +26,7 @@ import org.eclipse.core.commands.common.NotDefinedException; import org.eclipse.core.commands.contexts.Context; import org.eclipse.core.expressions.IEvaluationContext; +import org.eclipse.e4.core.commands.internal.HandlerServiceImpl; import org.eclipse.ui.IPageLayout; import org.eclipse.ui.ISources; import org.eclipse.ui.IWorkbenchPart; @@ -36,7 +37,6 @@ import org.eclipse.ui.contexts.IContextService; import org.eclipse.ui.handlers.HandlerUtil; import org.eclipse.ui.handlers.IHandlerService; -import org.eclipse.ui.internal.MakeHandlersGo; import org.eclipse.ui.services.IServiceLocator; import org.eclipse.ui.tests.harness.util.UITestCase; import org.eclipse.ui.views.contentoutline.ContentOutline; @@ -204,7 +204,7 @@ if (!cmd.isDefined()) { Category cat = commandService.getCategory(CATEGORY_ID); cmd.define("Test Handler", "Test handler activation", cat); - cmd.setHandler(new MakeHandlersGo(getWorkbench(), CMD_ID)); + cmd.setHandler(HandlerServiceImpl.getHandler(CMD_ID)); } }