Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Eclipse menu : update command state(Delete/Copy command state is not updated in the main menu)
Eclipse menu : update command state [message #651703] Tue, 01 February 2011 11:09 Go to next message
Nicolas Guyomar is currently offline Nicolas GuyomarFriend
Messages: 29
Registered: February 2010
Location: Nantes (France)
Junior Member
Hi everyone,

I have been using commands/handlers to build menus in an editor and a view following http://wiki.eclipse.org/Menu_Contributions

I have extended org.eclipse.ui.edit.delete and org.eclipse.ui.edit.copy in order to implement my own handlers.

Those handlers work perfectly fine with keyBinding or within a contextual menu, the handler isEnabled() method is called.

The problem I'm facing is that the Eclipse main menu Edit>Delete and Edit>Copy is not updated when my selection changes.
If I want it to be updated, I need to select an element in my editor, give the focus to an other one and give the focus back to my editor. This way the handler isEnabled() method is called and the Edit menu is updated.

I feel like I should fire an event when my selection changes so that the Worbench would know he has to update its menu, but I do not know how to fire it, or from where ?

I hope my problem description is clear enought

Regards

Nicolas Guyomar
--
http://www.eclipse.org/MoDisco/
http://www.eclipse.org/modeling/emft/facet/


Re: Eclipse menu : update command state [message #651709 is a reply to message #651703] Tue, 01 February 2011 11:33 Go to previous messageGo to next message
Animesh Kumar is currently offline Animesh KumarFriend
Messages: 79
Registered: September 2010
Location: Bangalore
Member
Hi,
Is your isHandled() method in the Handler returning true?
If not, try the changing the return statement method of the isHandled method.
Regards,
Animesh


Regards,
Animesh

[Updated on: Tue, 01 February 2011 11:35]

Report message to a moderator

Re: Eclipse menu : update command state [message #651723 is a reply to message #651709] Tue, 01 February 2011 12:44 Go to previous messageGo to next message
Nicolas Guyomar is currently offline Nicolas GuyomarFriend
Messages: 29
Registered: February 2010
Location: Nantes (France)
Junior Member
Hi,

The isHandled() method returns true but is only called when I try to execute the command (either from the contextual menu or the keyBinding).

If the delete/copy menu item state is enabled when it should not be according to my selection, I get the
org.eclipse.core.commands.NotEnabledException: Trying to execute the disabled command org.eclipse.ui.edit.delete
exception

Regards,
NIcolas


Re: Eclipse menu : update command state [message #651751 is a reply to message #651703] Tue, 01 February 2011 13:25 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

On 02/01/2011 06:09 AM, Nicolas Guyomar wrote:
> The problem I'm facing is that the Eclipse main menu Edit>Delete and
> Edit>Copy is not updated when my selection changes.

What version of eclipse are you based on? Is it an RCP app or running
in the eclipse workbench? How are Copy and Delete being contributed to
the Edit menu?

PW

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


Re: Eclipse menu : update command state [message #651756 is a reply to message #651751] Tue, 01 February 2011 13:44 Go to previous messageGo to next message
Nicolas Guyomar is currently offline Nicolas GuyomarFriend
Messages: 29
Registered: February 2010
Location: Nantes (France)
Junior Member
Hi,
I'm using Eclipse Version: 3.7.0 Build id: I20101028-1441

The application is running in the Eclipse Workbench as an installed plugin.

I have declared my handler for the delete command in my plugin.xml file, and set the <activeWhen> only on my part's ID, both editor and view.

 <extension
         point="org.eclipse.ui.handlers">
      <handler
            class="org.eclipse.emf.facet.widgets.nattable.handlers.DeleteHandler"
            commandId="org.eclipse.ui.edit.delete">
         <activeWhen>
            <or>
               <with   variable="activePartId">
                  <equals
                        value="org.eclipse.emf.facet.widgets.nattable.workbench.view.NatTableView">
                  </equals>
               </with>
               <with    variable="activePartId">
                  <equals
                        value="org.eclipse.emf.facet.widgets.nattable.workbench.editor.NatTableEditor">
                  </equals>
               </with>
            </or>
         </activeWhen>
      </handler>      
   </extension>


Then in order to use it in my contextual menu ( code for the editor popup menu)

<menuContribution
            allPopups="false"
            locationURI="popup:org.eclipse.emf.facet.widgets.nattable.workbench.editor.NatTableEditor">
         <command
               commandId="org.eclipse.ui.edit.delete"               
               icon="IMG_ETOOL_DELETE"
               style="push">
         </command>
  </menuContribution>


I did nothing to contribute to the Edit menu because the menu item are already in it.
I assumed those menu items (delete, copy paste ... ) behaviour had to be implemented by each contributor.

Regards,
Nicolas


Re: Eclipse menu : update command state [message #651852 is a reply to message #651756] Tue, 01 February 2011 19:18 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

On 02/01/2011 08:44 AM, Nicolas Guyomar wrote:
> <activeWhen>
> <or>
> <with variable="activePartId">
> <equals
> value=" org.eclipse.emf.facet.widgets.nattable.workbench.view.NatTab leView ">
> </equals>
> </with>
> <with variable="activePartId">
> <equals
> value=" org.eclipse.emf.facet.widgets.nattable.workbench.editor.NatT ableEditor ">
> </equals>
> </with>
> </or>
> </activeWhen>

Just as an aside, you would probably do:
<activeWhen>
<with variable="activePartId">
<or>
<equals value="...view.NatTableView"/>
<equals value="...editor.NatTableEditor"/>
</or>
</with>
</activeWhen>


>
> I did nothing to contribute to the Edit menu because the menu item are
> already in it. I assumed those menu items (delete, copy paste ... )
> behaviour had to be implemented by each contributor.

If you want to update the enabled state your handler has to call
org.eclipse.core.commands.AbstractHandler.setBaseEnabled(boo lean) when
the important information (like the selection in the editor it cares
about) changes.

Either that, or you need to provide an enabledWhen clause as well as the
activeWhen clause, where it can respond to changes in your editor's
selection.

PW


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


icon14.gif  Re: Eclipse menu : update command state [message #651959 is a reply to message #651852] Wed, 02 February 2011 09:29 Go to previous message
Nicolas Guyomar is currently offline Nicolas GuyomarFriend
Messages: 29
Registered: February 2010
Location: Nantes (France)
Junior Member
Hi Paul,

Thanks for the <activeWhen> first tips.

I did manage to update the state of my handler by adding a selectionChangedListener on my editor/view, and then by calling org.eclipse.core.commands.AbstractHandler.setBaseEnabled(boo lean).

Tank you for your help

Regards,
Nicolas


Previous Topic:Why does my RCP application not look like Eclipse?
Next Topic:Linking to a toc.xml which doesn't have any html contents
Goto Forum:
  


Current Time: Thu Mar 28 22:46:37 GMT 2024

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

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

Back to the top