use of org.cytoscape.model.subnetwork.CySubNetwork in project cytoscape-impl by cytoscape.
the class CyNetworkAutoDeleteTest method testAutoDeleteWhenSubnetworkIsDeleted.
@Test
public void testAutoDeleteWhenSubnetworkIsDeleted() {
CyNetwork network1 = TestCyNetworkFactory.getInstance();
CyRootNetwork rootNetwork = ((CySubNetwork) network1).getRootNetwork();
CyNode n1 = network1.addNode();
CyNode n2 = network1.addNode();
CyNode n3 = network1.addNode();
CyEdge e1 = network1.addEdge(n1, n2, false);
CyEdge e2 = network1.addEdge(n2, n3, false);
CyNetwork network2 = rootNetwork.addSubNetwork(Arrays.asList(n1, n2), Arrays.asList(e1));
rootNetwork.removeSubNetwork((CySubNetwork) network1);
assertFalse(rootNetwork.containsNode(n3));
assertFalse(network2.containsNode(n3));
assertFalse(rootNetwork.containsEdge(e2));
assertFalse(network2.containsEdge(e2));
assertNull(rootNetwork.getNode(n3.getSUID()));
assertNull(network2.getNode(n3.getSUID()));
rowExists(false, rootNetwork, n3);
rowExists(false, rootNetwork, e2);
}
use of org.cytoscape.model.subnetwork.CySubNetwork in project cytoscape-impl by cytoscape.
the class SessionHandler method setSessionNetworks.
/**
* @param netOrder Maps CyNetwork SUID to the network position
*/
private void setSessionNetworks(final Map<Long, Integer> netOrder) {
final CyNetworkManager netMgr = serviceRegistrar.getService(CyNetworkManager.class);
final List<CySubNetwork> sortedNetworks = new ArrayList<>();
for (CyNetwork n : netMgr.getNetworkSet()) {
if (n instanceof CySubNetwork && netMgr.networkExists(n.getSUID()))
sortedNetworks.add((CySubNetwork) n);
}
Collections.sort(sortedNetworks, new Comparator<CySubNetwork>() {
@Override
public int compare(final CySubNetwork n1, final CySubNetwork n2) {
try {
Integer o1 = netOrder.get(n1.getSUID());
Integer o2 = netOrder.get(n2.getSUID());
if (o1 == null)
o1 = -1;
if (o2 == null)
o2 = -1;
return o1.compareTo(o2);
} catch (final Exception e) {
logger.error("Cannot sort networks", e);
}
return 0;
}
});
final CyApplicationManager applicationMgr = serviceRegistrar.getService(CyApplicationManager.class);
final CyNetworkViewManager netViewMgr = serviceRegistrar.getService(CyNetworkViewManager.class);
final List<CyNetwork> selectedNetworks = applicationMgr.getSelectedNetworks();
final List<CyNetworkView> selectedViews = applicationMgr.getSelectedNetworkViews();
invokeOnEDT(() -> {
netPanel.setNetworks(sortedNetworks);
for (SubNetworkPanel snp : netPanel.getAllSubNetworkItems()) {
final int count = netViewMgr.getNetworkViews(snp.getModel().getNetwork()).size();
snp.getModel().setViewCount(count);
}
netPanel.setSelectedNetworks(selectedNetworks);
netViewMediator.getNetworkViewMainPanel().setSelectedNetworkViews(selectedViews);
});
}
use of org.cytoscape.model.subnetwork.CySubNetwork in project cytoscape-impl by cytoscape.
the class CyRootNetworkImpl method dispose.
@Override
public void dispose() {
Map<String, CyTable> tableMap;
serviceRegistrar.unregisterAllServices(columnAdder);
serviceRegistrar.unregisterAllServices(nameSetListener);
serviceRegistrar.unregisterAllServices(interactionSetListener);
serviceRegistrar.unregisterAllServices(networkAddedListenerDelegator);
serviceRegistrar.unregisterAllServices(networkNameSetListener);
serviceRegistrar.unregisterService(this, SessionLoadedListener.class);
for (CySubNetwork network : subNetworks) {
network.dispose();
}
tableMap = networkTableMgr.getTables(this, CyNetwork.class);
for (CyTable table : tableMap.values()) {
tableMgr.deleteTableInternal(table.getSUID(), true);
}
tableMap = networkTableMgr.getTables(this, CyNode.class);
for (CyTable table : tableMap.values()) {
tableMgr.deleteTableInternal(table.getSUID(), true);
}
tableMap = networkTableMgr.getTables(this, CyEdge.class);
for (CyTable table : tableMap.values()) {
tableMgr.deleteTableInternal(table.getSUID(), true);
}
networkTableMgr.removeAllTables(this);
removedAttributesCache.dispose();
}
use of org.cytoscape.model.subnetwork.CySubNetwork in project cytoscape-impl by cytoscape.
the class CyRootNetworkImpl method removeSubNetwork.
@Override
public void removeSubNetwork(final CySubNetwork sub) {
synchronized (lock) {
if (sub == null)
return;
if (!subNetworks.contains(sub))
throw new IllegalArgumentException("Subnetwork not a member of this RootNetwork " + sub);
if (sub.equals(base)) {
if (subNetworks.size() == 1)
throw new IllegalArgumentException("Can't remove base network from RootNetwork because it's the only subnetwork");
// Chose another base network
CySubNetwork oldBase = base;
for (CySubNetwork n : subNetworks) {
if (!n.equals(oldBase)) {
base = n;
// Better if the new base network is one that can be saved
if (n.getSavePolicy() == SavePolicy.SESSION_FILE)
break;
}
}
}
// clean up pointers for nodes in subnetwork
sub.removeNodes(sub.getNodeList());
Map<String, CyTable> tableMap;
tableMap = networkTableMgr.getTables(sub, CyNetwork.class);
for (CyTable table : tableMap.values()) {
tableMgr.deleteTableInternal(table.getSUID(), true);
}
tableMap = networkTableMgr.getTables(sub, CyNode.class);
for (CyTable table : tableMap.values()) {
tableMgr.deleteTableInternal(table.getSUID(), true);
}
tableMap = networkTableMgr.getTables(sub, CyEdge.class);
for (CyTable table : tableMap.values()) {
tableMgr.deleteTableInternal(table.getSUID(), true);
}
subNetworks.remove(sub);
sub.dispose();
garbageCollect();
}
}
use of org.cytoscape.model.subnetwork.CySubNetwork in project cytoscape-impl by cytoscape.
the class NetworkMainPanel method setNetworks.
/**
* Replace the current network list with the passed ones.
*/
public void setNetworks(final Collection<CySubNetwork> networks) {
clear();
ignoreSelectionEvents = true;
doNotUpdateCollapseExpandButtons = true;
try {
for (final CySubNetwork n : networks) addNetwork((CySubNetwork) n);
} finally {
doNotUpdateCollapseExpandButtons = false;
ignoreSelectionEvents = false;
}
getRootNetworkListPanel().update();
updateNetworkHeader();
updateNodeEdgeCount();
}
Aggregations