Close Eclipse Application Programmatically
I have an Eclipse Application that I want to close. The catch is that it is a headless application, so I can not use the following method:
PlatformUI.getWorkbench().close();
What alternative can I use to close the application cleanly?
My main plugin, the one that defines the product and the application, contains the following dependencies:
- org.eclipse.core.runtime
And that is about it.
I use the extension points:
- org.eclipse.core.runtime.applications
To define my app.
I create a Swing UI for it, and I want to be able to close the application after a certain process is done, or as a result of a user action. I开发者_如何学Go wonder if there is any API in Eclipse to do that, or in this case that I handle the UI on my own, do I have to close the application by exiting on the class that implements IApplication.
May be using ResourcesPlugin
services?
See this class for an example of stop method (I know it is an AbstractUI class, but it is basically a Plugin, and if you have such a class deriving from Plugin, you can implement the org.osgi.framework.BundleActivator#stop
method.
/**
* Shuts down this plug-in and discards all plug-in state.
*
* @exception CoreException
* If this method fails to shut down this plug-in.
*
* @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
*/
public final void stop(BundleContext context) throws Exception {
try {
/* Unregister as a save participant */
if (ResourcesPlugin.getWorkspace() != null) {
ResourcesPlugin.getWorkspace().removeSaveParticipant(this);
}
} catch (Exception e) {
throw new CoreException(new Status(IStatus.ERROR,
getSymbolicName(), CommonUIStatusCodes.PLUGIN_SHUTDOWN_FAILURE,
getShutdownErrorMessage(getPluginName()), e));
} finally {
super.stop(context);
}
}
(obviously, do not use CommonUIStatusCodes
)
精彩评论