Search in sources :

Example 1 with CyShutdownEvent

use of org.cytoscape.application.events.CyShutdownEvent in project cytoscape-impl by cytoscape.

the class MacCyActivator method start.

@Override
public void start(BundleContext context) throws Exception {
    final CyServiceRegistrar serviceRegistrar = getService(context, CyServiceRegistrar.class);
    final CyShutdown shutdown = getService(context, CyShutdown.class);
    final TaskFactory aboutTaskFactory = new HelpAboutTaskFactory(serviceRegistrar);
    final DialogTaskManager taskManager = getService(context, DialogTaskManager.class);
    final CyShutdownEvent[] lastShutdownEvent = new CyShutdownEvent[1];
    CyShutdownListener listener = (CyShutdownEvent e) -> {
        lastShutdownEvent[0] = e;
    };
    registerService(context, listener, CyShutdownListener.class, new Properties());
    Application application = Application.getApplication();
    application.setQuitHandler((QuitEvent event, QuitResponse response) -> {
        shutdown.exit(0);
        if (lastShutdownEvent[0] != null && !lastShutdownEvent[0].actuallyShutdown()) {
            response.cancelQuit();
        }
    });
    application.setAboutHandler((AboutEvent event) -> {
        taskManager.execute(aboutTaskFactory.createTaskIterator());
    });
}
Also used : AboutEvent(com.apple.eawt.AppEvent.AboutEvent) DialogTaskManager(org.cytoscape.work.swing.DialogTaskManager) Properties(java.util.Properties) CyServiceRegistrar(org.cytoscape.service.util.CyServiceRegistrar) CyShutdownListener(org.cytoscape.application.events.CyShutdownListener) HelpAboutTaskFactory(org.cytoscape.internal.view.help.HelpAboutTaskFactory) HelpAboutTaskFactory(org.cytoscape.internal.view.help.HelpAboutTaskFactory) TaskFactory(org.cytoscape.work.TaskFactory) Application(com.apple.eawt.Application) CyShutdownEvent(org.cytoscape.application.events.CyShutdownEvent) QuitResponse(com.apple.eawt.QuitResponse) CyShutdown(org.cytoscape.application.CyShutdown) QuitEvent(com.apple.eawt.AppEvent.QuitEvent)

Example 2 with CyShutdownEvent

use of org.cytoscape.application.events.CyShutdownEvent in project cytoscape-impl by cytoscape.

the class ShutdownHandler method exit.

@Override
public void exit(int retVal, boolean force) {
    CyShutdownEvent ev = new CyShutdownEvent(ShutdownHandler.this, force);
    serviceRegistrar.getService(CyEventHelper.class).fireEvent(ev);
    if (ev.actuallyShutdown()) {
        try {
            logger.info("#CiaoBello", rootBundle);
            CyApplicationConfiguration c = serviceRegistrar.getService(CyApplicationConfiguration.class);
            removeFailSafeFile(c.getConfigurationDirectoryLocation().getAbsolutePath());
            rootBundle.stop();
        } catch (BundleException e) {
            logger.error("Error while shutting down", e);
        }
    } else {
        logger.info("NOT shutting down, per listener instruction: " + ev.abortShutdownReason());
    }
}
Also used : CyEventHelper(org.cytoscape.event.CyEventHelper) BundleException(org.osgi.framework.BundleException) CyApplicationConfiguration(org.cytoscape.application.CyApplicationConfiguration) CyShutdownEvent(org.cytoscape.application.events.CyShutdownEvent)

Example 3 with CyShutdownEvent

use of org.cytoscape.application.events.CyShutdownEvent in project cytoscape-impl by cytoscape.

the class AppManagerAction method createShutdownListener.

private CyShutdownListener createShutdownListener() {
    CyShutdownListener shutdownListener = new CyShutdownListener() {

        @Override
        public void handleEvent(CyShutdownEvent e) {
            if (dialog != null) {
                dialog.setVisible(false);
                dialog.dispose();
            }
            serviceRegistrar.unregisterService(this, CyShutdownListener.class);
        }
    };
    return shutdownListener;
}
Also used : CyShutdownListener(org.cytoscape.application.events.CyShutdownListener) CyShutdownEvent(org.cytoscape.application.events.CyShutdownEvent)

Aggregations

CyShutdownEvent (org.cytoscape.application.events.CyShutdownEvent)3 CyShutdownListener (org.cytoscape.application.events.CyShutdownListener)2 AboutEvent (com.apple.eawt.AppEvent.AboutEvent)1 QuitEvent (com.apple.eawt.AppEvent.QuitEvent)1 Application (com.apple.eawt.Application)1 QuitResponse (com.apple.eawt.QuitResponse)1 Properties (java.util.Properties)1 CyApplicationConfiguration (org.cytoscape.application.CyApplicationConfiguration)1 CyShutdown (org.cytoscape.application.CyShutdown)1 CyEventHelper (org.cytoscape.event.CyEventHelper)1 HelpAboutTaskFactory (org.cytoscape.internal.view.help.HelpAboutTaskFactory)1 CyServiceRegistrar (org.cytoscape.service.util.CyServiceRegistrar)1 TaskFactory (org.cytoscape.work.TaskFactory)1 DialogTaskManager (org.cytoscape.work.swing.DialogTaskManager)1 BundleException (org.osgi.framework.BundleException)1