Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » reusable collapse all action?
reusable collapse all action? [message #505334] Tue, 29 December 2009 11:33 Go to next message
Natasha D'Silva is currently offline Natasha D'Silva
Messages: 25
Registered: July 2009
Junior Member
Hi,
I have a view with a treeviewer, and I am wondering if there is a simple way to reuse a collapse all action, in such a way that I could perhaps declare it in the plugin.xml and it would show up in the view toolbar, re-using icon and or handlers. Is this possible? I suppose it might not be since the handler would need access to the view's treeviewer. I looked at the org.eclipse.ui.CollapseAllHandler but I am not sure how to create an action in the view that links to the handler.

One problem I am trying to avoid is creating and identical copy of icons that are already in use elsewhere in the workbench, e.g. the collapse all icon. Is there a way to reuse an icon from another plugin's image registry? Something similar is done for fonts and colors in the JFaceResources, but I looked at its image registry but was unsuccessful.

Any help is appreciated,
Thanks.
Re: reusable collapse all action? [message #505916 is a reply to message #505334] Tue, 05 January 2010 09:48 Go to previous messageGo to next message
Paul Webster is currently offline Paul Webster
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

You activate org.eclipse.ui.handlers.CollapseAllHandler against your
viewer in your part (usually where you create your viewer). That should
allow the keybinding to work.

Then you can simply put the command id (stored in the constant
org.eclipse.ui.IWorkbenchCommandConstants.NAVIGATE_COLLAPSE_ ALL) in your
toolbar or menu using the org.eclipse.ui.menus extension point.

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: reusable collapse all action? [message #506031 is a reply to message #505916] Tue, 05 January 2010 14:39 Go to previous messageGo to next message
Natasha D'Silva is currently offline Natasha D'Silva
Messages: 25
Registered: July 2009
Junior Member
Thanks, that worked!
Re: reusable collapse all action? [message #506064 is a reply to message #506031] Tue, 05 January 2010 18:31 Go to previous messageGo to next message
Natasha D'Silva is currently offline Natasha D'Silva
Messages: 25
Registered: July 2009
Junior Member
Actually, I think there is a regression in 3.6, as this does not work. When I register the handler, my view's toolbar loses 3 or so of its actions, they aren't visible until I resize the view, and a text label appears for the collapse all action.
I have tested with the Sample view, and I still get the same problem.
Create a plugin using the Sample view template, and select a Tree viewer when prompted. Modify the view's get part control to add this at the end of the method, and you will see that several of the actions are missing.
IWorkbenchPartSite site = getSite();
		if (site != null) {
			IHandlerService handlerService = (IHandlerService) site.getService(
					IHandlerService.class);
			if (handlerService != null) {
				fCollapseHandler = new CollapseAllHandler(viewer);
				handlerService.activateHandler(CollapseAllHandler.COMMAND_ID, fCollapseHandler, null);
			}
		}



EDIT:
Here is a screenshot. The picture on the left shows the collapse all action when the handler is not activated, and the middle and right pictures show what the view looks like afterwards.
http://img10.imageshack.us/img10/8449/screenshotqb.png

[Updated on: Tue, 05 January 2010 18:45]

Report message to a moderator

Re: reusable collapse all action? [message #506190 is a reply to message #506064] Wed, 06 January 2010 04:00 Go to previous messageGo to next message
Paul Webster is currently offline Paul Webster
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Natasha D'Silva wrote:
> IWorkbenchPartSite site = getSite();
> if (site != null) {
> IHandlerService handlerService = (IHandlerService)
> site.getService(
> IHandlerService.class);
> if (handlerService != null) {
> fCollapseHandler = new CollapseAllHandler(viewer);
>
> handlerService.activateHandler(CollapseAllHandler.COMMAND_ID ,
> fCollapseHandler, null);
> }
> }

What XML are you using to add the command to the toolbar?

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: reusable collapse all action? [message #506225 is a reply to message #506190] Wed, 06 January 2010 10:36 Go to previous messageGo to next message
Natasha D'Silva is currently offline Natasha D'Silva
Messages: 25
Registered: July 2009
Junior Member
Here is the XML:

 <extension
         point="org.eclipse.ui.menus">
          <menuContribution
            locationURI="toolbar:p0.views.SampleView?after=additions">
         <command
               commandId="org.eclipse.ui.navigate.collapseAll"
               style="push">
         </command>
      </menuContribution>
      </extension>

Thanks!
Re: reusable collapse all action? [message #509922 is a reply to message #506225] Mon, 25 January 2010 14:07 Go to previous messageGo to next message
Paul Webster is currently offline Paul Webster
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Natasha D'Silva wrote:
> Here is the XML:
>
>
> <extension
> point="org.eclipse.ui.menus">
> <menuContribution
> locationURI="toolbar:p0.views.SampleView?after=additions">

Your XML looks fine as well as your handler activation. I'll fire up
the Sample view on the pre-M5 I builds and see if I can repo.

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: reusable collapse all action? [message #509933 is a reply to message #509922] Mon, 25 January 2010 14:25 Go to previous messageGo to next message
Paul Webster is currently offline Paul Webster
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

I create the plugin with a view (Sample View) and add the similar code
from your example:

IWorkbenchPartSite site = getSite();
if (site != null) {
IHandlerService handlerService = (IHandlerService) site.getService(
IHandlerService.class);
if (handlerService != null) {
fCollapseHandler = new CollapseAllHandler(viewer);
handlerService.activateHandler(CollapseAllHandler.COMMAND_ID ,
fCollapseHandler);
}
}

<extension
point="org.eclipse.ui.menus">
<menuContribution
locationURI="toolbar:z.ex.sample.view.views.SampleView">
<command
commandId="org.eclipse.ui.navigate.collapseAll"
style="push">
</command>
</menuContribution>
</extension>

When I launch the 3.6 SDK and open the view I see the entire toolbar and
the command is enabled. I can see the toolbar whether it's beside the
tabs or if enough tabs are open to move it to the second line.

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: reusable collapse all action? [message #803398 is a reply to message #505334] Tue, 21 February 2012 04:43 Go to previous message
Sreekanth SC is currently offline Sreekanth SC
Messages: 14
Registered: January 2011
Junior Member
Hi Paul,

I see the solution you have given to provide collapse-all/expand-all toolbar button to user defined views. Currently I am working on XText, and I have an editor defined for xtext and an outline view to show the elements in the editor. Its the normal eclipse outline view and it has options A-Z sorting and Link with editor toolbar buttons.

Now I have a requirement to add Collapse_All and Expand_All toolbar buttons to this Outline view. Is there any way I can do this?

Please do the needful. Thanks Smile

[Updated on: Tue, 21 February 2012 04:44]

Report message to a moderator

Previous Topic:Functionality of "Working Sets..." menu bar action in Breakpoints View
Next Topic:FilteredTree
Goto Forum:
  


Current Time: Wed Aug 27 23:22:59 EDT 2014

Powered by FUDForum. Page generated in 0.03914 seconds