use of org.cytoscape.model.events.NetworkDestroyedEvent in project cytoscape-impl by cytoscape.
the class CyNetworkManagerImpl method destroyNetwork.
@Override
public void destroyNetwork(final CyNetwork network) {
if (network == null)
throw new NullPointerException("Network is null");
final Long networkId = network.getSUID();
synchronized (lock) {
if (!networkMap.containsKey(networkId))
throw new IllegalArgumentException("network is not recognized by this NetworkManager");
}
final CyEventHelper cyEventHelper = serviceRegistrar.getService(CyEventHelper.class);
// let everyone know!
cyEventHelper.fireEvent(new NetworkAboutToBeDestroyedEvent(CyNetworkManagerImpl.this, network));
synchronized (lock) {
// check again within the lock in case something has changed
if (!networkMap.containsKey(networkId))
throw new IllegalArgumentException("network is not recognized by this NetworkManager");
for (CyNode n : network.getNodeList()) network.getRow(n).set(CyNetwork.SELECTED, false);
for (CyEdge e : network.getEdgeList()) network.getRow(e).set(CyNetwork.SELECTED, false);
networkMap.remove(networkId);
}
if (network instanceof CySubNetwork) {
final CySubNetwork subNetwork = (CySubNetwork) network;
final CyRootNetwork rootNetwork = subNetwork.getRootNetwork();
final CySubNetwork baseNetwork = rootNetwork.getBaseNetwork();
if (!subNetwork.equals(baseNetwork) || rootNetwork.getSubNetworkList().size() > 1) {
rootNetwork.removeSubNetwork(subNetwork);
network.dispose();
}
if (!hasRegisteredNetworks(rootNetwork))
rootNetwork.dispose();
} else {
network.dispose();
}
// let everyone know that some network is gone
cyEventHelper.fireEvent(new NetworkDestroyedEvent(CyNetworkManagerImpl.this));
}
Aggregations