use of org.cytoscape.model.subnetwork.CyRootNetworkManager in project cytoscape-impl by cytoscape.
the class ReadDataManager method createRootNetwork.
protected CyRootNetwork createRootNetwork() {
if (this.rootNetwork != null)
return this.rootNetwork;
final CyNetworkFactory networkFactory = serviceRegistrar.getService(CyNetworkFactory.class);
final CyNetwork baseNet = networkFactory.createNetwork();
final CyRootNetworkManager rootNetworkManager = serviceRegistrar.getService(CyRootNetworkManager.class);
final CyRootNetwork rootNetwork = rootNetworkManager.getRootNetwork(baseNet);
return rootNetwork;
}
use of org.cytoscape.model.subnetwork.CyRootNetworkManager in project cytoscape-impl by cytoscape.
the class CySessionManagerImpl method restoreTables.
private void restoreTables(final CySession sess) {
final Set<CyTable> allTables = new HashSet<>();
// Register all tables sent through the CySession, if not already registered
for (final CyTableMetadata metadata : sess.getTables()) {
allTables.add(metadata.getTable());
}
// There may be other network tables in the CyNetworkTableManager that were not serialized in the session file
// (e.g. Table Facades), so it's necessary to add them to CyTableManager as well
final CyNetworkTableManager netTblMgr = serviceRegistrar.getService(CyNetworkTableManager.class);
final CyRootNetworkManager rootNetMgr = serviceRegistrar.getService(CyRootNetworkManager.class);
for (final CyNetwork net : sess.getNetworks()) {
allTables.addAll(netTblMgr.getTables(net, CyNetwork.class).values());
allTables.addAll(netTblMgr.getTables(net, CyNode.class).values());
allTables.addAll(netTblMgr.getTables(net, CyEdge.class).values());
if (!(net instanceof CyRootNetwork)) {
final CyRootNetwork root = rootNetMgr.getRootNetwork(net);
allTables.addAll(netTblMgr.getTables(root, CyNetwork.class).values());
allTables.addAll(netTblMgr.getTables(root, CyNode.class).values());
allTables.addAll(netTblMgr.getTables(root, CyEdge.class).values());
}
}
// Register all tables sent through the CySession, if not already registered
final CyTableManager tblMgr = serviceRegistrar.getService(CyTableManager.class);
for (final CyTable tbl : allTables) {
if (tblMgr.getTable(tbl.getSUID()) == null)
tblMgr.addTable(tbl);
}
}
use of org.cytoscape.model.subnetwork.CyRootNetworkManager in project cytoscape-impl by cytoscape.
the class NetworkCollectionHelper method init.
void init() {
final CyApplicationManager appMgr = serviceRegistrar.getService(CyApplicationManager.class);
final CyRootNetworkManager rootNetMgr = serviceRegistrar.getService(CyRootNetworkManager.class);
// initialize the network Collection
name2RootMap = getRootNetworkMap();
final List<String> rootNames = new ArrayList<>();
rootNames.addAll(name2RootMap.keySet());
if (!rootNames.isEmpty()) {
sort(rootNames);
rootNames.add(0, CREATE_NEW_COLLECTION_STRING);
}
rootNetworkList = new ListSingleSelection<>(rootNames);
final CyNetwork net = appMgr != null ? appMgr.getCurrentNetwork() : null;
final CyRootNetwork rootNet = net != null ? rootNetMgr.getRootNetwork(net) : null;
final String rootNetName = rootNet != null ? rootNet.getRow(rootNet).get(CyRootNetwork.NAME, String.class) : CREATE_NEW_COLLECTION_STRING;
if (rootNames.contains(rootNetName))
rootNetworkList.setSelectedValue(rootNetName);
else if (rootNames.contains(CREATE_NEW_COLLECTION_STRING))
rootNetworkList.setSelectedValue(CREATE_NEW_COLLECTION_STRING);
if (rootNet != null)
targetColumnList = getTargetColumns(rootNet);
else
targetColumnList = new ListSingleSelection<>();
// initialize renderer list
final List<NetworkViewRenderer> renderers = new ArrayList<>();
final Set<NetworkViewRenderer> rendererSet = appMgr.getNetworkViewRendererSet();
// so the combo-box does not appear to the user, since there is nothing to select anyway.
if (rendererSet.size() > 1) {
renderers.addAll(rendererSet);
Collections.sort(renderers, new Comparator<NetworkViewRenderer>() {
@Override
public int compare(NetworkViewRenderer r1, NetworkViewRenderer r2) {
return r1.toString().compareToIgnoreCase(r2.toString());
}
});
}
rendererList = new ListSingleSelection<>(renderers);
final NetworkViewRenderer defViewRenderer = appMgr.getDefaultNetworkViewRenderer();
if (defViewRenderer != null && renderers.contains(defViewRenderer))
rendererList.setSelectedValue(defViewRenderer);
}
use of org.cytoscape.model.subnetwork.CyRootNetworkManager in project cytoscape-impl by cytoscape.
the class NetworkCollectionHelper method getRootNetworkMap.
private HashMap<String, CyRootNetwork> getRootNetworkMap() {
final HashMap<String, CyRootNetwork> name2RootMap = new HashMap<>();
final Set<CyNetwork> networkSet = serviceRegistrar.getService(CyNetworkManager.class).getNetworkSet();
final CyRootNetworkManager rootNetworkManager = serviceRegistrar.getService(CyRootNetworkManager.class);
for (CyNetwork net : networkSet) {
final CyRootNetwork rootNet = rootNetworkManager.getRootNetwork(net);
if (!name2RootMap.containsValue(rootNet))
name2RootMap.put(rootNet.getRow(rootNet).get(CyRootNetwork.NAME, String.class), rootNet);
}
return name2RootMap;
}
use of org.cytoscape.model.subnetwork.CyRootNetworkManager 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));
}
Aggregations