use of org.cytoscape.event.CyEventHelper 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.event.CyEventHelper 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());
}
}
use of org.cytoscape.event.CyEventHelper 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());
}
}
use of org.cytoscape.event.CyEventHelper in project cytoscape-impl by cytoscape.
the class NewNetworkSelectedNodesOnlyTaskFactoryTest method testObserver.
@Test
public void testObserver() throws Exception {
NetworkViewTestSupport viewSupport = new NetworkViewTestSupport();
NetworkTestSupport networkSupport = new NetworkTestSupport();
CyNetworkFactory networkFactory = networkSupport.getNetworkFactory();
UndoSupport undoSupport = mock(UndoSupport.class);
CyRootNetworkManager crnf = new CyRootNetworkManagerImpl();
CyNetworkViewFactory cnvf = viewSupport.getNetworkViewFactory();
CyNetworkManager netmgr = mock(CyNetworkManager.class);
CyNetworkViewManager networkViewManager = mock(CyNetworkViewManager.class);
CyNetworkNaming naming = mock(CyNetworkNaming.class);
VisualMappingManager vmm = mock(VisualMappingManager.class);
CyApplicationManager appManager = mock(CyApplicationManager.class);
CyEventHelper eventHelper = mock(CyEventHelper.class);
CyGroupManager groupMgr = mock(CyGroupManager.class);
RenderingEngineManager renderingEngineMgr = mock(RenderingEngineManager.class);
CyLayoutAlgorithm defLayout = mock(CyLayoutAlgorithm.class);
CyLayoutAlgorithmManager layoutMgr = mock(CyLayoutAlgorithmManager.class);
when(layoutMgr.getDefaultLayout()).thenReturn(defLayout);
CyServiceRegistrar serviceRegistrar = mock(CyServiceRegistrar.class);
when(serviceRegistrar.getService(CyLayoutAlgorithmManager.class)).thenReturn(layoutMgr);
NewNetworkSelectedNodesOnlyTaskFactoryImpl factory = new NewNetworkSelectedNodesOnlyTaskFactoryImpl(undoSupport, crnf, cnvf, netmgr, networkViewManager, naming, vmm, appManager, eventHelper, groupMgr, renderingEngineMgr, serviceRegistrar);
CyNetwork network = networkFactory.createNetwork();
CyNode node = network.addNode();
network.getRow(node).set(CyNetwork.SELECTED, true);
TaskObserver observer = mock(TaskObserver.class);
TaskMonitor taskMonitor = mock(TaskMonitor.class);
TaskIterator iterator = factory.createTaskIterator(network);
while (iterator.hasNext()) {
Task t = iterator.next();
t.run(taskMonitor);
if (t instanceof ObservableTask)
observer.taskFinished((ObservableTask) t);
}
verify(observer, times(1)).taskFinished(any(ObservableTask.class));
}
use of org.cytoscape.event.CyEventHelper in project cytoscape-impl by cytoscape.
the class HideSelectedNodesTaskFactoryTest method testRun.
@Test
public void testRun() throws Exception {
UndoSupport undoSupport = mock(UndoSupport.class);
CyEventHelper eventHelper = mock(CyEventHelper.class);
VisualMappingManager vmMgr = mock(VisualMappingManager.class);
CyServiceRegistrar serviceRegistrar = mock(CyServiceRegistrar.class);
when(serviceRegistrar.getService(UndoSupport.class)).thenReturn(undoSupport);
when(serviceRegistrar.getService(CyEventHelper.class)).thenReturn(eventHelper);
when(serviceRegistrar.getService(VisualMappingManager.class)).thenReturn(vmMgr);
HideSelectedNodesTaskFactoryImpl factory = new HideSelectedNodesTaskFactoryImpl(serviceRegistrar);
CyNetworkView view = mock(CyNetworkView.class);
TaskIterator ti = factory.createTaskIterator(view);
assertNotNull(ti);
assertTrue(ti.hasNext());
Task t = ti.next();
assertNotNull(t);
}
Aggregations