Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Adding command, menu contributions, handlers programmatically
Adding command, menu contributions, handlers programmatically [message #819915] Tue, 13 March 2012 09:40 Go to next message
ModelGeek Mising name is currently offline ModelGeek Mising name
Messages: 500
Registered: June 2011
Senior Member
Hi,

I would like to add commands, menu contributions, handlers programmatically. Is there any example available? For example all menus like File, Edit and all commands with handlers are defined programmatically.

thanks for assistance

Cheers,

[Updated on: Tue, 13 March 2012 09:49]

Report message to a moderator

Re: Adding command, menu contributions, handlers programmatically [message #819927 is a reply to message #819915] Tue, 13 March 2012 09:58 Go to previous messageGo to next message
El Shorty is currently offline El Shorty
Messages: 37
Registered: March 2012
Member
Hi,

I have a small example of handler I made to open a dialog

public class AddressDialogHandler extends AbstractHandler implements IHandler {

	@Override
	public Object execute(ExecutionEvent event) throws ExecutionException {
		final Shell s = HandlerUtil.getActiveShellChecked(event);
		
		new AddressDialog(s).open();
		return null;
	}

}


Hope it helps
Re: Adding command, menu contributions, handlers programmatically [message #819946 is a reply to message #819927] Tue, 13 March 2012 10:30 Go to previous messageGo to next message
ModelGeek Mising name is currently offline ModelGeek Mising name
Messages: 500
Registered: June 2011
Senior Member
Thanks!
I would like to know how i would attach this handler to command programmatically, and how i can add that command to menucomtribution programtically and how menuContribution can be added to menu bar programmatically.

Actually, i would like to create menubars and toolbars programatically,

if i can get a few lines of code showing how to add one menuContribution to menu bar, and how to add one command to menucontribution and how to attach handler to command then it will be much easier for me to understand.


thanks in advance!

cheers,
Re: Adding command, menu contributions, handlers programmatically [message #819963 is a reply to message #819946] Tue, 13 March 2012 10:56 Go to previous messageGo to next message
Libor Jelinek is currently offline Libor Jelinek
Messages: 143
Registered: January 2012
Location: Prague, Czech Rep.
Senior Member

Within org.eclipse.ui.menus extension point, in its <menuContribution> element is attribute class than can supply "content" of menu programmatically.

Checkout doc for org.eclipse.ui.menus:

<menuContribution
locationURI="menu:someorg.somemenu.id?after=additions">


class - If this optional attribute is specified the provided class will be instantiated and used to provide menu contributions at this location. If provided, all child elements will be ignored.
Re: Adding command, menu contributions, handlers programmatically [message #819967 is a reply to message #819963] Tue, 13 March 2012 11:03 Go to previous messageGo to next message
Agata Vackova is currently offline Agata Vackova
Messages: 9
Registered: February 2012
Junior Member
class must implement ExtensionContributionFactory. Could you provide an example?
Re: Adding command, menu contributions, handlers programmatically [message #820210 is a reply to message #819967] Tue, 13 March 2012 17:28 Go to previous messageGo to next message
Libor Jelinek is currently offline Libor Jelinek
Messages: 143
Registered: January 2012
Location: Prague, Czech Rep.
Senior Member

Have a look at e.g. this guru Lars' post.
Re: Adding command, menu contributions, handlers programmatically [message #825918 is a reply to message #820210] Wed, 21 March 2012 08:23 Go to previous message
Paul Webster is currently offline Paul Webster
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

For the basic window menu structure, you can create that using your ActionBarAdvisor. Add MenuManagers for each of File, Edit, Help, etc.

You can also add CommandContributionItems directly to the MenuManager you create, hooking them up to commands. org.eclipse.ui.IWorkbenchCommandConstants has a good list of command IDs supplied by the workbench.

PW


Previous Topic:ToggelCommand dynamically assign state
Next Topic:wrong handler for keybinding Ctrl+V when using multiple TextEditors
Goto Forum:
  


Current Time: Fri Aug 22 21:47:59 EDT 2014

Powered by FUDForum. Page generated in 0.01766 seconds