Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Restart Application
Restart Application [message #1014988] Wed, 27 February 2013 07:05 Go to next message
Bastian Wagenfeld is currently offline Bastian WagenfeldFriend
Messages: 183
Registered: January 2013
Senior Member
Hi,

how can I restart an e4 RCP? Is there something like IWorkbench.restart() like in an Eclipse 3.x RCP?

Thanks Smile
Bastian
Re: Restart Application [message #1015019 is a reply to message #1014988] Wed, 27 February 2013 08:28 Go to previous messageGo to next message
Christoph Keimel is currently offline Christoph KeimelFriend
Messages: 482
Registered: December 2010
Location: Germany
Senior Member
Hi Bastian

AFAIK this feature is not available (yet).
Have look at this Thread for a work around:
http://stackoverflow.com/questions/12869859/howto-restart-an-e4-rcp-application

Greetings
christoph
Re: Restart Application [message #1015053 is a reply to message #1015019] Wed, 27 February 2013 10:07 Go to previous messageGo to next message
Bastian Wagenfeld is currently offline Bastian WagenfeldFriend
Messages: 183
Registered: January 2013
Senior Member
Hi Christoph,

thank you, that seems to do the trick Smile

Best regards
Bastian
Re: Restart Application [message #1048357 is a reply to message #1015053] Wed, 24 April 2013 10:51 Go to previous messageGo to next message
Marc Meier is currently offline Marc MeierFriend
Messages: 9
Registered: April 2013
Junior Member
Hi Christoph,

I get the following error message when I try to use your code.


!ENTRY org.eclipse.e4.ui.workbench 4 0 2013-04-24 12:41:13.872
!MESSAGE Internal Error
!STACK 0
org.eclipse.e4.core.di.InjectionException: java.lang.NullPointerException
	at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:63)
	at org.eclipse.e4.core.internal.di.InjectorImpl.invokeUsingClass(InjectorImpl.java:231)
	at org.eclipse.e4.core.internal.di.InjectorImpl.invoke(InjectorImpl.java:212)
	at org.eclipse.e4.core.contexts.ContextInjectionFactory.invoke(ContextInjectionFactory.java:131)
	at org.eclipse.e4.core.commands.internal.HandlerServiceImpl.executeHandler(HandlerServiceImpl.java:171)
	at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.executeItem(HandledContributionItem.java:831)
	at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.handleWidgetSelection(HandledContributionItem.java:724)
	at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.access$7(HandledContributionItem.java:708)
	at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem$4.handleEvent(HandledContributionItem.java:647)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4169)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3758)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:1053)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:942)
	at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:86)
	at org.eclipse.e4.ui.internal.workbench.swt.E4Application.start(E4Application.java:150)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:353)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:180)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:629)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:584)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1438)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1414)
Caused by: java.lang.NullPointerException
	at net.restartets.handlers.QuitHandler.execute(QuitHandler.java:31)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:56)
	... 30 more



I copied your class (MyE4Application) in my project and call the method setRestart() in the following Handler :

package net.restartets.handlers;


import net.restartets.MyE4Application;

import org.eclipse.e4.core.di.annotations.Execute;
import org.eclipse.e4.ui.workbench.IWorkbench;

public class QuitHandler {

	@Execute
	public void execute(IWorkbench workbench) {
	    MyE4Application.getInstance().setRestart();
	    workbench.close();
	}

}



