Search in sources :

Example 1 with CySessionManager

use of org.cytoscape.session.CySessionManager in project cytoscape-impl by cytoscape.

the class CyActivator method start.

@Override
public void start(BundleContext bc) {
    CyServiceRegistrar serviceRegistrar = getService(bc, CyServiceRegistrar.class);
    CyEventHelper cyEventHelperRef = getService(bc, CyEventHelper.class);
    CyNetworkNaming cyNetworkNamingServiceRef = getService(bc, CyNetworkNaming.class);
    UndoSupport undoSupportServiceRef = getService(bc, UndoSupport.class);
    CyNetworkViewFactory cyNetworkViewFactoryServiceRef = getService(bc, CyNetworkViewFactory.class);
    CyNetworkFactory cyNetworkFactoryServiceRef = getService(bc, CyNetworkFactory.class);
    CyRootNetworkManager cyRootNetworkFactoryServiceRef = getService(bc, CyRootNetworkManager.class);
    VisualMappingManager visualMappingManagerServiceRef = getService(bc, VisualMappingManager.class);
    CyNetworkViewWriterManager networkViewWriterManagerServiceRef = getService(bc, CyNetworkViewWriterManager.class);
    CyNetworkManager cyNetworkManagerServiceRef = getService(bc, CyNetworkManager.class);
    CyNetworkViewManager cyNetworkViewManagerServiceRef = getService(bc, CyNetworkViewManager.class);
    CyApplicationManager cyApplicationManagerServiceRef = getService(bc, CyApplicationManager.class);
    CySessionManager cySessionManagerServiceRef = getService(bc, CySessionManager.class);
    CyTableFactory cyTableFactoryServiceRef = getService(bc, CyTableFactory.class);
    CyTableManager cyTableManagerServiceRef = getService(bc, CyTableManager.class);
    CyLayoutAlgorithmManager cyLayoutsServiceRef = getService(bc, CyLayoutAlgorithmManager.class);
    CyTableWriterManager cyTableWriterManagerRef = getService(bc, CyTableWriterManager.class);
    SynchronousTaskManager<?> synchronousTaskManagerServiceRef = getService(bc, SynchronousTaskManager.class);
    TunableSetter tunableSetterServiceRef = getService(bc, TunableSetter.class);
    CyRootNetworkManager rootNetworkManagerServiceRef = getService(bc, CyRootNetworkManager.class);
    CyNetworkTableManager cyNetworkTableManagerServiceRef = getService(bc, CyNetworkTableManager.class);
    RenderingEngineManager renderingEngineManagerServiceRef = getService(bc, RenderingEngineManager.class);
    CyNetworkViewFactory nullNetworkViewFactory = getService(bc, CyNetworkViewFactory.class, "(id=NullCyNetworkViewFactory)");
    CyGroupManager cyGroupManager = getService(bc, CyGroupManager.class);
    CyGroupFactory cyGroupFactory = getService(bc, CyGroupFactory.class);
    {
        DynamicTaskFactoryProvisionerImpl factory = new DynamicTaskFactoryProvisionerImpl(serviceRegistrar);
        registerAllServices(bc, factory);
    }
    createPreferencesTaskFactories(bc, serviceRegistrar);
    createFilterTaskFactories(bc, serviceRegistrar);
    createTableTaskFactories(bc, serviceRegistrar, undoSupportServiceRef, cyNetworkManagerServiceRef, cyApplicationManagerServiceRef, cyTableFactoryServiceRef, cyTableManagerServiceRef, cyTableWriterManagerRef, tunableSetterServiceRef, rootNetworkManagerServiceRef, cyNetworkTableManagerServiceRef);
    createNetworkTaskFactories(bc, serviceRegistrar, cyEventHelperRef, cyNetworkNamingServiceRef, undoSupportServiceRef, cyNetworkViewFactoryServiceRef, cyNetworkFactoryServiceRef, cyRootNetworkFactoryServiceRef, visualMappingManagerServiceRef, cyNetworkManagerServiceRef, cyNetworkViewManagerServiceRef, cyApplicationManagerServiceRef, synchronousTaskManagerServiceRef, rootNetworkManagerServiceRef, cyNetworkTableManagerServiceRef, renderingEngineManagerServiceRef, nullNetworkViewFactory, cyGroupManager, cyGroupFactory, networkViewWriterManagerServiceRef, tunableSetterServiceRef);
    createViewTaskFactories(bc, cyEventHelperRef, undoSupportServiceRef, visualMappingManagerServiceRef, networkViewWriterManagerServiceRef, cyNetworkViewManagerServiceRef, cyApplicationManagerServiceRef, cyLayoutsServiceRef, tunableSetterServiceRef, renderingEngineManagerServiceRef, cyNetworkManagerServiceRef, cySessionManagerServiceRef, serviceRegistrar);
    createVizmapTaskFactories(bc, serviceRegistrar);
    createSessionTaskFactories(bc, serviceRegistrar);
    createGroupTaskFactories(bc, undoSupportServiceRef, cyApplicationManagerServiceRef, cyGroupManager, cyGroupFactory, serviceRegistrar);
    createNodeEdgeTaskFactories(bc, serviceRegistrar, cyEventHelperRef, undoSupportServiceRef, cyNetworkViewManagerServiceRef, tunableSetterServiceRef, cyApplicationManagerServiceRef, cyTableManagerServiceRef, renderingEngineManagerServiceRef, visualMappingManagerServiceRef);
    createLayoutTaskFactories(bc, serviceRegistrar);
    createHelpTaskFactories(bc, serviceRegistrar);
}
Also used : CyEventHelper(org.cytoscape.event.CyEventHelper) CyNetworkTableManager(org.cytoscape.model.CyNetworkTableManager) CyRootNetworkManager(org.cytoscape.model.subnetwork.CyRootNetworkManager) CyNetworkViewManager(org.cytoscape.view.model.CyNetworkViewManager) RenderingEngineManager(org.cytoscape.view.presentation.RenderingEngineManager) CyTableWriterManager(org.cytoscape.io.write.CyTableWriterManager) UndoSupport(org.cytoscape.work.undo.UndoSupport) CyServiceRegistrar(org.cytoscape.service.util.CyServiceRegistrar) CyApplicationManager(org.cytoscape.application.CyApplicationManager) CyTableFactory(org.cytoscape.model.CyTableFactory) TunableSetter(org.cytoscape.work.TunableSetter) CyNetworkManager(org.cytoscape.model.CyNetworkManager) CyNetworkViewFactory(org.cytoscape.view.model.CyNetworkViewFactory) CyTableManager(org.cytoscape.model.CyTableManager) CyLayoutAlgorithmManager(org.cytoscape.view.layout.CyLayoutAlgorithmManager) CyNetworkNaming(org.cytoscape.session.CyNetworkNaming) CyNetworkViewWriterManager(org.cytoscape.io.write.CyNetworkViewWriterManager) CySessionManager(org.cytoscape.session.CySessionManager) CyNetworkFactory(org.cytoscape.model.CyNetworkFactory) VisualMappingManager(org.cytoscape.view.vizmap.VisualMappingManager) CyGroupFactory(org.cytoscape.group.CyGroupFactory) CyGroupManager(org.cytoscape.group.CyGroupManager)

