Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Bind a custom SWT button to command / handler
Bind a custom SWT button to command / handler [message #644549] Mon, 13 December 2010 08:50 Go to next message
Christophe Fondacci is currently offline Christophe Fondacci
Messages: 95
Registered: July 2009
Location: Paris
Member
Hello all,

I face the following problem :
I have a command and a handler which I use in a key binding for a text editor.
In this editor, I have a toolbar on top where there are some action button which need to do the same action as the key binding.
Since I got a command and a handler for the key binding, I would like to trigger the same code when the user pushes one of the toolbar button.

I need to mention that I do not want the controls to be on the main toolbar (though I don't want to use ActionBarContributor), I want those controls to be INSIDE the editor.

Ideally, I would love to contribute commands to editor toolbar exactly as I can do with views (through "toolbar:viewId?after=additions") but it seems not to be supported.

Alternatively, I look for a way to bind my own SWT button to an existing command so that its handler would be called when pressed.

Is there a way to achieve this ?

Thank you for any help,
Christophe
http://www.nextep-softwares.com
Re: Bind a custom SWT button to command / handler [message #644601 is a reply to message #644549] Mon, 13 December 2010 12:30 Go to previous messageGo to next message
Paul Webster is currently offline Paul Webster
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

If you have your own ToolBarManager, you can call
org.eclipse.ui.menus.IMenuService.populateContributionManage r(ContributionManager,
String)

Just remember to release the contributions when you are done with that
ToolBarManager.

In general, you can add a command to a MenuManager/ToolBarManager using
org.eclipse.ui.menus.CommandContributionItem, and worst case you can
programmatically execute an existing command using one of the
org.eclipse.ui.handlers.IHandlerService.executeCommand(*) methods.

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: Bind a custom SWT button to command / handler [message #644673 is a reply to message #644601] Mon, 13 December 2010 17:37 Go to previous message
Christophe Fondacci is currently offline Christophe Fondacci
Messages: 95
Registered: July 2009
Location: Paris
Member
Thank you, it works like a charm !

In case others interested, here is the working code :
	final ToolBar tb = new ToolBar(parent, SWT.NONE);
	tb.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
	tbm = new ToolBarManager(tb);
	tbm.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
	final IMenuService menuService = (IMenuService) getSite().getService(IMenuService.class);
	menuService.populateContributionManager(tbm, "toolbar:" + EDITOR_ID);
	// Explicit update needed otherwise contributions not displayed
	tbm.update(true);


Christophe.
http://www.nextep-softwares.com
Previous Topic:Calling a command in an headless RCP application
Next Topic:How to integrate own Viewer in RCP
Goto Forum:
  


Current Time: Fri Oct 24 07:21:31 GMT 2014

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

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