use of org.cytoscape.model.CyNetworkManager in project cytoscape-impl by cytoscape.
the class NewNetworkSelectedNodesEdgesTaskFactoryTest 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);
NewNetworkSelectedNodesEdgesTaskFactoryImpl factory = new NewNetworkSelectedNodesEdgesTaskFactoryImpl(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 CloneNetworkTaskTest method runTest.
@Test
public void runTest() {
final CyNetworkManager netmgr = mock(CyNetworkManager.class);
final CyNetworkViewManager networkViewManager = mock(CyNetworkViewManager.class);
final CyNetworkViewFactory netViewFactory = mock(CyNetworkViewFactory.class);
final RenderingEngineManager reManager = mock(RenderingEngineManager.class);
final CyNetworkNaming naming = mock(CyNetworkNaming.class);
final TaskMonitor tm = mock(TaskMonitor.class);
}
use of org.cytoscape.model.CyNetworkManager in project cytoscape-impl by cytoscape.
the class CySessionManagerImpl method restoreNetworks.
private void restoreNetworks(final CySession sess) {
logger.debug("Restoring networks...");
Set<CyNetwork> networks = sess.getNetworks();
final CyNetworkManager netMgr = serviceRegistrar.getService(CyNetworkManager.class);
for (CyNetwork n : networks) {
netMgr.addNetwork(n, false);
}
}
use of org.cytoscape.model.CyNetworkManager in project cytoscape-impl by cytoscape.
the class CySessionManagerImpl method disposeCurrentSession.
@Override
public void disposeCurrentSession() {
logger.debug("Disposing current session...");
// Destroy network views
final CyNetworkViewManager nvMgr = serviceRegistrar.getService(CyNetworkViewManager.class);
final Set<CyNetworkView> netViews = nvMgr.getNetworkViewSet();
for (final CyNetworkView nv : netViews) nvMgr.destroyNetworkView(nv);
nvMgr.reset();
// Destroy networks
final CyNetworkManager netMgr = serviceRegistrar.getService(CyNetworkManager.class);
final Set<CyNetwork> networks = netMgr.getNetworkSet();
for (final CyNetwork n : networks) netMgr.destroyNetwork(n);
netMgr.reset();
// Destroy styles
logger.debug("Removing current visual styles...");
final VisualMappingManager vmMgr = serviceRegistrar.getService(VisualMappingManager.class);
final VisualStyle defaultStyle = vmMgr.getDefaultVisualStyle();
final List<VisualStyle> allStyles = new ArrayList<>(vmMgr.getAllVisualStyles());
for (final VisualStyle vs : allStyles) {
if (!vs.equals(defaultStyle))
vmMgr.removeVisualStyle(vs);
}
// Destroy tables
final CyTableManager tblMgr = serviceRegistrar.getService(CyTableManager.class);
tblMgr.reset();
// Reset groups
serviceRegistrar.getService(CyGroupManager.class).reset();
// Unregister session properties
final Set<CyProperty<?>> cyPropsClone = getAllProperties();
for (CyProperty<?> cyProps : cyPropsClone) {
if (cyProps.getSavePolicy().equals(CyProperty.SavePolicy.SESSION_FILE)) {
serviceRegistrar.unregisterAllServices(cyProps);
sessionProperties.remove(cyProps.getName());
}
}
// Clear undo stack
serviceRegistrar.getService(UndoSupport.class).reset();
// Reset current table and rendering engine
final CyApplicationManager appMgr = serviceRegistrar.getService(CyApplicationManager.class);
appMgr.reset();
currentFileName = null;
disposed = true;
}
use of org.cytoscape.model.CyNetworkManager in project cytoscape-impl by cytoscape.
the class CyNetworkNamingImpl method getSuggestedSubnetworkTitle.
@Override
public String getSuggestedSubnetworkTitle(final CyNetwork parentNetwork) {
String parentName = parentNetwork.getRow(parentNetwork).get(CyNetwork.NAME, String.class);
// capture just the digits
Pattern p = Pattern.compile(".*\\((\\d*)\\)$");
Matcher m = p.matcher(parentName);
int start = 0;
if (m.matches()) {
parentName = parentName.substring(0, m.start(1) - 1);
start = Integer.decode(m.group(1));
}
final CyNetworkManager netManager = serviceRegistrar.getService(CyNetworkManager.class);
for (int i = start; true; i++) {
final String nameCandidate = parentName + "(" + (i + 1) + ")";
if (!isNetworkTitleTaken(nameCandidate, netManager))
return nameCandidate;
}
}
Aggregations