Example 2 with CySessionManager

use of org.cytoscape.session.CySessionManager in project cytoscape-impl by cytoscape.

the class NewSessionTask method run.

@Override
public void run(TaskMonitor tm) throws Exception {
    if (confirm && destroyCurrentSession) {
        // Also checks destroyCurrentSession for backwards compatibility
        tm.setTitle("Create New Session");
        tm.setProgress(0.0);
        final CyEventHelper eventHelper = serviceRegistrar.getService(CyEventHelper.class);
        final CySessionManager sessionManager = serviceRegistrar.getService(CySessionManager.class);
        // Let everybody know the current session will be destroyed
        eventHelper.fireEvent(new SessionAboutToBeLoadedEvent(this));
        tm.setProgress(0.1);
        // Dispose the current session before loading the new one
        sessionManager.disposeCurrentSession();
        tm.setProgress(0.2);
        sessionManager.setCurrentSession(null, null);
        tm.setProgress(1.0);
    }
}
Also used : CyEventHelper(org.cytoscape.event.CyEventHelper) CySessionManager(org.cytoscape.session.CySessionManager) SessionAboutToBeLoadedEvent(org.cytoscape.session.events.SessionAboutToBeLoadedEvent)

Example 3 with CySessionManager

use of org.cytoscape.session.CySessionManager 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 4 with CySessionManager

use of org.cytoscape.session.CySessionManager in project cytoscape-impl by cytoscape.

the class OpenSessionCommandTask method run.

