Mario Ortegón
Mario Ortegón

Reputation: 18900

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:

And that is about it.

I use the extension points:

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 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.

Upvotes: 3

Views: 4115

Answers (1)

VonC
VonC

Reputation: 1323303

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)

Upvotes: 1

Related Questions