A very common thing for RCP applications is to present a Login-Dialog to the user. The proposed way of doing this in e4 applications is by using a Lifecycle-Hook which looks something like this in your e4+SWT-RCP:
public class StartupHook { @PostContextCreate public void startUp() { // show your login dialog if( ! <check-if-abort> ) { System.exit(0); } } }
and yes System.exit(0)
is the only way in e4+SWT – the boostrap code does not check a return value. We had discovered this missing API already in e(fx)clipse 1.0.0 and allowed you to return a boolean
value to indicate that the boot process should stop and the application to shutdown gracefully so you wrote something like this:
public class StartupHook { @PostContextCreate public Boolean startUp() { // show your login dialog if( ! <check-if-abort> ) { return Boolean.FALSE; } return Boolean.TRUE; } }
API to restart your e4 app on startup
So while the initial API solved the most common usecase it is falling short for more advanced stuff like automatically updating your application in the StartupHook and restarting the OSGi-Framework afterwards (yes I know technically this is not needed in OSGi but for the sake of laziness many apps do it like this!).
e(fx)clipse 1.1.0 addresses this problem by introducing an enumeration org.eclipse.fx.ui.services.restart.LifecycleRV
with the following options:
- CONTINUE : Continue with the boot process
- SHUTDOWN : Shutdown the application
- RESTART : Restart the application
- RESTART_CLEAR_STATE : Restart the application with a cleared persisted state
public class StartupHook { @PostContextCreate public LifecycleRV startUp() { // check update if( <check-if-updated> ) { return LifecycleRV.RESTART; } // show your login dialog if( ! <check-if-abort> ) { return LifecycleRV.SHUTDOWN; } return LifecycleRV.CONTINUE; } }
Please note that the feature of restarting is also available at later times using org.eclipse.fx.ui.services.restart.RestartService
.
Both APIs are documented in our wiki-recipes who are a great resource to learn about all the advanced features of e(fx)clipse runtime.
Pingback: e(fx)clipse 1.1.0 released | Tomsondev Blog
Pingback: A simple auto-updater for Eclipse RCP applications – Modular Mind