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 17:58 Go to next message
Tom Dev is currently offline Tom Dev
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 19:51 Go to previous messageGo to next message
Joseph Carroll is currently offline Joseph Carroll
Messages: 156
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 03:05 Go to previous messageGo to next message
Christoph Keimel is currently offline Christoph Keimel
Messages: 277
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 03:30 Go to previous messageGo to next message
Tom Dev is currently offline Tom Dev
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 03:36 Go to previous messageGo to next message
Christoph Keimel is currently offline Christoph Keimel
Messages: 277
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 03:37]

Report message to a moderator

Re: Running some code after initialization [message #894950 is a reply to message #894932] Wed, 11 July 2012 04:42 Go to previous messageGo to next message
Tom Dev is currently offline Tom Dev
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 04:49 Go to previous messageGo to next message
Christoph Keimel is currently offline Christoph Keimel
Messages: 277
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 06:21 Go to previous message
Tom Dev is currently offline Tom Dev
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
Previous Topic:Alternate row color
Next Topic:Migration from eclipse 3.x
Goto Forum:
  


Current Time: Mon May 20 08:31:20 EDT 2013

Powered by FUDForum. Page generated in 0.01886 seconds