Search in sources :

Example 1 with NetworkAboutToBeDestroyedEvent

use of org.cytoscape.model.events.NetworkAboutToBeDestroyedEvent 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));
}
Also used : NetworkDestroyedEvent(org.cytoscape.model.events.NetworkDestroyedEvent) CyEventHelper(org.cytoscape.event.CyEventHelper) NetworkAboutToBeDestroyedEvent(org.cytoscape.model.events.NetworkAboutToBeDestroyedEvent) CyNode(org.cytoscape.model.CyNode) CyEdge(org.cytoscape.model.CyEdge) CySubNetwork(org.cytoscape.model.subnetwork.CySubNetwork) CyRootNetwork(org.cytoscape.model.subnetwork.CyRootNetwork)

Aggregations

CyEventHelper (org.cytoscape.event.CyEventHelper)1 CyEdge (org.cytoscape.model.CyEdge)1 CyNode (org.cytoscape.model.CyNode)1 NetworkAboutToBeDestroyedEvent (org.cytoscape.model.events.NetworkAboutToBeDestroyedEvent)1 NetworkDestroyedEvent (org.cytoscape.model.events.NetworkDestroyedEvent)1 CyRootNetwork (org.cytoscape.model.subnetwork.CyRootNetwork)1 CySubNetwork (org.cytoscape.model.subnetwork.CySubNetwork)1