use of org.cytoscape.work.SynchronousTaskManager in project cytoscape-impl by cytoscape.
the class SessionHandler method handleEvent.
@Override
public void handleEvent(final CyShutdownEvent e) {
final CyNetworkManager netMgr = serviceRegistrar.getService(CyNetworkManager.class);
// If there are no networks, just quit.
if (netMgr.getNetworkSet().isEmpty() || e.forceShutdown())
return;
// Ask user whether to save current session or not.
final String msg = "Do you want to save your session?";
final String header = "Save Networks Before Quitting?";
final Object[] options = { "Yes, save and quit", "No, just quit", "Cancel" };
final int n = JOptionPane.showOptionDialog(desktop.getJFrame(), msg, header, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
if (n == JOptionPane.NO_OPTION) {
return;
} else if (n == JOptionPane.YES_OPTION) {
final CySessionManager sessionMgr = serviceRegistrar.getService(CySessionManager.class);
final String sessionFileName = sessionMgr.getCurrentSessionFileName();
final File file;
if (sessionFileName == null || sessionFileName.isEmpty()) {
FileChooserFilter filter = new FileChooserFilter("Session File", "cys");
List<FileChooserFilter> filterCollection = new ArrayList<FileChooserFilter>(1);
filterCollection.add(filter);
final FileUtil fileUtil = serviceRegistrar.getService(FileUtil.class);
file = fileUtil.getFile(desktop, "Save Session File", FileUtil.SAVE, filterCollection);
} else {
file = new File(sessionFileName);
}
if (file == null) {
// just check the file again in case the file chooser dialoge task is canceled.
e.abortShutdown("User canceled the shutdown request.");
return;
}
final SynchronousTaskManager<?> syncTaskMgr = serviceRegistrar.getService(SynchronousTaskManager.class);
final SaveSessionAsTaskFactory saveTaskFactory = serviceRegistrar.getService(SaveSessionAsTaskFactory.class);
syncTaskMgr.execute(saveTaskFactory.createTaskIterator(file));
return;
} else {
e.abortShutdown("User canceled the shutdown request.");
return;
}
}
use of org.cytoscape.work.SynchronousTaskManager in project cytoscape-impl by cytoscape.
the class CyActivator method start.
public void start(BundleContext bc) {
final CommandLineArgs args = getService(bc, CommandLineArgs.class);
final CyVersion cyVersion = getService(bc, CyVersion.class);
final CyShutdown cyShutdown = getService(bc, CyShutdown.class);
final AvailableCommands availableCommands = getService(bc, AvailableCommands.class);
final CommandExecutorTaskFactory cmdExec = getService(bc, CommandExecutorTaskFactory.class);
final SynchronousTaskManager taskManager = getService(bc, SynchronousTaskManager.class);
new Thread(new Runnable() {
public void run() {
StartupConfig sc = new StartupConfig(cmdExec, taskManager);
Parser p = new Parser(args.getArgs(), cyShutdown, cyVersion, sc, availableCommands);
sc.start();
try {
Thread.sleep(200);
} catch (InterruptedException ie) {
ie.printStackTrace();
}
cyShutdown.exit(0);
}
}).start();
}
use of org.cytoscape.work.SynchronousTaskManager in project PhenomeScape by soulj.
the class CommandExecutor method execute.
public static void execute(String command, CyServiceRegistrar cyServiceRegistrar) {
CommandExecutorTaskFactory executor = cyServiceRegistrar.getService(CommandExecutorTaskFactory.class);
List<String> commands = new ArrayList<String>();
commands.add(command);
TaskIterator task = executor.createTaskIterator(commands, null);
SynchronousTaskManager manager = cyServiceRegistrar.getService(SynchronousTaskManager.class);
manager.execute(task);
}
Aggregations