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