Search in sources :

Example 46 with CySubNetwork

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);
}
Also used : CySubNetwork(org.cytoscape.model.subnetwork.CySubNetwork) CyRootNetwork(org.cytoscape.model.subnetwork.CyRootNetwork) Test(org.junit.Test)

Example 47 with CySubNetwork

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);
    });
}
Also used : CyNetworkViewManager(org.cytoscape.view.model.CyNetworkViewManager) ArrayList(java.util.ArrayList) CyNetwork(org.cytoscape.model.CyNetwork) CyApplicationManager(org.cytoscape.application.CyApplicationManager) CyNetworkManager(org.cytoscape.model.CyNetworkManager) SubNetworkPanel(org.cytoscape.internal.view.SubNetworkPanel) CyNetworkView(org.cytoscape.view.model.CyNetworkView) CySubNetwork(org.cytoscape.model.subnetwork.CySubNetwork)

Example 48 with CySubNetwork

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();
}
Also used : CyTable(org.cytoscape.model.CyTable) CyNetwork(org.cytoscape.model.CyNetwork) CyNode(org.cytoscape.model.CyNode) CyEdge(org.cytoscape.model.CyEdge) CySubNetwork(org.cytoscape.model.subnetwork.CySubNetwork)

Example 49 with CySubNetwork

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();
    }
}
Also used : CyTable(org.cytoscape.model.CyTable) CyNetwork(org.cytoscape.model.CyNetwork) CyNode(org.cytoscape.model.CyNode) CyEdge(org.cytoscape.model.CyEdge) CySubNetwork(org.cytoscape.model.subnetwork.CySubNetwork)

Example 50 with CySubNetwork

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();
}
Also used : CySubNetwork(org.cytoscape.model.subnetwork.CySubNetwork)

Aggregations

CySubNetwork (org.cytoscape.model.subnetwork.CySubNetwork)88 CyNode (org.cytoscape.model.CyNode)44 CyRootNetwork (org.cytoscape.model.subnetwork.CyRootNetwork)35 CyNetwork (org.cytoscape.model.CyNetwork)31 CyEdge (org.cytoscape.model.CyEdge)28 Test (org.junit.Test)19 CyRow (org.cytoscape.model.CyRow)15 ArrayList (java.util.ArrayList)12 CyTable (org.cytoscape.model.CyTable)11 CyNetworkView (org.cytoscape.view.model.CyNetworkView)11 HashSet (java.util.HashSet)7 CyGroup (org.cytoscape.group.CyGroup)7 HashMap (java.util.HashMap)6 CyNetworkManager (org.cytoscape.model.CyNetworkManager)6 CyApplicationManager (org.cytoscape.application.CyApplicationManager)5 CyEventHelper (org.cytoscape.event.CyEventHelper)5 CyNetworkViewManager (org.cytoscape.view.model.CyNetworkViewManager)5 Dimension (java.awt.Dimension)3 GroupCollapsedEvent (org.cytoscape.group.events.GroupCollapsedEvent)3 VisualStyle (org.cytoscape.view.vizmap.VisualStyle)3