Thanks for your help
Re: Restart Application [message #1048360 is a reply to message #1048357] Wed, 24 April 2013 11:00 Go to previous messageGo to next message
Bastian Wagenfeld is currently offline Bastian WagenfeldFriend
Messages: 183
Registered: January 2013
Senior Member
Hi Marc,

that's because the Workbench is null. But since your class MyE4Application implements the method stop(), that should stop the application, you can do the following:
@Execute
	public void execute(IWorkbench workbench) {
	    MyE4Application.getInstance().setRestart();
	    MyE4Application.getInstance().stop();
	}


Best regards
Bastian
Re: Restart Application [message #1048392 is a reply to message #1048360] Wed, 24 April 2013 12:05 Go to previous messageGo to next message
Marc Meier is currently offline Marc MeierFriend
Messages: 9
Registered: April 2013
Junior Member
Hi Bastian,

i get the same error message with the stop() method. Are you sure that the workbench is null? I can stop the application with "workbench.close()" ...

MyE4Application
package net.restartets;

import org.eclipse.e4.ui.internal.workbench.swt.E4Application;
import org.eclipse.equinox.app.IApplication;
import org.eclipse.equinox.app.IApplicationContext;

public abstract class MyE4Application implements IApplication {

    private static MyE4Application instance;

    public static MyE4Application getInstance() {
        return instance;
    }

    private Integer exitRet = IApplication.EXIT_OK;
    
    private E4Application e4app;

    public void setRestart() {
        exitRet = IApplication.EXIT_RESTART;
    }

    @Override
    public Object start(IApplicationContext context) throws Exception {
        instance = this;
        e4app = new E4Application();
        e4app.start(context);
        return exitRet;
    }

    @Override
    public void stop() {
        e4app.stop();
    }
}



package net.restartets.handlers;


import net.restartets.MyE4Application;

import org.eclipse.e4.core.di.annotations.Execute;
import org.eclipse.e4.ui.workbench.IWorkbench;

public class QuitHandler {

	@Execute
	public void execute(IWorkbench workbench) {
		
	    MyE4Application.getInstance().setRestart();
            MyE4Application.getInstance().stop();
	   // workbench.close();
	}

}


Thanks your your help

Marc
Re: Restart Application [message #1048411 is a reply to message #1048392] Wed, 24 April 2013 12:33 Go to previous messageGo to next message
Bastian Wagenfeld is currently offline Bastian WagenfeldFriend
Messages: 183
Registered: January 2013
Senior Member
Hi Marc,

I thought it would be, but the Workbench won't be null, because otherwise it wouldn't be injected, I think. Restarting the application with the handler you posted works for me. Also, I don't need a Workbench to restart it.
Did you set your application in your plugin.xml as an extension?

Best regards
Bastian
Re: Restart Application [message #1048423 is a reply to message #1048411] Wed, 24 April 2013 12:54 Go to previous messageGo to next message
Marc Meier is currently offline Marc MeierFriend
Messages: 9
Registered: April 2013
Junior Member
Sry I dont know what you mean exactly..

here my plugin.xml

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

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

</plugin>

[Updated on: Wed, 24 April 2013 12:55]

Report message to a moderator

Re: Restart Application [message #1048433 is a reply to message #1048423] Wed, 24 April 2013 13:07 Go to previous messageGo to next message
Bastian Wagenfeld is currently offline Bastian WagenfeldFriend
Messages: 183
Registered: January 2013
Senior Member
You have to register it there with an extension like:

<extension
         id="MyApplication"
         point="org.eclipse.core.runtime.applications">
      <application>
         <run
               class="net.restartets.MyE4Application">
         </run>
      </application>
   </extension>


Add this and the application will use your own class, so you won't get a NullPointerException anymore.

Best regards
Bastian
Re: Restart Application [message #1048936 is a reply to message #1048433] Thu, 25 April 2013 06:12 Go to previous messageGo to next message
Marc Meier is currently offline Marc MeierFriend
Messages: 9
Registered: April 2013
Junior Member
Hi Bastian,

i have added it to my plugin.xml


<?xml version="1.0" encoding="UTF-8"?>
<plugin>
   <extension
         id="MyApplication"
         point="org.eclipse.core.runtime.applications">
      <application>
         <run class="net.restartets.MyE4Application">
         </run>
      </application>
   </extension>
   
   <extension
         id="product"
         point="org.eclipse.core.runtime.products">
      <product
            name="net.restartets"
            application="org.eclipse.e4.ui.workbench.swt.E4Application">
         <property
               name="appName"
               value="net.restartets">
         </property>
         <property
               name="applicationXMI"
               value="net.restartets/Application.e4xmi">
         </property>
         <property
               name="applicationCSS"
               value="platform:/plugin/net.restartets/css/default.css">
         </property>
      </product>
   </extension>
</plugin>



but it still does not work :/

Re: Restart Application [message #1048946 is a reply to message #1048936] Thu, 25 April 2013 06:31 Go to previous messageGo to next message
Bastian Wagenfeld is currently offline Bastian WagenfeldFriend
Messages: 183
Registered: January 2013
Senior Member
Hi Marc,

how did you register it to your plugin.xml? Did you copy it to your plugin.xml or where you able to add through the Extensions-tab in the Manifest-editor? Maybe it is just a typo?!
Otherwise I don't know what's causing the NullPointerException. Now, MyE4Application.getInstance() returns null?

Bastian
Re: Restart Application [message #1048988 is a reply to message #1048946] Thu, 25 April 2013 07:52 Go to previous messageGo to next message
Christoph Keimel is currently offline Christoph KeimelFriend
Messages: 482
Registered: December 2010
Location: Germany
Senior Member
Hi Marc,

I think this part of your plugin.xml
<extension
         id="product"
         point="org.eclipse.core.runtime.products">
      <product
            name="net.restartets"
            application="org.eclipse.e4.ui.workbench.swt.E4Application">

should be something like
<extension
         id="product"
         point="org.eclipse.core.runtime.products">
      <product
            name="net.restartets"
            application="net.restartets.MyE4Application">

Put a breakpoint in MyE4Application.start(...) an see if that realy gets called!

Greetings
Christoph
Re: Restart Application [message #1049051 is a reply to message #1048988] Thu, 25 April 2013 09:34 Go to previous messageGo to next message
Marc Meier is currently offline Marc MeierFriend
Messages: 9
Registered: April 2013
Junior Member
Quote:

how did you register it to your plugin.xml? Did you copy it to your plugin.xml or where you able to add through the Extensions-tab in the Manifest-editor? Maybe it is just a typo?!
Otherwise I don't know what's causing the NullPointerException. Now, MyE4Application.getInstance() returns null?


I register it in the Extension-tab in the Manifest-editor. No org.eclipse.e4.core.di.InjectionException returns null.

<?xml version="1.0" encoding="UTF-8"?>
<plugin>
   <extension
         id="product"
         point="org.eclipse.core.runtime.products">
      <product
            application="org.eclipse.e4.ui.workbench.swt.E4Application"
            name="net.restartets">
         <property
               name="appName"
               value="net.restartets">
         </property>
         <property
               name="applicationXMI"
               value="net.restartets/Application.e4xmi">
         </property>
         <property
               name="applicationCSS"
               value="platform:/plugin/net.restartets/css/default.css">
         </property>
      </product>
   </extension>
   
   <extension
         id="id1"
         point="org.eclipse.core.runtime.applications">
      <application
            cardinality="singleton-global"
            thread="main"
            visible="true">
         <run
               class="net.restartets.MyE4Application">
         </run>
      </application>
   </extension>
</plugin>


Quote:


I think this part of your plugin.xml

<extension
         id="product"
         point="org.eclipse.core.runtime.products">
      <product
            name="net.restartets"
            application="org.eclipse.e4.ui.workbench.swt.E4Application">
should be something like

<extension
         id="product"
         point="org.eclipse.core.runtime.products">
      <product
            name="net.restartets"
            application="net.restartets.MyE4Application">




Hi Christoph ,

I tried this. Then i get the following RuntimeException:

!ENTRY org.eclipse.osgi 4 0 2013-04-25 11:27:56.359
!MESSAGE Application error
!STACK 1
java.lang.RuntimeException: Application "net.restartets.MyE4Application" could not be found in the registry. The applications available are: org.eclipse.equinox.app.error, org.eclipse.e4.ui.workbench.swt.E4Application, org.eclipse.e4.ui.workbench.swt.GenTopic, org.eclipse.ant.core.antRunner, net.restartets.id1.
	at org.eclipse.equinox.internal.app.EclipseAppContainer.startDefaultApp(EclipseAppContainer.java:248)
	at org.eclipse.equinox.internal.app.MainApplicationLauncher.run(MainApplicationLauncher.java:29)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:353)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:180)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:629)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:584)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1438)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1414)


Quote:

Put a breakpoint in MyE4Application.start(...) an see if that realy gets called!


That is the problem. The the method start() in MyE4Application gets never called.
Re: Restart Application [message #1049090 is a reply to message #1049051] Thu, 25 April 2013 10:53 Go to previous messageGo to next message
Christoph Keimel is currently offline Christoph KeimelFriend
Messages: 482
Registered: December 2010
Location: Germany
Senior Member
You need to add the Application "net.restartets.MyE4Application" to the registry, just like the Exception says.

http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fextension-points%2Forg_eclipse_core_runtime_applications.html
Re: Restart Application [message #1049163 is a reply to message #1049090] Thu, 25 April 2013 13:07 Go to previous messageGo to next message
Marc Meier is currently offline Marc MeierFriend
Messages: 9
Registered: April 2013
Junior Member
OK.Now I have created a new project. Add the Application to the registry ...

And now I get another Exception :/

!ENTRY org.eclipse.osgi 4 0 2013-04-25 14:55:20.400
!MESSAGE Application error
!STACK 1
org.eclipse.core.runtime.CoreException: Plug-in "restart" was unable to instantiate class "restart.MyE4Application".
	at org.eclipse.core.internal.registry.osgi.RegistryStrategyOSGI.throwException(RegistryStrategyOSGI.java:194)
	at org.eclipse.core.internal.registry.osgi.RegistryStrategyOSGI.createExecutableExtension(RegistryStrategyOSGI.java:186)
	at org.eclipse.core.internal.registry.ExtensionRegistry.createExecutableExtension(ExtensionRegistry.java:905)
	at org.eclipse.core.internal.registry.ConfigurationElement.createExecutableExtension(ConfigurationElement.java:243)
	at org.eclipse.core.internal.registry.ConfigurationElementHandle.createExecutableExtension(ConfigurationElementHandle.java:55)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:191)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:353)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:180)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:629)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:584)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1438)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1414)
