views:

122

answers:

1

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

+1  A: 

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)

VonC
Actually, my application does not use the Resource Plugin either :D Any other chances?
Mario Ortegón
@Mario: is it a pure osgi plugin then?
VonC
@VonC I've added some more info. Now that I tought about it, I realize that probably there is no Eclipse way, because there is no Workbench. I am creating my own stuff for UI, so I have to dispose of it myself.
Mario Ortegón
@Mario: you are right, you only need to determine where that un-allocation can take place. I will have look at it tomorrow.
VonC