@Override
public void run(final TaskMonitor tm) throws Exception {
    final CyEventHelper eventHelper = serviceRegistrar.getService(CyEventHelper.class);
    final CySessionManager sessionManager = serviceRegistrar.getService(CySessionManager.class);
    try {
        try {
            tm.setTitle("Open Session");
            tm.setStatusMessage("Opening Session File.\n\nIt may take a while.\nPlease wait...");
            tm.setProgress(0.0);
            if (file == null && (url == null || url.trim().isEmpty()))
                throw new NullPointerException("No file or URL specified.");
            final CySessionReaderManager readerMgr = serviceRegistrar.getService(CySessionReaderManager.class);
            if (file != null)
                reader = readerMgr.getReader(file.toURI(), file.getName());
            else
                reader = readerMgr.getReader(new URI(url.trim()), url);
            if (reader == null)
                throw new NullPointerException("Failed to find appropriate reader for file: " + file);
            // Let everybody know the current session will be destroyed
            eventHelper.fireEvent(new SessionAboutToBeLoadedEvent(this));
            tm.setProgress(0.1);
            // Dispose the current session before loading the new one
            serviceRegistrar.getService(CySessionManager.class).disposeCurrentSession();
            tm.setProgress(0.2);
            // Now we can read the new session
            if (!cancelled)
                reader.run(tm);
            tm.setProgress(0.8);
        } catch (Exception e) {
            disposeCancelledSession(e, sessionManager);
            throw e;
        }
        if (cancelled)
            disposeCancelledSession(null, sessionManager);
        else
            changeCurrentSession(sessionManager, tm);
    } finally {
        // plug big memory leak
        reader = null;
    }
}
Also used : CyEventHelper(org.cytoscape.event.CyEventHelper) CySessionManager(org.cytoscape.session.CySessionManager) SessionAboutToBeLoadedEvent(org.cytoscape.session.events.SessionAboutToBeLoadedEvent) URI(java.net.URI) CySessionReaderManager(org.cytoscape.io.read.CySessionReaderManager)

Example 5 with CySessionManager

use of org.cytoscape.session.CySessionManager in project cytoscape-impl by cytoscape.

the class SaveSessionTask method run.

@Override
public void run(TaskMonitor tm) throws Exception {
    CySession session = null;
    File file = null;
    final CyEventHelper eventHelper = serviceRegistrar.getService(CyEventHelper.class);
    try {
        final CySessionManager sessionMgr = serviceRegistrar.getService(CySessionManager.class);
        tm.setProgress(0.05);
        session = sessionMgr.getCurrentSession();
        final String fileName = sessionMgr.getCurrentSessionFileName();
        file = new File(fileName);
        writer = new CySessionWriter(session, file, serviceRegistrar);
        writer.run(tm);
        tm.setProgress(1.0);
        // Add this session file URL as the most recent file.
        if (!file.getName().endsWith(".cys"))
            file = new File(file.getPath() + ".cys");
    } catch (Exception e) {
        eventHelper.fireEvent(new SessionSaveCancelledEvent(this));
        throw e;
    }
    if (!cancelled) {
        // Fire event to tell others session has been saved to a file.
        eventHelper.fireEvent(new SessionSavedEvent(this, session, file.getAbsolutePath()));
        serviceRegistrar.getService(RecentlyOpenedTracker.class).add(file.toURI().toURL());
    }
}
Also used : CySession(org.cytoscape.session.CySession) CyEventHelper(org.cytoscape.event.CyEventHelper) RecentlyOpenedTracker(org.cytoscape.io.util.RecentlyOpenedTracker) CySessionManager(org.cytoscape.session.CySessionManager) SessionSavedEvent(org.cytoscape.session.events.SessionSavedEvent) File(java.io.File) SessionSaveCancelledEvent(org.cytoscape.session.events.SessionSaveCancelledEvent)

Aggregations

CySessionManager (org.cytoscape.session.CySessionManager)6 CyEventHelper (org.cytoscape.event.CyEventHelper)5 CyNetworkManager (org.cytoscape.model.CyNetworkManager)3 File (java.io.File)2 CyApplicationManager (org.cytoscape.application.CyApplicationManager)2 CySessionReaderManager (org.cytoscape.io.read.CySessionReaderManager)2 SaveSessionAsTaskFactory (org.cytoscape.task.write.SaveSessionAsTaskFactory)2 FileUtil (org.cytoscape.util.swing.FileUtil)2 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Properties (java.util.Properties)1 AppManagerAction (org.cytoscape.app.internal.action.AppManagerAction)1 CitationsAction (org.cytoscape.app.internal.action.CitationsAction)1 AppManager (org.cytoscape.app.internal.manager.AppManager)1 UpdateManager (org.cytoscape.app.internal.net.UpdateManager)1 WebQuerier (org.cytoscape.app.internal.net.WebQuerier)1 AddAllowOriginHeader (org.cytoscape.app.internal.net.server.AddAllowOriginHeader)1 AppGetResponder (org.cytoscape.app.internal.net.server.AppGetResponder)1 CyHttpd (org.cytoscape.app.internal.net.server.CyHttpd)1