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