Caused by: java.lang.InstantiationException
	at sun.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance(Unknown Source)
	at java.lang.reflect.Constructor.newInstance(Unknown Source)
	at java.lang.Class.newInstance0(Unknown Source)
	at java.lang.Class.newInstance(Unknown Source)
	at org.eclipse.core.internal.registry.osgi.RegistryStrategyOSGI.createExecutableExtension(RegistryStrategyOSGI.java:184)
	... 16 more



the new plugin.xml:
<?xml version="1.0" encoding="UTF-8"?>
<plugin>

   <extension
         id="product"
         point="org.eclipse.core.runtime.products">
      <product
            name="restart"
            application="restart.id1">
         <property
               name="appName"
               value="restart">
         </property>
         <property
               name="applicationXMI"
               value="restart/Application.e4xmi">
         </property>
      </product>
   </extension>
   <extension
         id="id1"
         point="org.eclipse.core.runtime.applications">
      <application
            cardinality="singleton-global"
            thread="main"
            visible="true">
         <run
               class="restart.MyE4Application">
         </run>
      </application>
   </extension>


</plugin>



I get the Message (Warning):

"Discouraged access: The type E4Application is not accessible due to restriction on required library C:\eclipse_4.2\eclipse\plugins
\org.eclipse.e4.ui.workbench.swt_0.10.3.v20130124-133900.jar"

