Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Menu bar not checking handler enablement
Menu bar not checking handler enablement [message #336070] Tue, 19 May 2009 10:25 Go to next message
Rob is currently offline RobFriend
Messages: 27
Registered: July 2009
Junior Member
I have created a command, which I have added to the main menu bar and as a
context menu to a tree viewer.
The enablement of the command depends on the tree node selected, and this
is checked programmatically using the isEnabled() method of the commands

Now, it works fine for the context menu - i can see that isEnabled() is
called before the context menu is displayed, and the enablement state is
updated correctly.
However, when the menu is shown from the main menu bar - isEnabled() is
not called, and the command does not have the correct state. Note: if I
hide and open the rcp app window, isEnabled() is called and the state is
correct from the main menu.

Could anyone offer help on this? I guess I need the main menu to check the
enablement of handlers before it is displayed?
xml supplied [message #336079 is a reply to message #336070] Wed, 20 May 2009 13:37 Go to previous messageGo to next message
Rob is currently offline RobFriend
Messages: 27
Registered: July 2009
Junior Member
Here are pieces of the xml i'm using. It's pretty simple stuff. I know the
plugin is being loaded. From what I could find on the web, if no
<enabledWhen> flag is specified, the isEnabled() method on the handler
should be called. However, this is still not being called when the menu
"My Menu" is opened from the menu bar.

Any help on this would be great - i've been trying to fix it for days!

description="My Category."
name="My Commands">

label="My Menu">

Re: Menu bar not checking handler enablement [message #336087 is a reply to message #336070] Wed, 20 May 2009 17:48 Go to previous message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

If you are implementing isEnabled() programmatically, you need to
determine your enabled state yourself, and then update it and fire the
appropriate HandlerEvent (from 3.4 and on, you should be subclassing and
using org.eclipse.core.commands.AbstractHandler.setBaseEnabled(boo lean))

It's up to you to track the selection changes if you are managing your
handler enablement programmatically.

You can also enter an enabledWhen clause in your
org.eclipse.ui.handlers/handler definition:

<enabledWhen><with variable="selection"> <count value="1"/> <iterate
ifEmpty="false"> <!-- check node here--> <instanceof
value="com.example.MyLeaf"/> </iterate> </with> </enabledWhen>

Check out e.platform.doc.isv/reference/extension-points/org_eclipse_ui _handlers.html


Paul Webster e.platform.doc.isv/guide/workbench.htm

Previous Topic:Access handler reference
Next Topic:More control over Eclipse builders
Goto Forum:

Current Time: Sun Jun 17 22:29:46 GMT 2018

Powered by FUDForum. Page generated in 0.01507 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top