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
Hi,
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
handler.

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?
Thanks!
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!
Thanks!

<extension
point="org.eclipse.ui.commands">
<category
description="My Category."
id="com.myapp.commands.category"
name="My Commands">
</category>
<command
categoryId="com.myapp.commands.category"
id="com.myapp.commands.activate"
name="Activate">
</command>
:

<extension
point="org.eclipse.ui.menus">
<menuContribution
locationURI="menu:org.eclipse.ui.main.menu?before=window">
<menu
label="My Menu">
<command
commandId="com.myapp.activate">
</command>
:

<extension
point="org.eclipse.ui.handlers">
<handler
class="com.myapp.handlers.ActivateHandler"
commandId="com.myapp.commands.activate">
</handler>
:
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
http://help.eclipse.org/ganymede/index.jsp?topic=/org.eclips e.platform.doc.isv/reference/extension-points/org_eclipse_ui _handlers.html

PW


--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/ganymede/index.jsp?topic=/org.eclips e.platform.doc.isv/guide/workbench.htm


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


Current Time: Fri Mar 29 07:54:31 GMT 2024

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

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

Back to the top