Search in sources :

Example 1 with CyShutdownListener

use of org.cytoscape.application.events.CyShutdownListener 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 CyShutdownListener

use of org.cytoscape.application.events.CyShutdownListener 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)2 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 CyShutdown (org.cytoscape.application.CyShutdown)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