Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Handler does not execute
Handler does not execute [message #957978] Thu, 25 October 2012 16:52 Go to next message
Christian Eugster is currently offline Christian Eugster
Messages: 134
Registered: July 2009
Location: St. Gallen Switzerland
Senior Member
Hi,

In a eclipse4 app I have:

In the model:
a command add.level.command,
a command edit.level.command,
a part with toolbar with a Direct Toolbar Item that references a class AddLevelHandler and a handler edit.level.handler that references edit.level.command.

An implementation of:
the mentioned AddLevelHandler
a EditLevelHandler that is references by edit.level.handler.

Running the app, both toolbar items are shown but clicking on them does nothing. The objects AddLevelHandler and EditLevelHandler are instantiated on startup. The execution method is annotated with @Execute. There are no exceptions thrown.

As an example the code for AddLevelHandler. EditLevelHandler just has some minor differences.

 
package ch.eugster.herakles.tectonics.handlers;

import javax.inject.Inject;

import org.eclipse.e4.core.di.annotations.Execute;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swt.widgets.Shell;

import ch.eugster.herakles.persistence.model.Level;
import ch.eugster.herakles.persistence.service.LevelService;
import ch.eugster.herakles.tectonics.dialogs.LevelInputDialog;
import ch.eugster.image.service.ImageConverter;

public class AddLevelHandler 
{
	@Inject
	private Shell shell;

	@Inject
	private LevelService levelService;
	
	@Inject
	private ImageConverter imageConverter;
	
	public AddLevelHandler()
	{
		System.out.println();
	}
	
	@Execute
	public void execute() 
	{
		Level level = Level.newInstance();
		LevelInputDialog dialog = new LevelInputDialog(shell, level, imageConverter);
		if (dialog.open() == IDialogConstants.OK_ID)
		{
			levelService.persist(level);
		}
	}
		
}


Can anyone tell me what I am missing? I did not find any hints googling. Thank you!


[Updated on: Thu, 25 October 2012 17:00]

Report message to a moderator

Re: Handler does not execute [message #958940 is a reply to message #957978] Fri, 26 October 2012 10:34 Go to previous messageGo to next message
Brian de Alwis is currently offline Brian de Alwis
Messages: 192
Registered: January 2012
Senior Member

Check your logs to see if there are any errors. Enable the tracing in org.eclipse.e4.core.di. See the FAQ:

http://wiki.eclipse.org/Eclipse4/RCP/FAQ#Why_is_my_handler.27s_.40Execute_not_being_triggered.3F


Eclipse Platform committer. Ask me about Eclipse support, training, and consulting.
Re: Handler does not execute [message #958982 is a reply to message #958940] Fri, 26 October 2012 11:06 Go to previous messageGo to next message
Christian Eugster is currently offline Christian Eugster
Messages: 134
Registered: July 2009
Location: St. Gallen Switzerland
Senior Member
I added the trace. There is nothing logged except some statements from aries concerning a service (LevelService) that is injected in the handler (so it seems to inject properly):

org.apache.aries.blueprint[org.apache.aries.blueprint.container.ServiceRecipe] : Retrieving service for bundle org.eclipse.e4.ui.workbench_0.10.3.v20120822-140642 [30] and service registration {ch.eugster.herakles.persistence.service.LevelService}={osgi.service.blueprint.compname=levelBean, service.id=112}
org.apache.aries.transaction.blueprint[org.apache.aries.transaction.TxComponentMetaDataHelperImpl] : Getting the txAttribute for the component {0} and method {1}
org.apache.aries.transaction.blueprint[org.apache.aries.transaction.TxComponentMetaDataHelperImpl] : Return the txAttribute {0} for the component and method
org.apache.aries.transaction.blueprint[org.apache.aries.transaction.TxInterceptorImpl] : Method: public java.lang.String java.lang.Object.toString(), has transaction strategy: REQUIRED
org.apache.aries.blueprint[org.apache.aries.blueprint.container.ServiceRecipe] : Method entry: getService, args ch.eugster.herakles.persistence.jpa.service.LevelServiceComponent@2ff7ac92


When I add @Inject to the execute method, the execute method is called. But as said by Tom Schindl in an other thread (http://www.eclipse.org/forums/index.php/mv/msg/385788/924928/#msg_924928), the @Inject annotation must not be added. Have you another suggestion?

[Updated on: Fri, 26 October 2012 11:11]

Report message to a moderator

Re: Handler does not execute [message #959023 is a reply to message #958982] Fri, 26 October 2012 11:45 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk Fauth
Messages: 1354
Registered: July 2012
Senior Member
There is one thing you might want to try. Maybe it would be better to get the Shell injected to the execute method instead of being injected as field.
Re: Handler does not execute [message #959060 is a reply to message #959023] Fri, 26 October 2012 12:27 Go to previous messageGo to next message
Christian Eugster is currently offline Christian Eugster
Messages: 134
Registered: July 2009
Location: St. Gallen Switzerland
Senior Member
Nothing changed. It must be me, that has not configured right, but I cannot figure out, what it could be.

Must there another condition be fullfilled exept of:
injected services must be present in the system
execute method must be annotated with @Execute
the menu must reference the handler in question (if DirectToolItem) or
the handler must reference the same command as the menu does (if HandledToolItem).

Is there anything missing?
Re: Handler does not execute [message #959083 is a reply to message #959060] Fri, 26 October 2012 12:49 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk Fauth
Messages: 1354
Registered: July 2012
Senior Member
Have you declared your handler also in the application model in the Handlers section?
Re: Handler does not execute (SOLVED) [message #959122 is a reply to message #959083] Fri, 26 October 2012 13:21 Go to previous messageGo to next message
Christian Eugster is currently offline Christian Eugster
Messages: 134
Registered: July 2009
Location: St. Gallen Switzerland
Senior Member
As I understand, this is not necessary for DirectToolItem's. But: yes I had declared it for all handlers and removed some putting them to the classURI of DirectToolItems. The handlers for HandledToolItem's are declared in the model.

I got it: Header Import-Package was missing the package org.eclipse.e4.core.di.annotations.

This raises another question: Why does eclipse not complain the missing package? Even forcing "add dependencies" in the automated management of dependecies section of the manifest editor did resolve it (there the bundle org.eclipse.e4.core.di is included).



[Updated on: Fri, 26 October 2012 13:33]

Report message to a moderator

Re: Handler does not execute [message #959133 is a reply to message #959122] Fri, 26 October 2012 13:30 Go to previous message
Dirk Fauth is currently offline Dirk Fauth
Messages: 1354
Registered: July 2012
Senior Member
Seems you are right on that. No need for a handler declaration for DirectToolItems. Have you ensured that the ClassURI points to the right class?

And if this is correct, maybe you are missing an Addon. I'm not yet very familiar with the Eclipse 4 Addons, but maybe you need to add the CommandServiceAddon to the section of Addons. In my application which I created by wizard, I also see the CommandProcessingAddon.
Previous Topic:Lifecycle events on a window
Next Topic:Howto dispose an MWindow?
Goto Forum:
  


Current Time: Fri Oct 31 20:15:25 GMT 2014

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

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