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);
}
}
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;
}
}
Aggregations