Search in sources :

Example 1 with SessionSaveCancelledEvent

use of org.cytoscape.session.events.SessionSaveCancelledEvent in project cytoscape-impl by cytoscape.

the class SaveSessionAsTask method cancel.

@Override
public void cancel() {
    super.cancel();
    if (writer != null)
        writer.cancel();
    serviceRegistrar.getService(CyEventHelper.class).fireEvent(new SessionSaveCancelledEvent(this));
}
Also used : CyEventHelper(org.cytoscape.event.CyEventHelper) SessionSaveCancelledEvent(org.cytoscape.session.events.SessionSaveCancelledEvent)

Example 2 with SessionSaveCancelledEvent

use of org.cytoscape.session.events.SessionSaveCancelledEvent in project cytoscape-impl by cytoscape.

the class SaveSessionAsTask method run.

@Override
public void run(TaskMonitor tm) throws Exception {
    CySession session = null;
    final CyEventHelper eventHelper = serviceRegistrar.getService(CyEventHelper.class);
    try {
        tm.setProgress(0.05);
        session = serviceRegistrar.getService(CySessionManager.class).getCurrentSession();
        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) SessionSavedEvent(org.cytoscape.session.events.SessionSavedEvent) File(java.io.File) SessionSaveCancelledEvent(org.cytoscape.session.events.SessionSaveCancelledEvent)

Example 3 with SessionSaveCancelledEvent

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

CyEventHelper (org.cytoscape.event.CyEventHelper)3 SessionSaveCancelledEvent (org.cytoscape.session.events.SessionSaveCancelledEvent)3 File (java.io.File)2 RecentlyOpenedTracker (org.cytoscape.io.util.RecentlyOpenedTracker)2 CySession (org.cytoscape.session.CySession)2 SessionSavedEvent (org.cytoscape.session.events.SessionSavedEvent)2 CySessionManager (org.cytoscape.session.CySessionManager)1