Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » handlerService.executeHandler loops indefinitely
handlerService.executeHandler loops indefinitely [message #1061409] Fri, 31 May 2013 13:54 Go to next message
Ozgur Cagdas is currently offline Ozgur CagdasFriend
Messages: 32
Registered: May 2013
Member
Hi,

I am trying to execute a command within the 'init' method of a Part which is annotated as @PostConstruct but somehow the execution line triggers a loop and the console is flooded with the 'true' messages printed by the below println line and the application doesn't go any further than that point. If I comment out the 'handlerService.executeHandler' line, 'true' is printed only once and execution continues as normal.

I have this command tied to a popup menu item as well and when I activate it from the menu, it also runs without any issues. Seems like I'm making a fundamental mistake here but can't figure out what it is.

The init method of the Part is;
@PostConstruct
	public void init(Composite parent, final IEclipseContext context, EMenuService service) 


and this is the bit which I'm having the issue with;
ECommandService commandService = context.get(ECommandService.class);
EHandlerService handlerService = context.get(EHandlerService.class);

ParameterizedCommand myCommand = commandService.createCommand("com.mycomp.first_command.id", null);
		
System.out.println(handlerService.canExecute(myCommand));
		
Object result = handlerService.executeHandler(myCommand);


I also tried injecting the ECommandService and EHandlerService parameters into the 'init' method but it didn't make any difference at all.

Thanks in advance,

O.

[Updated on: Fri, 31 May 2013 14:03]

Report message to a moderator

Re: handlerService.executeHandler loops indefinitely [message #1061590 is a reply to message #1061409] Mon, 03 June 2013 07:45 Go to previous messageGo to next message
Eclipse UserFriend
Where does the code in the second bit reside? A handler, method? A @CanEecute method or something similar?
Re: handlerService.executeHandler loops indefinitely [message #1061628 is a reply to message #1061590] Mon, 03 June 2013 11:09 Go to previous messageGo to next message
Ozgur Cagdas is currently offline Ozgur CagdasFriend
Messages: 32
Registered: May 2013
Member
Sorry for not being clear, the second bit is also in the 'init' method of the Part. I think it looked like a good idea to me showing the function signature and body separately in the post but obviously it is not Smile

The @Execute method of this command's handler gets the same Part injected as a parameter. So, could executing the command before the @PostConstruct exits be what's triggering the @PostConstruct to be called recursively for this Part?

The alternative I can think of is creating another class with a @PostConstruct annotated method which gets this Part as a parameter and executing the command there. Is that kosher?

What could be the recommended ways to centralise such an initialisation effort for multiple Parts (in my example, reading a config file and pushing data to multiple Parts) other than a class with a @PostConstruct method which receives all those Parts as injected parameters?

Me being very new to e4 and DI makes things difficult to explain for me. Sorry and thanks again,

O.
Re: handlerService.executeHandler loops indefinitely [message #1061664 is a reply to message #1061628] Mon, 03 June 2013 12:28 Go to previous messageGo to next message
Andrzej Szczepanski is currently offline Andrzej SzczepanskiFriend
Messages: 16
Registered: May 2013
Junior Member
Ozgur Cagdas wrote on Mon, 03 June 2013 13:09

The @Execute method of this command's handler gets the same Part injected as a parameter. So, could executing the command before the @PostConstruct exits be what's triggering the @PostConstruct to be called recursively for this Part?

I guess so... your approach is a little confusing for me.

How about injecting EPartService or EModelService and accessing the part instances you care about through them?
Re: handlerService.executeHandler loops indefinitely [message #1061828 is a reply to message #1061664] Tue, 04 June 2013 09:43 Go to previous message
Ozgur Cagdas is currently offline Ozgur CagdasFriend
Messages: 32
Registered: May 2013
Member
Well, the problem is mostly because I'm not quite clear how to use OSGi services and lifecycle handler. Thanks very much for the direction, the services you mentioned seem helpful.

I've followed the below link to handle post init of Parts, so I'm doing things in the event handler I defined in the @PostContextCreate and this makes sure that all the Parts are created and their @PostConstruct methods are executed.

http://www.eclipse.org/forums/index.php/m/894881/

Regards,

O.
Previous Topic:Injecting IServiceConstants.ACTIVE_SELECTION to implement a selection listener
Next Topic:Running some code after initialization
Goto Forum:
  


Current Time: Thu Mar 28 11:29:03 GMT 2024

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

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

Back to the top