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());
});
}
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());
}
}
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;
}
Aggregations