Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 64547 Details for
Bug 173213
[Commands] Show View cannot be executed from the Command Composer
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Hander Service v02
handlerservice-v02.txt (text/plain), 12.45 KB, created by
Paul Webster
on 2007-04-22 14:51:12 EDT
(
hide
)
Description:
Hander Service v02
Filename:
MIME Type:
Creator:
Paul Webster
Created:
2007-04-22 14:51:12 EDT
Size:
12.45 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.ui.workbench >Index: Eclipse UI/org/eclipse/ui/internal/handlers/HandlerAuthority.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/handlers/HandlerAuthority.java,v >retrieving revision 1.37 >diff -u -r1.37 HandlerAuthority.java >--- Eclipse UI/org/eclipse/ui/internal/handlers/HandlerAuthority.java 20 Apr 2007 16:35:31 -0000 1.37 >+++ Eclipse UI/org/eclipse/ui/internal/handlers/HandlerAuthority.java 22 Apr 2007 18:51:25 -0000 >@@ -12,6 +12,7 @@ > package org.eclipse.ui.internal.handlers; > > import java.util.Collection; >+import java.util.Collections; > import java.util.HashMap; > import java.util.HashSet; > import java.util.Iterator; >@@ -23,6 +24,7 @@ > import org.eclipse.core.commands.Command; > import org.eclipse.core.commands.IHandler; > import org.eclipse.core.commands.util.Tracing; >+import org.eclipse.core.expressions.EvaluationContext; > import org.eclipse.core.expressions.EvaluationResult; > import org.eclipse.core.expressions.Expression; > import org.eclipse.core.expressions.IEvaluationContext; >@@ -517,13 +519,15 @@ > } > > /** >- * Currently this is a kludge. >+ * Currently this is a an internal method to help locate a handler. > * <p> > * DO NOT CALL THIS METHOD. > * </p> > * >- * @param commandId the command id to check >- * @param the context to use for activations >+ * @param commandId >+ * the command id to check >+ * @param context >+ * the context to use for activations > * @since 3.3 > */ > public final IHandler findHandler(String commandId, >@@ -532,7 +536,7 @@ > if (o instanceof IHandlerActivation) { > IHandlerActivation activation = (IHandlerActivation) o; > try { >- if (activation.getExpression().evaluate(context) == EvaluationResult.TRUE) { >+ if (eval(context, activation)) { > return activation.getHandler(); > } > } catch (CoreException e) { >@@ -543,10 +547,10 @@ > IHandlerActivation lastActivation = null; > IHandlerActivation currentActivation = null; > Iterator i = activations.iterator(); >- while (i.hasNext()) { >+ while (i.hasNext() && lastActivation==null) { > IHandlerActivation activation = (IHandlerActivation) i.next(); > try { >- if (activation.getExpression().evaluate(context) == EvaluationResult.TRUE) { >+ if (eval(context, activation)) { > lastActivation = currentActivation; > currentActivation = activation; > } >@@ -554,15 +558,88 @@ > // OK, this one is out of the running > } > } >- if (currentActivation!=null) { >- if (lastActivation==null) { >+ if (currentActivation != null) { >+ if (lastActivation == null) { > return currentActivation.getHandler(); > } >- if (lastActivation.getSourcePriority()!=currentActivation.getSourcePriority()) { >- return currentActivation.getHandler(); >+ if (lastActivation.getSourcePriority() != currentActivation >+ .getSourcePriority()) { >+ return lastActivation.getHandler(); > } > } > } > return null; > } >+ >+ /** >+ * Evaluate the expression for the handler and bypass the result cache. >+ * <p> >+ * DO NOT CALL THIS METHOD. >+ * </p> >+ * >+ * @param context >+ * @param activation >+ * @return <code>true</code> if the handler expression can evaluate to >+ * true. >+ * @throws CoreException >+ * @since 3.3 >+ */ >+ private boolean eval(IEvaluationContext context, >+ IHandlerActivation activation) throws CoreException { >+ Expression expression = activation.getExpression(); >+ if (expression == null) { >+ return true; >+ } >+ return expression.evaluate(context) == EvaluationResult.TRUE; >+ } >+ >+ /** >+ * Normally the context returned from getCurrentState() still tracks the >+ * application state. This method creates a copy and fills it in with the >+ * variables that we know about. Currently it does not fill in the active >+ * selection. >+ * <p> >+ * DO NOT CALL THIS METHOD. It is experimental in 3.3. >+ * </p> >+ * >+ * @return an evaluation context with no parent. >+ * @since 3.3 >+ */ >+ public IEvaluationContext getContextSnapshot() { >+ EvaluationContext context = new EvaluationContext(null, >+ Collections.EMPTY_LIST); >+ IEvaluationContext tmpContext = getCurrentState(); >+ context.addVariable(ISources.ACTIVE_ACTION_SETS_NAME, tmpContext >+ .getVariable(ISources.ACTIVE_ACTION_SETS_NAME)); >+ context.addVariable(ISources.ACTIVE_CONTEXT_NAME, tmpContext >+ .getVariable(ISources.ACTIVE_CONTEXT_NAME)); >+ context.addVariable(ISources.ACTIVE_EDITOR_ID_NAME, tmpContext >+ .getVariable(ISources.ACTIVE_EDITOR_ID_NAME)); >+ context.addVariable(ISources.ACTIVE_EDITOR_NAME, tmpContext >+ .getVariable(ISources.ACTIVE_EDITOR_NAME)); >+ context.addVariable(ISources.ACTIVE_PART_ID_NAME, tmpContext >+ .getVariable(ISources.ACTIVE_PART_ID_NAME)); >+ context.addVariable(ISources.ACTIVE_PART_NAME, tmpContext >+ .getVariable(ISources.ACTIVE_PART_NAME)); >+ context.addVariable(ISources.ACTIVE_SITE_NAME, tmpContext >+ .getVariable(ISources.ACTIVE_SITE_NAME)); >+ context >+ .addVariable( >+ ISources.ACTIVE_WORKBENCH_WINDOW_IS_COOLBAR_VISIBLE_NAME, >+ tmpContext >+ .getVariable(ISources.ACTIVE_WORKBENCH_WINDOW_IS_COOLBAR_VISIBLE_NAME)); >+ context >+ .addVariable( >+ ISources.ACTIVE_WORKBENCH_WINDOW_IS_PERSPECTIVEBAR_VISIBLE_NAME, >+ tmpContext >+ .getVariable(ISources.ACTIVE_WORKBENCH_WINDOW_IS_PERSPECTIVEBAR_VISIBLE_NAME)); >+ context.addVariable(ISources.ACTIVE_WORKBENCH_WINDOW_NAME, tmpContext >+ .getVariable(ISources.ACTIVE_WORKBENCH_WINDOW_NAME)); >+ context >+ .addVariable( >+ ISources.ACTIVE_WORKBENCH_WINDOW_SHELL_NAME, >+ tmpContext >+ .getVariable(ISources.ACTIVE_WORKBENCH_WINDOW_SHELL_NAME)); >+ return context; >+ } > } >Index: Eclipse UI/org/eclipse/ui/internal/handlers/HandlerProxy.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/handlers/HandlerProxy.java,v >retrieving revision 1.19 >diff -u -r1.19 HandlerProxy.java >--- Eclipse UI/org/eclipse/ui/internal/handlers/HandlerProxy.java 29 Mar 2007 19:44:50 -0000 1.19 >+++ Eclipse UI/org/eclipse/ui/internal/handlers/HandlerProxy.java 22 Apr 2007 18:51:25 -0000 >@@ -19,7 +19,9 @@ > import org.eclipse.core.commands.HandlerEvent; > import org.eclipse.core.commands.IHandler; > import org.eclipse.core.commands.IHandlerListener; >+import org.eclipse.core.expressions.EvaluationResult; > import org.eclipse.core.expressions.Expression; >+import org.eclipse.core.expressions.IEvaluationContext; > import org.eclipse.core.runtime.CoreException; > import org.eclipse.core.runtime.IConfigurationElement; > import org.eclipse.core.runtime.IStatus; >@@ -158,10 +160,10 @@ > this.enabledWhenExpression = enabledWhenExpression; > this.evaluationService = evaluationService; > if (enabledWhenExpression != null) { >- proxyEnabled = false; >+ setProxyEnabled(false); > registerEnablement(); > } else { >- proxyEnabled = true; >+ setProxyEnabled(true); > } > } > >@@ -170,7 +172,26 @@ > */ > private void registerEnablement() { > enablementRef = evaluationService.addEvaluationListener( >- enabledWhenExpression, getEnablementListener(), PROP_ENABLED, null); >+ enabledWhenExpression, getEnablementListener(), PROP_ENABLED, >+ null); >+ } >+ >+ void setEnabledFor(IEvaluationContext context) throws ExecutionException { >+ if (enabledWhenExpression != null) { >+ try { >+ setProxyEnabled(enabledWhenExpression.evaluate(context) == EvaluationResult.TRUE); >+ } catch (CoreException e) { >+ throw new ExecutionException(e.getMessage(), e); >+ } >+ } >+ } >+ >+ void setProxyEnabled(boolean enabled) { >+ proxyEnabled = enabled; >+ } >+ >+ boolean getProxyEnabled() { >+ return proxyEnabled; > } > > /** >@@ -181,12 +202,9 @@ > enablementListener = new IPropertyChangeListener() { > public void propertyChange(PropertyChangeEvent event) { > if (event.getProperty() == PROP_ENABLED) { >- if (event.getNewValue() != null) { >- proxyEnabled = ((Boolean) event.getNewValue()) >- .booleanValue(); >- } else { >- proxyEnabled = false; >- } >+ setProxyEnabled(event.getNewValue() == null ? false >+ : ((Boolean) event.getNewValue()) >+ .booleanValue()); > fireHandlerChanged(new HandlerEvent(HandlerProxy.this, > true, false)); > } >@@ -227,7 +245,7 @@ > public final boolean isEnabled() { > if (enabledWhenExpression != null) { > // proxyEnabled reflects the enabledWhen clause >- if (!proxyEnabled) { >+ if (!getProxyEnabled()) { > return false; > } > if (isOkToLoad() && loadHandler()) { >Index: Eclipse UI/org/eclipse/ui/internal/handlers/HandlerService.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/handlers/HandlerService.java,v >retrieving revision 1.23 >diff -u -r1.23 HandlerService.java >--- Eclipse UI/org/eclipse/ui/internal/handlers/HandlerService.java 29 Mar 2007 19:09:44 -0000 1.23 >+++ Eclipse UI/org/eclipse/ui/internal/handlers/HandlerService.java 22 Apr 2007 18:51:25 -0000 >@@ -75,7 +75,7 @@ > * @param evaluationService > * The evaluation service to use; must not be <code>null</code>. > */ >- public HandlerService(final ICommandService commandService, >+ public HandlerService(final ICommandService commandService, > final IEvaluationService evaluationService) { > if (commandService == null) { > throw new NullPointerException( >@@ -83,7 +83,8 @@ > } > this.commandService = commandService; > this.handlerAuthority = new HandlerAuthority(commandService); >- this.handlerPersistence = new HandlerPersistence(this, evaluationService); >+ this.handlerPersistence = new HandlerPersistence(this, >+ evaluationService); > } > > public final IHandlerActivation activateHandler( >@@ -225,19 +226,89 @@ > ISources.ACTIVE_SHELL_NAME, shell); > } > } >- >+ > /** >- * Currently this is a kludge. >+ * Currently this is a an internal method to help locate a handler. > * <p> > * DO NOT CALL THIS METHOD. > * </p> > * >- * @param commandId the command id to check >- * @param the context to use for activations >+ * @param commandId >+ * the command id to check >+ * @param context >+ * the context to use for activations > * @since 3.3 > */ > public final IHandler findHandler(String commandId, > IEvaluationContext context) { > return handlerAuthority.findHandler(commandId, context); > } >+ >+ /** >+ * Normally the context returned from getCurrentState() still tracks the >+ * application state. This method creates a copy and fills it in with the >+ * variables that we know about. Currently it does not fill in the active >+ * selection. >+ * <p> >+ * DO NOT CALL THIS METHOD. It is experimental in 3.3. >+ * </p> >+ * >+ * @return an evaluation context with no parent. >+ * @since 3.3 >+ */ >+ public final IEvaluationContext getContextSnapshot() { >+ return handlerAuthority.getContextSnapshot(); >+ } >+ >+ /** >+ * Execute the command using the provided context. It takes care of finding >+ * the correct active handler given the context, and executes with that >+ * handler. >+ * <p> >+ * It currently cannot effect the enablement of the handler. >+ * </p> >+ * <p> >+ * DO NOT CALL THIS METHOD. It is experimental in 3.3. >+ * </p> >+ * >+ * @param command >+ * the parameterized command to execute >+ * @param trigger >+ * the SWT event trigger ... can be null >+ * @param context >+ * the evaluation context to run against. >+ * @return >+ * @throws ExecutionException >+ * @throws NotDefinedException >+ * @throws NotEnabledException >+ * @throws NotHandledException >+ * @since 3.3 >+ * @see #getContextSnapshot() >+ */ >+ public final Object executeCommandInContext( >+ final ParameterizedCommand command, final Event trigger, >+ IEvaluationContext context) throws ExecutionException, >+ NotDefinedException, NotEnabledException, NotHandledException { >+ IHandler oldHandler = command.getCommand().getHandler(); >+ >+ IHandler handler = findHandler(command.getId(), context); >+ boolean enabled = true; >+ if (handler instanceof HandlerProxy) { >+ enabled = ((HandlerProxy) handler).getProxyEnabled(); >+ } >+ >+ try { >+ command.getCommand().setHandler(handler); >+ if (handler instanceof HandlerProxy) { >+ ((HandlerProxy) handler).setEnabledFor(context); >+ } >+ >+ return command.executeWithChecks(trigger, context); >+ } finally { >+ if (handler instanceof HandlerProxy) { >+ ((HandlerProxy) handler).setProxyEnabled(enabled); >+ } >+ command.getCommand().setHandler(oldHandler); >+ } >+ } > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 173213
:
61932
|
62000
|
62012
|
64257
| 64547