Search in sources :

Example 46 with CyEventHelper

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

Example 47 with CyEventHelper

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());
    }
}
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 48 with CyEventHelper

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

Example 49 with CyEventHelper

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));
}
Also used : CyEventHelper(org.cytoscape.event.CyEventHelper) Task(org.cytoscape.work.Task) ObservableTask(org.cytoscape.work.ObservableTask) CyNetwork(org.cytoscape.model.CyNetwork) CyServiceRegistrar(org.cytoscape.service.util.CyServiceRegistrar) ObservableTask(org.cytoscape.work.ObservableTask) TaskIterator(org.cytoscape.work.TaskIterator) TaskMonitor(org.cytoscape.work.TaskMonitor) CyLayoutAlgorithm(org.cytoscape.view.layout.CyLayoutAlgorithm) CyNode(org.cytoscape.model.CyNode) CyGroupManager(org.cytoscape.group.CyGroupManager) CyRootNetworkManager(org.cytoscape.model.subnetwork.CyRootNetworkManager) CyNetworkViewManager(org.cytoscape.view.model.CyNetworkViewManager) RenderingEngineManager(org.cytoscape.view.presentation.RenderingEngineManager) CyRootNetworkManagerImpl(org.cytoscape.model.internal.CyRootNetworkManagerImpl) NetworkTestSupport(org.cytoscape.model.NetworkTestSupport) NetworkViewTestSupport(org.cytoscape.ding.NetworkViewTestSupport) UndoSupport(org.cytoscape.work.undo.UndoSupport) CyApplicationManager(org.cytoscape.application.CyApplicationManager) TaskObserver(org.cytoscape.work.TaskObserver) CyNetworkManager(org.cytoscape.model.CyNetworkManager) CyNetworkViewFactory(org.cytoscape.view.model.CyNetworkViewFactory) CyLayoutAlgorithmManager(org.cytoscape.view.layout.CyLayoutAlgorithmManager) CyNetworkNaming(org.cytoscape.session.CyNetworkNaming) CyNetworkFactory(org.cytoscape.model.CyNetworkFactory) VisualMappingManager(org.cytoscape.view.vizmap.VisualMappingManager) Test(org.junit.Test)

Example 50 with CyEventHelper

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);
}
Also used : CyEventHelper(org.cytoscape.event.CyEventHelper) Task(org.cytoscape.work.Task) TaskIterator(org.cytoscape.work.TaskIterator) VisualMappingManager(org.cytoscape.view.vizmap.VisualMappingManager) UndoSupport(org.cytoscape.work.undo.UndoSupport) CyNetworkView(org.cytoscape.view.model.CyNetworkView) CyServiceRegistrar(org.cytoscape.service.util.CyServiceRegistrar) Test(org.junit.Test)

Aggregations

CyEventHelper (org.cytoscape.event.CyEventHelper)63 CyNetworkView (org.cytoscape.view.model.CyNetworkView)19 VisualMappingManager (org.cytoscape.view.vizmap.VisualMappingManager)19 CyNode (org.cytoscape.model.CyNode)15 UndoSupport (org.cytoscape.work.undo.UndoSupport)14 CyServiceRegistrar (org.cytoscape.service.util.CyServiceRegistrar)13 ArrayList (java.util.ArrayList)11 CyApplicationManager (org.cytoscape.application.CyApplicationManager)11 CyNetwork (org.cytoscape.model.CyNetwork)10 VisualStyle (org.cytoscape.view.vizmap.VisualStyle)10 Test (org.junit.Test)10 Task (org.cytoscape.work.Task)9 CyTable (org.cytoscape.model.CyTable)8 CyNetworkViewManager (org.cytoscape.view.model.CyNetworkViewManager)8 TaskIterator (org.cytoscape.work.TaskIterator)8 CyEdge (org.cytoscape.model.CyEdge)7 CyRow (org.cytoscape.model.CyRow)7 CyNetworkViewFactory (org.cytoscape.view.model.CyNetworkViewFactory)6 CyNetworkManager (org.cytoscape.model.CyNetworkManager)5 CyNetworkNaming (org.cytoscape.session.CyNetworkNaming)5