Search in sources :

Example 36 with CyNetworkManager

use of org.cytoscape.model.CyNetworkManager 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 37 with CyNetworkManager

use of org.cytoscape.model.CyNetworkManager in project cytoscape-impl by cytoscape.

the class SetCurrentNetworkTaskFactoryImplTest method testRun.

@Test
public void testRun() throws Exception {
    CyApplicationManager appMgr = mock(CyApplicationManager.class);
    CyNetworkManager netmgr = mock(CyNetworkManager.class);
    ;
    SetCurrentNetworkTaskFactoryImpl factory = new SetCurrentNetworkTaskFactoryImpl(appMgr, netmgr);
    TaskIterator ti = factory.createTaskIterator();
    assertNotNull(ti);
    assertTrue(ti.hasNext());
    Task t = ti.next();
    assertNotNull(t);
}
Also used : CyApplicationManager(org.cytoscape.application.CyApplicationManager) Task(org.cytoscape.work.Task) CyNetworkManager(org.cytoscape.model.CyNetworkManager) TaskIterator(org.cytoscape.work.TaskIterator) SetCurrentNetworkTaskFactoryImpl(org.cytoscape.task.internal.setcurrent.SetCurrentNetworkTaskFactoryImpl) Test(org.junit.Test)

Example 38 with CyNetworkManager

use of org.cytoscape.model.CyNetworkManager in project cytoscape-impl by cytoscape.

the class AddNestedNetworkTaskFactory method isReady.

@Override
public boolean isReady(View<CyNode> nodeView, CyNetworkView networkView) {
    if (!super.isReady(nodeView, networkView))
        return false;
    // Check if the network is registered.
    // Nodes with unregistered network pointers should be ignored because they are probably being used as something
    // else other than regular nested networks (e.g. groups).
    final CyNode node = nodeView.getModel();
    final CyNetwork net = networkView.getModel();
    final CyNetwork netPointer = node.getNetworkPointer();
    final CyNetworkManager netMgr = serviceRegistrar.getService(CyNetworkManager.class);
    final CyGroupManager grMgr = serviceRegistrar.getService(CyGroupManager.class);
    return (netPointer == null) || (netMgr.networkExists(netPointer.getSUID()) && !grMgr.isGroup(node, net));
}
Also used : CyNetworkManager(org.cytoscape.model.CyNetworkManager) CyNetwork(org.cytoscape.model.CyNetwork) CyNode(org.cytoscape.model.CyNode) CyGroupManager(org.cytoscape.group.CyGroupManager)

Example 39 with CyNetworkManager

use of org.cytoscape.model.CyNetworkManager in project cytoscape-impl by cytoscape.

the class GoToNestedNetworkTaskFactory method isReady.

@Override
public boolean isReady(View<CyNode> nodeView, CyNetworkView networkView) {
    if (!super.isReady(nodeView, networkView))
        return false;
    // Check if there is a network pointer and if it is registered.
    final CyNode node = nodeView.getModel();
    final CyNetwork np = node.getNetworkPointer();
    final CyNetworkManager netMgr = serviceRegistrar.getService(CyNetworkManager.class);
    return np != null && netMgr.networkExists(np.getSUID());
}
Also used : CyNetworkManager(org.cytoscape.model.CyNetworkManager) CyNetwork(org.cytoscape.model.CyNetwork) CyNode(org.cytoscape.model.CyNode)

Example 40 with CyNetworkManager

use of org.cytoscape.model.CyNetworkManager in project cytoscape-impl by cytoscape.

the class GoToNestedNetworkTask method run.

@Override
public void run(TaskMonitor tm) throws Exception {
    final CyNode node = nodeView.getModel();
    final CyNetwork netPointer = node.getNetworkPointer();
    final CyNetworkManager netMgr = serviceRegistrar.getService(CyNetworkManager.class);
    if (netPointer != null && netMgr.networkExists(netPointer.getSUID())) {
        CyNetworkView pointerView = null;
        final CyNetworkViewManager netViewMgr = serviceRegistrar.getService(CyNetworkViewManager.class);
        Collection<CyNetworkView> views = netViewMgr.getNetworkViews(netPointer);
        for (CyNetworkView nv : views) {
            // Get the first view
            pointerView = nv;
            break;
        }
        if (pointerView == null) {
            // Create a network view
            final Set<CyNetwork> networks = new HashSet<CyNetwork>();
            networks.add(netPointer);
            final CreateNetworkViewTaskFactory createViewFactory = serviceRegistrar.getService(CreateNetworkViewTaskFactory.class);
            TaskIterator iter = createViewFactory.createTaskIterator(networks);
            this.insertTasksAfterCurrentTask(iter);
        } else {
            // Just set the existing one as current
            final CyApplicationManager appMgr = serviceRegistrar.getService(CyApplicationManager.class);
            appMgr.setCurrentNetworkView(pointerView);
        }
    }
}
Also used : CreateNetworkViewTaskFactory(org.cytoscape.task.create.CreateNetworkViewTaskFactory) CyApplicationManager(org.cytoscape.application.CyApplicationManager) CyNetworkManager(org.cytoscape.model.CyNetworkManager) TaskIterator(org.cytoscape.work.TaskIterator) CyNetworkViewManager(org.cytoscape.view.model.CyNetworkViewManager) CyNetwork(org.cytoscape.model.CyNetwork) CyNode(org.cytoscape.model.CyNode) CyNetworkView(org.cytoscape.view.model.CyNetworkView) HashSet(java.util.HashSet)

Aggregations

CyNetworkManager (org.cytoscape.model.CyNetworkManager)49 CyNetwork (org.cytoscape.model.CyNetwork)28 CyApplicationManager (org.cytoscape.application.CyApplicationManager)14 Test (org.junit.Test)14 CyNetworkViewManager (org.cytoscape.view.model.CyNetworkViewManager)12 CyNode (org.cytoscape.model.CyNode)9 ArrayList (java.util.ArrayList)8 CyGroupManager (org.cytoscape.group.CyGroupManager)8 CyNetworkFactory (org.cytoscape.model.CyNetworkFactory)8 CyRootNetworkManager (org.cytoscape.model.subnetwork.CyRootNetworkManager)7 CyNetworkViewFactory (org.cytoscape.view.model.CyNetworkViewFactory)7 VisualMappingManager (org.cytoscape.view.vizmap.VisualMappingManager)7 CyTableManager (org.cytoscape.model.CyTableManager)6 CyServiceRegistrar (org.cytoscape.service.util.CyServiceRegistrar)6 CyNetworkView (org.cytoscape.view.model.CyNetworkView)6 RenderingEngineManager (org.cytoscape.view.presentation.RenderingEngineManager)6 TaskIterator (org.cytoscape.work.TaskIterator)6 CyEventHelper (org.cytoscape.event.CyEventHelper)5 CyLayoutAlgorithmManager (org.cytoscape.view.layout.CyLayoutAlgorithmManager)5 UndoSupport (org.cytoscape.work.undo.UndoSupport)5