One command and handler per menu entry? [message #505357] |
Tue, 29 December 2009 22:37 |
Eclipse User |
|
|
|
Originally posted by: ddd.asd.com
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 =
HandlerUtil.getActiveWorkbenchWindowChecked(event);
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?
|
|
|
|
Re: One command and handler per menu entry? [message #505495 is a reply to message #505477] |
Thu, 31 December 2009 11:17 |
Eclipse User |
|
|
|
Originally posted by: asd.asd.com
"Prakash G.R." <grprakash@gmail.com> wrote in message
news:hhhhk3$ulk$1@build.eclipse.org...
> On 30/12/09 4:07 AM, klm wrote:
> > For both handlers I specify the same class which looks like this:
>
> That doesn't look right. Why would two commands have a single handler
> class? Would it be more meaningful if they were done by different classes?
>
>
> - Prakash
> Platform UI Team, IBM
>
> Blog <http://blog.eclipse-tips.com>
> Twitter <http://www.twitter.com/Eclipse_Tips>
Yes that was also my original approach but creating a:
command
handler
handlerClass
for each menu entry seems a bit overkill. When entry 1 from the menu is
selected application 1 is launced, when entry 2 from the menu is selected
application 2 is launched.... and so fourth.
|
|
|
|
|
Re: One command and handler per menu entry? [message #603904 is a reply to message #505477] |
Thu, 31 December 2009 11:17 |
Eclipse User |
|
|
|
Originally posted by: asd.asd.com
"Prakash G.R." <grprakash@gmail.com> wrote in message
news:hhhhk3$ulk$1@build.eclipse.org...
> On 30/12/09 4:07 AM, klm wrote:
> > For both handlers I specify the same class which looks like this:
>
> That doesn't look right. Why would two commands have a single handler
> class? Would it be more meaningful if they were done by different classes?
>
>
> - Prakash
> Platform UI Team, IBM
>
> Blog <http://blog.eclipse-tips.com>
> Twitter <http://www.twitter.com/Eclipse_Tips>
Yes that was also my original approach but creating a:
command
handler
handlerClass
for each menu entry seems a bit overkill. When entry 1 from the menu is
selected application 1 is launced, when entry 2 from the menu is selected
application 2 is launched.... and so fourth.
|
|
|
|
Powered by
FUDForum. Page generated in 0.02439 seconds