3.3: org.eclipse.ui.menus and parameterized commands - how to en/disable the visible menu when one c [message #467652] |
Wed, 09 May 2007 13:51  |
Eclipse User |
|
|
|
I am using the new 3.3 menu extension point (entries below). I have a
single handler that handles the "record navigation" command. The
command takes a single parameter (an enum) that indicates the navigation
type such as MoveFirst(move to the first record), MoveLast, Add (add a
record) etc. This is in contrast to having 8 different commands and
handlers and implementing the handlers in classes multiple times.
The handler handles the command and uses the parameter to determine
which method to call on an appropriately tagged editor part. When the
right type of editor is active, I need to keep all the record navigation
menu entries visible but dis/enable their states based on the state of
the edited record e.g. the save button should only be enabled when the
record has been modified in some way.
How do I control the enablement state of the visible menu entry on the
screen via programming when I only have one handler handling all of the
commands and I want to keep all of the menu entries visible? The main
record navigation menu entry is only visible when an editor that
implements the interface tag is active but I need to enable at the menu
contribution level as well.
All of the menu/command stuff works fine, I just can't seem to get hold
an IContributionItem that allows me to set the enablement state of a
particular menu entry. IContributionItem does not have a setEnable()
method on it only a isEnabled() method.
The words navigation below refers to record navigation and the concept
of actions below refers to the action of navigation not an IAction object.
========org.eclipse.ui.menu extension point entry
<menuContribution locationURI="menu:org.eclipse.ui.main.menu?after=edit">
<menu id="navigation" label="Navigation">
<command id="navigation.moveFirst"
commandId="navigation.navigate" label="Move First">
<parameter name="action" value="MoveFirst" />
</command>
<command id="navigation.movePrevious"
commandId="navigation.navigate" label="Move Previous">
<parameter name="action" value="MovePrevious" />
</command>
<command id="navigation.moveNext"
commandId="navigation.navigate" label="Move Next">
<parameter name="action" value="MoveNext" />
</command>
<command id="navigation.moveFirst"
commandId="navigation.navigate" label="Move Last">
<parameter name="action" value="MoveLast" />
</command>
<separator name="sep1" visible="true" />
<command id="navigation.save" commandId="navigation.navigate"
label="Save Changes">
<parameter name="action" value="Save" />
</command>
<command id="navigation.add" commandId="navigation.navigate"
label="Add New">
<parameter name="action" value="Add" />
</command>
<separator name="sep2" visible="true" />
<command id="navigation.revert" commandId="navigation.navigate"
label="Revert Changes">
<parameter name="action" value="Revert" />
</command>
<separator name="sep3" visible="true" />
<command id="delete" commandId="navigation.navigate"
label="Delete Current">
<parameter name="action" value="Delete" />
</command>
<visibleWhen>
<with variable="activePart">
<instanceof
value="org.myapp.ui.actions.IRecordNavigationCapable" />
</with>
</visibleWhen>
</menu>
</menuContribution>
================the command
<command
categoryId="navigator"
description="Perform a navigation action."
id="navigation.navigate"
name="Perform Navigation Action"
defaultHandler="org.myapp.ui.actions.RecordNavigationHandler ">
<commandParameter
id="action"
name="Navigation Action"
values="org.myapp.ui.actions.RecordNavigationValues"/>
</command>
===================the handler
public class RecordNavigationHandler extends AbstractHandler {
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IWorkbenchPart part = HandlerUtil.getActivePartChecked(event);
if (part instanceof IRecordNavigationCapable) {
IRecordNavigationCapable p = (IRecordNavigationCapable)part;
String actionParam = event.getParameter("action");
RecordNavigationAction actionEnum =
RecordNavigationAction.valueOf(actionParam);
p.navigate(actionEnum);
}
return null;
}
}
================interface tag
public interface IRecordNavigationCapable {
void navigate(RecordNavigationAction action);
}
|
|
|
|
|
|
|
|
Re: 3.3: org.eclipse.ui.menus and parameterized commands - how to en/disable the visible menu when o [message #467779 is a reply to message #467771] |
Thu, 10 May 2007 13:33   |
Eclipse User |
|
|
|
aappddeevv wrote:
> I took a deeper look at the recommendation but there is no obvious way
> to get to contribution item that somehow understands setEnabled().
> UIElement enablement is all based on the handler presence. While
> UIElement has some setText() type methods, etc. it lacks setEnabled().
>
> Any other ideas? It looks like I need to create 8 command and handler
> subclasses or log this as a feature request.
Sorry, I went back and re-read your post.
You are correct, it won't work for enablement which is a property of the
command itself by way of the current active handler (and all of your
parameterized commands are really just pointing at one command). My
UIElement example is about updating properties of the UI element
(MenuItem or ToolItem) like label, icon, things that can be rendered.
You can (and probably should) log a feature request (although I'm not
sure what can be done because of the architecture). In any event it
won't be looked at until 3.4 (June 2008)
In the short term you will need to create multiple commands. You can
reuse your handler, however, by making it an IExecutableExtension and
then for each time you specify the handler class append a :MoveFirst or
so. This will be passed to your handler's setInitializationData(*) method.
BTW: Save, Add, Revert, and Delete are are not navigation actions and
deserve their own command anyway :-)
PW
|
|
|
Re: 3.3: org.eclipse.ui.menus and parameterized commands - how to en/disable the visible menu when o [message #467812 is a reply to message #467779] |
Thu, 10 May 2007 17:53   |
Eclipse User |
|
|
|
Thanks for the feedback and I will look into the approach you mention.
True they are not navigation events :-)
I am thinking in the spirit of the BindingNavigator that .Net has for
navigating between records and doing things to lists of records in the
interface.
Paul Webster wrote:
> aappddeevv wrote:
>> I took a deeper look at the recommendation but there is no obvious way
>> to get to contribution item that somehow understands setEnabled().
>> UIElement enablement is all based on the handler presence. While
>> UIElement has some setText() type methods, etc. it lacks setEnabled().
>>
>> Any other ideas? It looks like I need to create 8 command and handler
>> subclasses or log this as a feature request.
>
> Sorry, I went back and re-read your post.
>
> You are correct, it won't work for enablement which is a property of the
> command itself by way of the current active handler (and all of your
> parameterized commands are really just pointing at one command). My
> UIElement example is about updating properties of the UI element
> (MenuItem or ToolItem) like label, icon, things that can be rendered.
>
>
> You can (and probably should) log a feature request (although I'm not
> sure what can be done because of the architecture). In any event it
> won't be looked at until 3.4 (June 2008)
>
> In the short term you will need to create multiple commands. You can
> reuse your handler, however, by making it an IExecutableExtension and
> then for each time you specify the handler class append a :MoveFirst or
> so. This will be passed to your handler's setInitializationData(*) method.
>
> BTW: Save, Add, Revert, and Delete are are not navigation actions and
> deserve their own command anyway :-)
>
> PW
|
|
|
Re: 3.3: org.eclipse.ui.menus and parameterized commands - how to en/disable the visible menu when o [message #467815 is a reply to message #467812] |
Thu, 10 May 2007 20:44  |
Eclipse User |
|
|
|
BTW, so far after looking into IExecutableExtension as well as
manipulating the execution context/evaluation context, I am frustrated
that it so hard to changed the enablement state in a menu in a straight
forward, programmatic way.
After more browsing, another way appears could work is to use the "test"
expression which when combined with the <with variable="activeEditor">
may allow me to use an intercepting class that knows about special
methods on my editor subclass reflecting the state of the "navigation"
menu options. This way, I can decouple my editor class from handlers
and commands altogether which is what I want.
Ouch!
aappddeevv wrote:
> Thanks for the feedback and I will look into the approach you mention.
>
> True they are not navigation events :-)
>
> I am thinking in the spirit of the BindingNavigator that .Net has for
> navigating between records and doing things to lists of records in the
> interface.
>
>
> Paul Webster wrote:
>> aappddeevv wrote:
>>> I took a deeper look at the recommendation but there is no obvious way
>>> to get to contribution item that somehow understands setEnabled().
>>> UIElement enablement is all based on the handler presence. While
>>> UIElement has some setText() type methods, etc. it lacks setEnabled().
>>>
>>> Any other ideas? It looks like I need to create 8 command and
>>> handler subclasses or log this as a feature request.
>>
>> Sorry, I went back and re-read your post.
>>
>> You are correct, it won't work for enablement which is a property of
>> the command itself by way of the current active handler (and all of
>> your parameterized commands are really just pointing at one command).
>> My UIElement example is about updating properties of the UI element
>> (MenuItem or ToolItem) like label, icon, things that can be rendered.
>>
>>
>> You can (and probably should) log a feature request (although I'm not
>> sure what can be done because of the architecture). In any event it
>> won't be looked at until 3.4 (June 2008)
>>
>> In the short term you will need to create multiple commands. You can
>> reuse your handler, however, by making it an IExecutableExtension and
>> then for each time you specify the handler class append a :MoveFirst
>> or so. This will be passed to your handler's setInitializationData(*)
>> method.
>>
>> BTW: Save, Add, Revert, and Delete are are not navigation actions and
>> deserve their own command anyway :-)
>>
>> PW
|
|
|
Powered by
FUDForum. Page generated in 0.04416 seconds