Restarting an e4 application with the intial workbench.e4xmi


e4 applications by default remember the state when getting shutdown and restore that state on the next restart. This is the behavior most people expect from an application but there are situations people would like to reset the application into its original state or maybe the developer wants that e.g. after having installed/uninstalled certain new bundles.

Unfortunately the workbench currently does not provide a way restart and clear the current state. So I’ve implemented a small library you can make use of in your e4 applications.

There are 2 parts:

  1. a service called RestartService which has a method restart(boolean)
  2. a Lifecycle-Addon you can reuse or copy the code from min to yours

Useage is very simple e.g. in your handler:

import org.eclipse.e4.core.di.annotations.Execute;

import at.bestsolution.e4.extensions.core.services.RestartService;

public class RestartHandler {
  @Execute
  public void restart(RestartService service) {
    service.restart(true);
  }
}

and to enable the addon you make your plugin.xml look like this:

<?xml version="1.0" encoding="UTF-8"?>
<plugin>
  <extension
    id="product"
    point="org.eclipse.core.runtime.products">
    <product
      name="SampleProject"
      application="org.eclipse.e4.ui.workbench.swt.E4Application">
      <property
        name="applicationCSS"
        value="platform:/plugin/SampleProject/css/default.css">
      </property>
      <property
        name="lifeCycleURI"
        value="bundleclass://at.bestsolution.e4.extensions.lifecycle/at.bestsolution.e4.extensions.lifecycle.ExtensibleLifecycle">
      </property>
      <property
        name="appName"
        value="SampleProject">
      </property>
    </product>
  </extension>
</plugin>

If you want to make use of it you can find the p2-repo at http://downloads.foss.bestsolution.at/e4-extensions/nightly/ or if you prefer the source it is hosted at the github account of BestSolution.at at https://github.com/BestSolution-at/e4-extensions.

Advertisements
This entry was posted in e4. Bookmark the permalink.

7 Responses to Restarting an e4 application with the intial workbench.e4xmi

  1. Dieter Rehbein says:

    Here is another solution for the same problem (clear persisted state, if a new application version is installed):

    I’ve implemented a subclass of E4Application, which overrides the method

    public Object start(final IApplicationContext applicationContext) throws Exception;
    if (isVersionChanged()) {
    System.setProperty(“clearPersistedState”, “true”);
    }
    return super.start(applicationContext);
    }

    The method isVersionChanged() returns true, if a new version of the application is detected (it is not part of E4Application, has to be implemented by yourself).

    Then I’ve added an extension to the plugin.xml of the application for the extension point org.eclipse.core.runtime.applications, which adds this subclass of E4Application to the list of available applications.

    In the application product definition (tab Overview) select your application-class.

    => Now the persisted state is cleared everytime a new version of the application installed

    • Tom Schindl says:

      Right that works but E4Application is not public API bottom line is that the core framework should provide this feature built-in

  2. Pingback: Add p2 update functionality to an Eclipse 4 application - Eclipse RCP Cookbook - codecentric Blog

  3. Pingback: Add p2 update functionality to an e(fx)clipse application – Eclipse RCP Cookbook - codecentric Blog

  4. Tried to use “at.bestsolution.e4.extensions.core.services.RestartService” from p2-repo at http://downloads.foss.bestsolution.at/e4-extensions/nightly/ for e4 RCP development with Eclipse Neon.1a Release (4.6.1). Plugin not visible in any view within Eclipse for RCP Developers? May be because it is not signed? (I have no other idea after several tries.)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s