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 #505357] Tue, 29 December 2009 22:37 Go to next message
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 #505477 is a reply to message #505357] Thu, 31 December 2009 06:50 Go to previous messageGo to next message
Prakash G.R. is currently offline Prakash G.R.
Messages: 621
Registered: July 2009
Senior Member
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>
Re: One command and handler per menu entry? [message #505495 is a reply to message #505477] Thu, 31 December 2009 11:17 Go to previous messageGo to next message
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 #505645 is a reply to message #505495] Mon, 04 January 2010 05:38 Go to previous message
Prakash G.R. is currently offline Prakash G.R.
Messages: 621
Registered: July 2009
Senior Member
On 31/12/09 4:47 PM, klm wrote:
> 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.

You should be looking at the command parameters then:
http://blog.eclipse-tips.com/2008/12/commands-part-3-paramet ers-for-commands.html

- Prakash
Platform UI Team, IBM

Blog <http://blog.eclipse-tips.com>
Twitter <http://www.twitter.com/Eclipse_Tips>
Re: One command and handler per menu entry? [message #603900 is a reply to message #505357] Thu, 31 December 2009 06:50 Go to previous message
Prakash G.R. is currently offline Prakash G.R.
Messages: 621
Registered: July 2009
Senior Member
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>
Re: One command and handler per menu entry? [message #603904 is a reply to message #505477] Thu, 31 December 2009 11:17 Go to previous message
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 #603921 is a reply to message #505495] Mon, 04 January 2010 05:38 Go to previous message
Prakash G.R. is currently offline Prakash G.R.
Messages: 621
Registered: July 2009
Senior Member
On 31/12/09 4:47 PM, klm wrote:
> 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.

You should be looking at the command parameters then:
http://blog.eclipse-tips.com/2008/12/commands-part-3-paramet ers-for-commands.html

- Prakash
Platform UI Team, IBM

Blog <http://blog.eclipse-tips.com>
Twitter <http://www.twitter.com/Eclipse_Tips>
Previous Topic:IPluginModelBase listener + stale information
Next Topic:How to set up cross/hybrid target platform for RCP and RAP plugins?
Goto Forum:
  


Current Time: Fri Oct 24 08:52:00 GMT 2014

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

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