Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » E4 Commands and Handlers
E4 Commands and Handlers [message #787666] Tue, 31 January 2012 21:14 Go to next message
Josh Davis is currently offline Josh DavisFriend
Messages: 20
Registered: August 2011
Junior Member
Should this code work?
ECommandService eCommandService = context.get(ECommandService.class);
final Category lunch = eCommandService.getCategory("z.ex.view.keybindings.category");
        if (!lunch.isDefined()) {
            lunch.define("Lunch", "Actions take at lunch time.");
        }
final Command eatTaco = eCommandService.getCommand("z.ex.view.keybindings.eatTaco");
        if (!eatTaco.isDefined()) {
            eatTaco.define("Eat That Taco", "Go for the taco.", lunch);
        }

EHandlerService eHandlerService = context.get(EHandlerService.class);
final IHandler handler = new AbstractHandler() {
   public Object execute(final ExecutionEvent event) throwsExecutionException {
                System.out.println("Eat that Taco");
                return null;
            }
        };
        eHandlerService.activateHandler("z.ex.view.keybindings.eatTaco", handler);


I can't seem to get it to do what I am expecting.
I expect the command to be created (which it does) and then a handler added to the command (which it does not)
I copied this example from an example for adding commands and handlers in e3. I modified how the services are looked up

When activateHandler is called shouldn't eatTaco.getHandler() not be null? Unfortunately it is still null. I am having the same issue when I try to use the compatibility layer (IHandlerService and ICommandService is used in the e3 example)
Re: E4 Commands and Handlers [message #787699 is a reply to message #787666] Tue, 31 January 2012 22:04 Go to previous messageGo to next message
Lars Vogel is currently offline Lars VogelFriend
Messages: 1098
Registered: July 2009
Senior Member

I don't think that will work. Mixing Eclipse 4 and Eclipse 3 is AFAIK not supported.

Not sure if you have seen this, but I have an updated version of my Eclipse 4 Tutorial online. I'm not covering exactly your case but I also show how to dynamically add model elements.

Mayby it helps.

[Updated on: Tue, 31 January 2012 22:25]

Report message to a moderator

Re: E4 Commands and Handlers [message #787708 is a reply to message #787699] Tue, 31 January 2012 22:21 Go to previous messageGo to next message
Josh Davis is currently offline Josh DavisFriend
Messages: 20
Registered: August 2011
Junior Member
Thanks for the reply Lars. I always check your tutorial and Tom's before I post. So I am familiar with it. If the solution to my issue is in your tutorial, I am not seeing it. I am not sure what you meant by "Mixing Eclipse 4 and Eclipse 4 is AFAIK not supported." I think you might have meant Eclipse 3?
I don't think my above code example has Eclipse 3 in it, unless I am overlooking something.
EHandlerService is a e4 class from what I can tell.

I mentioned e3 in my post because we also have some classes that are trying to add commands and activate handlers using the ICommandService and IHandlerService which I would expect to be handled by the compatibility layer. When I step through the code it looks like it is trying to activate the handler, however once the logic is done the command doesn't seem to be getting assigned the handler.
Re: E4 Commands and Handlers [message #787716 is a reply to message #787708] Tue, 31 January 2012 22:32 Go to previous messageGo to next message
Lars Vogel is currently offline Lars VogelFriend
Messages: 1098
Registered: July 2009
Senior Member

Sorry I had a typo. I was referring to the following section: http://www.vogella.de/articles/Eclipse4RCP/article.html#importantmodelelement_examples

At the end of this chapter I show how you can add a model element dynamically. In my example a Part.

In your example your are using AbstractHandler, I believe you should try using the @Execute annotation.
Re: E4 Commands and Handlers [message #787748 is a reply to message #787716] Tue, 31 January 2012 23:40 Go to previous messageGo to next message
Lars Vogel is currently offline Lars VogelFriend
Messages: 1098
Registered: July 2009
Senior Member

The following works for me:

Command command = commandService.getCommand("testing.throwingerror.aboutCommand");

// Returns true
System.out.println(command.isDefined());

// Activate Handler
handerService.activateHandler("testing.throwingerror.aboutCommand",new AboutHandler());

ParameterizedCommand cmd = commandService.createCommand("testing.throwingerror.aboutCommand", null);
command = commandService.getCommand("testing.throwingerror.aboutCommand");

// Return null and false, not sure why
System.out.println(command.getHandler());
System.out.println(command.isEnabled());

// Execution works file
System.out.println(handerService.canExecute(cmd));
handerService.executeHandler(cmd);


The only think I don't know is why isEnabled() and getHandler() return false and null.

Maybe Paul can clarify.
Re: E4 Commands and Handlers [message #788242 is a reply to message #787748] Wed, 01 February 2012 14:50 Go to previous messageGo to next message
Lars Vogel is currently offline Lars VogelFriend
Messages: 1098
Registered: July 2009
Senior Member

I just asked Paul in IRC.

command.getHandler() and command.isEnabled() are for Eclipse 3.x based API and are not used in Eclipse 4. Hence they will always return null / false in Eclipse 4 applications.
Re: E4 Commands and Handlers [message #788243 is a reply to message #788242] Wed, 01 February 2012 14:52 Go to previous messageGo to next message
Josh Davis is currently offline Josh DavisFriend
Messages: 20
Registered: August 2011
Junior Member
Thank you Lars for getting the answer for me. I appreciate it.
Re: E4 Commands and Handlers [message #788933 is a reply to message #788243] Thu, 02 February 2012 11:52 Go to previous messageGo to next message
Lars Vogel is currently offline Lars VogelFriend
Messages: 1098
Registered: July 2009
Senior Member

@Josh: No problem, I also added the example here: http://www.vogella.de/articles/Eclipse4Services/article.html#commandservice
Re: E4 Commands and Handlers [message #1727376 is a reply to message #788933] Tue, 22 March 2016 14:15 Go to previous message
Alexander Kerner is currently offline Alexander KernerFriend
Messages: 25
Registered: January 2015
Junior Member
Hi,

I tried the example

(http://www.vogella.de/articles/Eclipse4Services/article.html#commandservice)

but the problem is that
handlerService.canExecute(cmd)
always returns false.

Can anyone tell me what I am missing?
Previous Topic:Debugging Eclipse Welcome Page
Next Topic:Execute commands on a RCP instance by using command lines
Goto Forum:
  


Current Time: Thu Apr 25 00:12:49 GMT 2024

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

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

Back to the top