Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Key binding and selection in viewer(How to test selection in viewer and get the selection in handler for key binding?)
Key binding and selection in viewer [message #685299] Fri, 17 June 2011 08:30 Go to next message
Martin W is currently offline Martin WFriend
Messages: 7
Registered: July 2009
Junior Member
I have a command which I use in a popup menu in a tree viewer and I want to reuse for key binding:

<command commandId="my.command.delete" label="Delete">
   <visibleWhen>
      <reference definitionId="my.expression.delete"></reference>
   </visibleWhen>
</command>

<definition id="my.expression.delete">
   <with variable="activeMenuSelection">
      <iterate ifEmpty="false" operator="and">
         <or>
            <instanceof value="model.IOne"></instanceof>
            <instanceof value="model.ITwo"></instanceof>
         </or>
      </iterate>
   </with>
</definition>


This command is only visible if the specified objects are selected. Now I want to support deleting these objects also by the DEL key. So I have add a new key binding;

<key commandId="my.delete" contextId="my.navigationView" schemeId="my.scheme" sequence="DEL"></key>


But I have two problems: How can I reuse my delete expression for my key binding? Of course 'activeMenuSelection' doesn't work in this case. But how can I test which objects are selected? In my DeleteHandler I call 'HandlerUtil.getActiveMenuSelection(event)' to get the selection. How can I get the selection independent of the call by popup menu or by DEL key.

I understand that eclipse doesn't know that the context of my key binding is only activated if the tree viewer of my navigation view has the focus. My key binding should be only active if the command is visible in the popup menu.

[Updated on: Fri, 17 June 2011 09:14]

Report message to a moderator

Re: Key binding and selection in viewer [message #685551 is a reply to message #685299] Fri, 17 June 2011 18:17 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

A keybinding is valid in an over-arching kind of context. In your case, as long as the my.navigationView context is active. Presumably it was activated in your view createPartControl(*).

That keybinding will always point to that command. But you can 1) determine if a handler is active for that command and/or 2) determine if that handler thinks it is enabled. Both activeWhen and enabledWhen are supported in org.eclipse.ui.handlers.

Outside of a context menu, you would need to use selection instead of activeMenuSelection.

PW


Re: Key binding and selection in viewer [message #685796 is a reply to message #685551] Mon, 20 June 2011 07:10 Go to previous messageGo to next message
Martin W is currently offline Martin WFriend
Messages: 7
Registered: July 2009
Junior Member
Thanks for your reply.

Quote:
In your case, as long as the my.navigationView context is active. Presumably it was activated in your view createPartControl(*).

My context my.navigationView is only active as long the tree viewer having the focus.

Quote:
Outside of a context menu, you would need to use selection instead of activeMenuSelection.

This was also my first idea. But it didn't work.

<handler class="handlers.DeleteHandler" commandId="my.command.delete">
   <activeWhen>
      <with variable="selection">
         <iterate ifEmpty="false" operator="and">
            <or>
               <instanceof value="model.IOne"></instanceof>
               <instanceof value="model.ITwo"></instanceof>
            </or>
         </iterate>
      </with>
   </activeWhen>
</handler>


The command is always disabled, in popup menu and as key binding. But if I replace <with variable="selection"> with <with variable="activeMenuSelection">, my command is at least enabled in my popup menu. But how can I enable my command also as key binding?
Re: Key binding and selection in viewer [message #685810 is a reply to message #685796] Mon, 20 June 2011 09:13 Go to previous message
Martin W is currently offline Martin WFriend
Messages: 7
Registered: July 2009
Junior Member
I have found the problem: The selection provider wasn't set in my view.
Previous Topic:How do I add a control to the beginning of the status line?
Next Topic:Grey Background in Forms Toolbar
Goto Forum:
  


Current Time: Tue Apr 23 06:34:05 GMT 2024

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

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

Back to the top