Skip to main content



      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
Eclipse UserFriend
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
Eclipse UserFriend
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
Eclipse UserFriend
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
Eclipse UserFriend
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
Eclipse UserFriend
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] by 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
Eclipse UserFriend
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
Eclipse UserFriend
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 messageGo to next message
Eclipse UserFriend
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 05:46 Go to previous message
Eclipse UserFriend

@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 05:48] by 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: Wed Jul 23 17:15:22 EDT 2025

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

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

Back to the top