Search in sources :

Example 1 with SynchronousTaskManager

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;
    }
}
Also used : SynchronousTaskManager(org.cytoscape.work.SynchronousTaskManager) FileChooserFilter(org.cytoscape.util.swing.FileChooserFilter) CyNetworkManager(org.cytoscape.model.CyNetworkManager) CySessionManager(org.cytoscape.session.CySessionManager) ArrayList(java.util.ArrayList) List(java.util.List) NetworkList(org.cytoscape.internal.io.networklist.NetworkList) File(java.io.File) FileUtil(org.cytoscape.util.swing.FileUtil) SaveSessionAsTaskFactory(org.cytoscape.task.write.SaveSessionAsTaskFactory)

Example 2 with SynchronousTaskManager

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();
}
Also used : CommandExecutorTaskFactory(org.cytoscape.command.CommandExecutorTaskFactory) SynchronousTaskManager(org.cytoscape.work.SynchronousTaskManager) CyVersion(org.cytoscape.application.CyVersion) AvailableCommands(org.cytoscape.command.AvailableCommands) CommandLineArgs(org.cytoscape.cmdline.CommandLineArgs) CyShutdown(org.cytoscape.application.CyShutdown)

Example 3 with SynchronousTaskManager

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);
}
Also used : TaskIterator(org.cytoscape.work.TaskIterator) CommandExecutorTaskFactory(org.cytoscape.command.CommandExecutorTaskFactory) SynchronousTaskManager(org.cytoscape.work.SynchronousTaskManager) ArrayList(java.util.ArrayList)

Aggregations

SynchronousTaskManager (org.cytoscape.work.SynchronousTaskManager)3 ArrayList (java.util.ArrayList)2 CommandExecutorTaskFactory (org.cytoscape.command.CommandExecutorTaskFactory)2 File (java.io.File)1 List (java.util.List)1 CyShutdown (org.cytoscape.application.CyShutdown)1 CyVersion (org.cytoscape.application.CyVersion)1 CommandLineArgs (org.cytoscape.cmdline.CommandLineArgs)1 AvailableCommands (org.cytoscape.command.AvailableCommands)1 NetworkList (org.cytoscape.internal.io.networklist.NetworkList)1 CyNetworkManager (org.cytoscape.model.CyNetworkManager)1 CySessionManager (org.cytoscape.session.CySessionManager)1 SaveSessionAsTaskFactory (org.cytoscape.task.write.SaveSessionAsTaskFactory)1 FileChooserFilter (org.cytoscape.util.swing.FileChooserFilter)1 FileUtil (org.cytoscape.util.swing.FileUtil)1 TaskIterator (org.cytoscape.work.TaskIterator)1