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 13:40 Go to next message
ModelGeek Mising name is currently offline ModelGeek Mising nameFriend
Messages: 529
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 13: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 13:58 Go to previous messageGo to next message
El Shorty is currently offline El ShortyFriend
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 14:30 Go to previous messageGo to next message
ModelGeek Mising name is currently offline ModelGeek Mising nameFriend
Messages: 529
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 14:56 Go to previous messageGo to next message
Libor Jelinek is currently offline Libor JelinekFriend
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 15:03 Go to previous messageGo to next message
Agata Vackova is currently offline Agata VackovaFriend
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 21:28 Go to previous messageGo to next message
Libor Jelinek is currently offline Libor JelinekFriend
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 12:23 Go to previous message
Paul Webster is currently offline Paul WebsterFriend
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: Mon Nov 24 12:37:17 GMT 2014

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

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