Close the Eclipse Programmatically Application

I have an Eclipse application that I want to close. The trick is that this is a headless application, so I cannot use the following method:

PlatformUI.getWorkbench().close();

What alternative can I use to close the application?

My main plugin, which defines the product and application, contains the following dependencies:

  • org.eclipse.core.runtime

And this is about it.

I use extension points:

  • org.eclipse.core.runtime.applications

To determine my application.

I create a Swing interface for it, and I want to be able to close the application after a certain process or as a result of a user action. I wonder if there is any API in Eclipse for this or in this case I process the user interface myself, I need to close the application, leaving the class that implements IApplication.

+3
source share
1 answer

Can I use the ResourcesPluginservices?

See this class for an example of the stop method (I know that this is AbstractUI , but basically it is Plugin , and if you get such a class from a plugin you can implement the method org.osgi.framework.BundleActivator#stop.

/**
 * 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)

+1

Source: https://habr.com/ru/post/1744908/


All Articles