Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Update Toolbar(Need to update the toolbar if something is selected in a table)
Update Toolbar [message #499300] Fri, 20 November 2009 17:22 Go to next message
dwain Missing name is currently offline dwain Missing nameFriend
Messages: 35
Registered: October 2009
Member
I have an RCP application that has a table view. In that view I have a delete button that I want to be active when something in the table is selected. So I created the command:
      <command id="com.plugin.security.command.delete" name="Delete ">
      </command>


and the handler:
      <handler class="com.plugin.security.commands.Delete" commandId="com.plugin.security.command.delete">
         <activeWhen>
            <with variable="selection">
               <iterate ifEmpty="false" operator="or">
               </iterate>
            </with>
         </activeWhen>
      </handler>


Which works if you select an item from the table and then minimize then restore the window. But that is not a good way to to have your menu update. So I also added a SelectionChanged listener to the table and attempted to get the toolbar manager for that view and update it but was unable to find the manager. How can I get the toolbar to update?

Thank you,
Dwain
Re: Update Toolbar [message #499304 is a reply to message #499300] Fri, 20 November 2009 17:55 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Did you use a table viewer? Did you set it up as the selection provider for your view?

There's nothing inherently wrong with your activeWhen, except use <count/> instead of <iterate/>

PW


Re: Update Toolbar [message #506059 is a reply to message #499304] Tue, 05 January 2010 22:39 Go to previous messageGo to next message
dwain Missing name is currently offline dwain Missing nameFriend
Messages: 35
Registered: October 2009
Member
Thank you very much for your response Paul. I am using a TableViewer that sits on a CTabItem in a view. After I create the TableViewer I set the selection provider by
//resultsTableViewer is my TableViewer
getSite().setSelectionProvider(resultsTableViewer);


I think that is the proper way to set the selection provider. Since it does get enabled after you minimize then restore your window. But it does not get enabled when you select something. I also changed the activeWhen to the following:

   <extension point="org.eclipse.ui.handlers">
      <handler class="com.vanns.plugin.security.commands.Delete" commandId="com.vanns.plugin.security.commands.delete">
         <activeWhen>
            <with variable="selection">
               <count value="1">
               </count>
            </with>
         </activeWhen>
      </handler>
   </extension>


Which I believe is correct but not completely certain on that either. Any other ideas for this problem?

Thanks
Re: Update Toolbar [message #506196 is a reply to message #506059] Wed, 06 January 2010 14:07 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Have you implemented setFocus() in your viewpart?

When the table has 1 thing selected your command should be active. When
the table has 2 things enabled your command should be disabled. You
shouldn't have to min/max or change active part focus to get it to work.

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/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm


Re: Update Toolbar [message #506557 is a reply to message #506196] Thu, 07 January 2010 23:58 Go to previous messageGo to next message
dwain Missing name is currently offline dwain Missing nameFriend
Messages: 35
Registered: October 2009
Member
Yes I have implemented the setFocus() method. Right now it is just empty. I tried setting the appropriate SelectionProvider, which is the TableViewer that is on the CTabItem that is currently selected, in that method but that did not work either. Is there a method I should call to update the menu after I set the provider? If there is an editor open and I have something in the TableViewer selected and give the editor focus, then give the focus back to the view that contains the table then the menu item gets updated.

[Updated on: Fri, 08 January 2010 00:06]

Report message to a moderator

Re: Update Toolbar [message #506705 is a reply to message #506557] Fri, 08 January 2010 21:21 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

dwain wrote:
> Yes I have implemented the setFocus() method. Right now it is just
> empty.

setFocus() has to set the focus on the SWT control. i.e. if you
generate the Sample View with a tree or table, you'll see a common
implementation with for a part with a viewer.

your selection provider should be set in the createPartControl(*) method:

getSite().setSelectionProvider(viewer)

Later,
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/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm


Re: Update Toolbar [message #508687 is a reply to message #506705] Tue, 19 January 2010 20:44 Go to previous message
dwain Missing name is currently offline dwain Missing nameFriend
Messages: 35
Registered: October 2009
Member
Thank you very much for all your help Paul. I finally got this working. I was able to find the answer in the article http://www.eclipse.org/articles/Article-WorkbenchSelections/ article.html which informed me that "Replacing the selection provider during the lifetime of the part is not properly supported by the workbench" and that was my problem. I was resetting the selection provider for each tab when it gained focus. I was able to make it work by making my view the selection provider and then having the view determine what is selected by what tab is the currently selected tab. Thanks again.

Dwain
Previous Topic:Calls functionalities of a plugin with another one
Next Topic:JWS RCP java.lang.RuntimeException: No application id has been found
Goto Forum:
  


Current Time: Thu Apr 18 14:37:22 GMT 2024

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

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

Back to the top