Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Plugin Development Environment (PDE) » One command and handler per menu entry?
One command and handler per menu entry? [message #603889] Tue, 29 December 2009 22:37
Eclipse UserFriend
Originally posted by:

I would like to create a menu with two or more entries. Currently I create
each entry using a command and and a handler and adds the commands to a menu
in a menuContribution.

For both handlers I specify the same class which looks like this:

public class SampleHandler extends AbstractHandler {
private final static String commandID1= "command1";
private final static String commandID2= "command2";

public SampleHandler() {

* the command has been executed, so extract extract the needed information
* from the application context.
public Object execute(ExecutionEvent event) throws ExecutionException {
IWorkbenchWindow window =
String commandID = event.getCommand().getId();

if(commandID.equals(commandID1)) {

// Do action for command 1

if(commandID.equals(commandID2)) {

// Do action for command 2

return null;

But if I want 10 entries in the same menu the above begins to look ugly (I
also need to define 10 commands and 10 handlers). Further its error prone to
specify the command ID's manually and do the string matching. It would be
better if a list of available commands could be iterated.

Is there a better way to add multiple entries to a menu or do I need to
specify a single command and handler per entry?
Previous Topic:actionsSet is visible in all perspectives
Next Topic:actionsSet is visible in all perspectives
Goto Forum:

Current Time: Fri Aug 14 03:11:18 GMT 2020

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

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

Back to the top