Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Running some code after initialization
Running some code after initialization [message #894881] Tue, 10 July 2012 21:58 Go to next message
Tom Dev is currently offline Tom DevFriend
Messages: 4
Registered: July 2012
Junior Member
Hi,

I would like to run some code once the e4 application is initialized and the workbench started. In Eclipse 3.x, I would put this in the method "initialize" of the class ApplicationWorkbenchAdvisor.

What is the best way to implement this in the e4 framework?

Thank you,

Tom
Re: Running some code after initialization [message #894893 is a reply to message #894881] Tue, 10 July 2012 23:51 Go to previous messageGo to next message
Joseph Carroll is currently offline Joseph CarrollFriend
Messages: 174
Registered: May 2012
Location: Milwaukee, WI
Senior Member

What are you trying to accomplish with this "code"?

More than likely you will need a lifecycle handler.
Re: Running some code after initialization [message #894930 is a reply to message #894881] Wed, 11 July 2012 07:05 Go to previous messageGo to next message
Christoph Keimel is currently offline Christoph KeimelFriend
Messages: 482
Registered: December 2010
Location: Germany
Senior Member
See this tutorial from Lars on how to register a lifecycle class:
http://www.vogella.com/articles/Eclipse4RCP/article.html#lifecycle
Re: Running some code after initialization [message #894931 is a reply to message #894930] Wed, 11 July 2012 07:30 Go to previous messageGo to next message
Tom Dev is currently offline Tom DevFriend
Messages: 4
Registered: July 2012
Junior Member
Thank you for your replies.

@Joseph
The code I would like to run would initialize listeners and start new threads. For instance, if a file has been in the command line arguments, this file would be opened and run.

@Christoph
I already did some tests with @PostContextCreate and @ProcessAdditions. The problem is that when these methods are called, the workbench is not ready yet.

My guess is that I would need to register to IEventBroker for some events such that when the main window has been opened. There is a few things on the life cycle of a part in the tutorials from Vogella on e4 but nothing about the lifecycle of the shell, the workbench or the main window.

Tom
Re: Running some code after initialization [message #894932 is a reply to message #894931] Wed, 11 July 2012 07:36 Go to previous messageGo to next message
Christoph Keimel is currently offline Christoph KeimelFriend
Messages: 482
Registered: December 2010
Location: Germany
Senior Member
There is a discussion goint on about this:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=376821

As a workaround you could do something like:
@PostContextCreate
void postContextCreate(final IEventBroker eventBroker) {
	eventBroker.subscribe(UIEvents.UILifeCycle.ACTIVATE, new EventHandler() {
		@Override
		public void handleEvent(Event event) {
			...
			eventBroker.unsubscribe(this);
		}
	});
}

[Updated on: Wed, 11 July 2012 07:37]

Report message to a moderator

Re: Running some code after initialization [message #894950 is a reply to message #894932] Wed, 11 July 2012 08:42 Go to previous messageGo to next message
Tom Dev is currently offline Tom DevFriend
Messages: 4
Registered: July 2012
Junior Member
Thank you. Reading the discussion was informative: I understand now that there is no easy way to define that an application is started.

I have tried to subscribe to the UIEvents.UILifeCycle.ACTIVATE event using the code you suggested. Somehow, the method postContextCreate is called but the event is never triggered. Any idea ?

Tom
Re: Running some code after initialization [message #894956 is a reply to message #894950] Wed, 11 July 2012 08:49 Go to previous messageGo to next message
Christoph Keimel is currently offline Christoph KeimelFriend
Messages: 482
Registered: December 2010
Location: Germany
Senior Member
Hi Tom,

when I first started out looking for a way to hide my custom splash at the right moment, I used this to output all events:
	@PostContextCreate
	public void postContextCreate(final IEventBroker eventBroker) {
		logger.info("AppLifeCycle: @PostContextCreate");
		eventBroker.subscribe(UIEvents.ALL_SUB_TOPICS, new EventHandler() {
			@Override
			public void handleEvent(Event event) {
				logger.info("UIEvent: {}", event);
			}
		});
	}

Maybe this will help you debug your case.

BTW: I am using the org.eclipse.e4*_0.10.1.*.jar plugins and I am not using the compat-layer for 3.x
Re: Running some code after initialization [message #894977 is a reply to message #894956] Wed, 11 July 2012 10:21 Go to previous messageGo to next message
Tom Dev is currently offline Tom DevFriend
Messages: 4
Registered: July 2012
Junior Member
Hi Christoph,

thank you for the tip. I was doing something similar but registering my event logger only in @ProcessAdditions: I was missing most of the UI initialization events.

My next step is to use the compatibility layer.

Thank you very much for your help,

Tom
Re: Running some code after initialization [message #1061829 is a reply to message #894956] Tue, 04 June 2013 09:46 Go to previous message
Ozgur Cagdas is currently offline Ozgur CagdasFriend
Messages: 32
Registered: May 2013
Member

@Christoph
It might be obvious for many but my Eclipse's auto completion for missing classes did initially mislead me, so below list of imports is required to use the suggested lifecyclehandler. Might be of help for somebody else as well.

import org.eclipse.e4.core.services.events.IEventBroker;
import org.eclipse.e4.ui.workbench.UIEvents;
import org.eclipse.e4.ui.workbench.lifecycle.PostContextCreate;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Shell;
import org.osgi.service.event.Event;
import org.osgi.service.event.EventHandler;


Thanks very much for the useful suggestion by the way.

Regards,

O.

[Updated on: Tue, 04 June 2013 09:48]

Report message to a moderator

Previous Topic:handlerService.executeHandler loops indefinitely
Next Topic:Integrating JDT and org.eclipse.ant in Eclipse IDE for C/C++ Developers
Goto Forum:
  


Current Time: Thu Mar 28 16:35:23 GMT 2024

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

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

Back to the top