Search in sources :

Example 1 with SessionAboutToBeLoadedEvent

use of org.cytoscape.session.events.SessionAboutToBeLoadedEvent 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 2 with SessionAboutToBeLoadedEvent

use of org.cytoscape.session.events.SessionAboutToBeLoadedEvent 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)

Aggregations

CyEventHelper (org.cytoscape.event.CyEventHelper)2 CySessionManager (org.cytoscape.session.CySessionManager)2 SessionAboutToBeLoadedEvent (org.cytoscape.session.events.SessionAboutToBeLoadedEvent)2 URI (java.net.URI)1 CySessionReaderManager (org.cytoscape.io.read.CySessionReaderManager)1