for the following import in the class MyE4Application.

import org.eclipse.e4.ui.internal.workbench.swt.E4Application;


Re: Restart Application [message #1049204 is a reply to message #1049163] Thu, 25 April 2013 13:58 Go to previous messageGo to next message
Christoph Keimel is currently offline Christoph KeimelFriend
Messages: 482
Registered: December 2010
Location: Germany
Senior Member
Hi Marc

1) the Warning is due to the fact that you are using an internal API which might (or might not) change in the future. As I described in the original post:

Beware though, that this workaround uses an internal API, which is likely to change in the future!

You can turn these warnings off in the settings if you wish (for the workspace or also for individual projects).

2) I don't know why you are getting the CoreException. Does your restart.MyE4Application have a public constructor without any parameters? The framework needs to create an instance of MyE4Application at some point ...

You might ask this question on the Equinox forum, since this (creating an application to run on Equinox) has nothing to do with E4. Maybe you could try to create a simple application (MySimpleApplication implements IApplication) with a System.out.println, without any dependencies. If you manage to get this to run (get MySimpleApplication .start(...) to get called), then you will probably know what is wrong with your current setup.

Hope this helps!
Christoph
Re: Restart Application [message #1049207 is a reply to message #1049204] Thu, 25 April 2013 14:02 Go to previous messageGo to next message
Christoph Keimel is currently offline Christoph KeimelFriend
Messages: 482
Registered: December 2010
Location: Germany
Senior Member
Hi Marc

another point: Is your MyE4Application abstract? If yes, it should not be. This was wrong in the answer on stackoverflow.

Greetings
christoph

[Updated on: Thu, 25 April 2013 14:03]

Report message to a moderator

Re: Restart Application [message #1049652 is a reply to message #1049207] Fri, 26 April 2013 05:42 Go to previous message
Marc Meier is currently offline Marc MeierFriend
Messages: 9
Registered: April 2013
Junior Member
Hi Chritsoph,

Yes my MyE4Application was abstract. ^^ I've also just noticed that.

Thanks for your help Bastian and Christoph Smile
Previous Topic:Questions about migrating from 3.5 to 4.3
Next Topic:Hints on using JFace Wizard with Dependency Injection?
Goto Forum:
  


Current Time: Tue Mar 19 05:07:31 GMT 2024

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

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

Back to the top