How do I create this handler expression at runtime? [message #325018] |
Tue, 05 February 2008 17:36  |
Eclipse User |
|
|
|
Originally posted by: none.ibm.com
From the help, there is a handler with an enablement expression.
<extension
point="org.eclipse.ui.handlers">
<handler
commandId="commandId"
class="org.eclipse.Handler">
<enabledWhen>
<with variable="activeContexts">
<iterator operator="or">
<equals value="org.eclipse.ui.contexts.window"/>
</iterator>
</with>
</enabledWhen>
</handler>
</extension>
How do I create this expression at runtime? Do I have to create a DOM and
run it through ExpressionConverter?
|
|
|
|
|
Re: How do I create this handler expression at runtime? [message #325056 is a reply to message #325051] |
Thu, 07 February 2008 03:15   |
Eclipse User |
|
|
|
Yes, I think there is a much easier way to do this. I'm assuming you
are using 3.3 or higher. The key to the solution is your statement
about "when the user is in one place in the UI". Do you mean a
particular editor or view?
You can set handlers for commands which will be active only when the
Part is active. Like this:
// Do this when your part is initializing
IHandlerService handlerService = (IHandlerService)part.getSite()
.getService(IHandlerService.class);
handlerService.activateHandler(ID_COMMAND_COPY, new
AbstractHandler()
{
@Override
public Object execute(ExecutionEvent event)
throws ExecutionException
{
// Do the work
return null;
}
});
This handler is then made active whenever the part is active.
If you need more control, then you can associate an expression with your
handler in the configuration to check other conditions, like the current
selection.
Randy Hudson wrote:
> Thanks for the detailed example. I sure hope there is an easier way.
>
> Here's what I'm trying to do. I have two instances of an action with a
> keybinding. For example, "Select All". When the user is in one place of
> the UI, I want one action to be active. And in another place, the other
> action. I was thinking I could simply turn on and off the contexts for
> these "places" or modes of the UI. But these contexts aren't of interest to
> the User, so I didn't want to declare them and have them appear in the
> keybinding preferences.
>
> Shouldn't I be able to programmatically register a Handler with the
> condition "context is A", or "color is blue"? My backup plan is to just
> unregister and reregister actions with the keybinding service based on the
> users context.
>
> "Francis Upton" <francisu@ieee.org> wrote in message
> news:fobiot$r0o$1@build.eclipse.org...
>> I think the answer to your question is yes if you want to stick to the API.
>>
>> If you don't want to create a DOM, you can use another mechanism that
>> defines extension points directly in XML, though I think that API is
>> subject to change. Here is an example of how it's used:
>
>
|
|
|
Re: How do I create this handler expression at runtime? [message #325067 is a reply to message #325056] |
Thu, 07 February 2008 09:44   |
Eclipse User |
|
|
|
Originally posted by: none.ibm.com
> Yes, I think there is a much easier way to do this. I'm assuming you are
> using 3.3 or higher. The key to the solution is your statement about
> "when the user is in one place in the UI". Do you mean a particular
> editor or view?
No, I mean a sub-section inside an editor or view. The editor is compound.
> You can set handlers for commands which will be active only when the Part
> is active. Like this:
>
> // Do this when your part is initializing
> IHandlerService handlerService = (IHandlerService)part.getSite()
> .getService(IHandlerService.class);
I want this, except "part" is not a workbench part, but an arbitrary "mode"
or perhaps an SWT control nested within my (editor)part.
> If you need more control, then you can associate an expression with your
> handler in the configuration to check other conditions, like the current
> selection.
I think I do need more control. The problem with associating an expression
seems to be that I have to do it at development time, instead of at runtime.
This seems like a gap in the expressions support. I shouldn't have to use
extensions unless I am extending some other plug-in. Also, I want to
inherit the command definition from the editor, but simply swap out the
handler based on sub-context. I don't want to define real command
definitions and contexts for each specific handler for the *same* command.
|
|
|
|
Powered by
FUDForum. Page generated in 0.03156 seconds