Skip to main content



      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
Eclipse UserFriend
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] by 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
Eclipse UserFriend
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
Eclipse UserFriend
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
Eclipse UserFriend
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
Eclipse UserFriend
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
Eclipse UserFriend
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
Eclipse UserFriend
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: Wed Jul 23 12:03:56 EDT 2025

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

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

Back to the top