LifeCycleHandler to hook into the startup process of an e4-app

In the past on RCP 3.x we hooked into the Application*-Classes to popup things like login screens just before the main application came up. With e4 we dont have the Application-Classes anymore, instead there is a standard E4Application-Class wich is responsible to create the Workbench Model and startup the GUI. Using LifeCycleHandlers you we are able to hook into the startup process of an e4 application. You can register a handler from within your plugin.xml by adding a new property named “lifeCycleURI” like this:

<pre><?xml version="1.0" encoding="UTF-8"?>
<plugin>

<extension
id="product"
point="org.eclipse.core.runtime.products">
<product
name="de.hama.ui"
application="org.eclipse.e4.ui.workbench.swt.E4Application">
<property
name="appName"
value="de.hama.ui">
</property>
<property
name="applicationXMI"
value="de.hama.ui/Application.e4xmi">
</property>
<property
name="applicationCSS"
value="platform:/plugin/de.hama.ui/css/default.css">
</property>
<property
name="lifeCycleURI"
value="platform:/plugin/de.hama.ui/de.hama.ui.handlers.StartupLifeCycleHandler">
</property>
</product>
</extension>

</plugin>

So now we have the definition of a LifeCycleHandler and during runtime the class E4Application will look into the plugin “de.hama.ui” to find a classed named “StartupLifeCycleHandler” in the package “de.hama.ui.handlers”. Easy stuff so far. Like every handler in e4 a LifeCycleHandler is just a POJO, the difference now is that we do not use the @Execute or @CanExecute-Annotations to define wich method inside the handler has to be executed instead there is a new Eclipse-specific Annotation @PostContextCreate wich we can use to mark the method to be executed.After this method is executed, the e4 main app will show up.

Here is an example of a LifeCycleHandler to open a Login-Dialog right before the startup of the main application:

public class StartupLifeCycleHandler {

@Inject
LoginDaoJdbc loginDao;

@PostContextCreate
public void startup(IEclipseContext context) {

int i = loginDialog.open();
if (i == Window.CANCEL)
System.exit(0);

context.set("lfsDS", loginDao.getInitialDataSource());
context.set("login", loginDialog.getLogin());

}

Hope that helps…. have fun!

About these ads

One Response to LifeCycleHandler to hook into the startup process of an e4-app

  1. Christoph sagt:

    Thank you very much for this helpful blog entry in reply of my question.

    I have still an unresolved problem. In the StartupLifeCycleHandler i need access to the splash shell otherwise my dialog will disappear behind the splash image if i use the current/active shell.

Kommentar verfassen

Trage deine Daten unten ein oder klicke ein Icon um dich einzuloggen:

WordPress.com-Logo

Du kommentierst mit Deinem WordPress.com-Konto. Abmelden / Ändern )

Twitter-Bild

Du kommentierst mit Deinem Twitter-Konto. Abmelden / Ändern )

Facebook-Foto

Du kommentierst mit Deinem Facebook-Konto. Abmelden / Ändern )

Google+ photo

Du kommentierst mit Deinem Google+-Konto. Abmelden / Ändern )

Verbinde mit %s

Folgen

Erhalte jeden neuen Beitrag in deinen Posteingang.

%d Bloggern gefällt das: