Search in sources :

Example 61 with CyEdge

use of org.cytoscape.model.CyEdge in project cytoscape-impl by cytoscape.

the class CySubNetworkImpl method addEdge.

@Override
public CyEdge addEdge(final CyNode source, final CyNode target, final boolean isDirected) {
    // important that it's edgeAdd and not addEdge
    final CyEdge ret;
    synchronized (this) {
        // first add an edge to the root network
        ret = parent.addEdge(source, target, isDirected);
        // then add the resulting CyEdge to this network
        addEdgeInternal(source, target, isDirected, ret);
        getRow(ret).set(CyNetwork.SELECTED, false);
    }
    if (fireAddedNodesAndEdgesEvents)
        eventHelper.addEventPayload((CyNetwork) this, ret, AddedEdgesEvent.class);
    return ret;
}
Also used : CyNetwork(org.cytoscape.model.CyNetwork) CyEdge(org.cytoscape.model.CyEdge) AddedEdgesEvent(org.cytoscape.model.events.AddedEdgesEvent)

Example 62 with CyEdge

use of org.cytoscape.model.CyEdge in project cytoscape-impl by cytoscape.

the class CySubNetworkImpl method removeEdges.

@Override
public boolean removeEdges(final Collection<CyEdge> edges) {
    if (edges == null || edges.isEmpty())
        return false;
    // Possible error if one of the edges isn't contained in subnetwork, but
    // since this is only a notification, maybe that's OK.
    eventHelper.fireEvent(new AboutToRemoveEdgesEvent(this, edges));
    CyTable hiddenTable = getTable(CyEdge.class, CyNetwork.HIDDEN_ATTRS);
    CyTable localTable = getTable(CyEdge.class, CyNetwork.LOCAL_ATTRS);
    CyTable defaultTable = getTable(CyEdge.class, CyNetwork.DEFAULT_ATTRS);
    List<Long> suids = new ArrayList<>();
    for (CyEdge edge : edges) {
        if (containsEdge(edge)) {
            // getRow(edge).set(CyNetwork.SELECTED, false);
            suids.add(edge.getSUID());
        }
    }
    boolean ret = removeEdgesInternal(edges);
    hiddenTable.deleteRows(suids);
    defaultTable.deleteRows(suids);
    if (ret) {
        parent.subnetworkEdgesRemoved(edges);
    }
    if (ret) {
        eventHelper.fireEvent(new RemovedEdgesEvent(this));
    }
    return ret;
}
Also used : CyTable(org.cytoscape.model.CyTable) RemovedEdgesEvent(org.cytoscape.model.events.RemovedEdgesEvent) AboutToRemoveEdgesEvent(org.cytoscape.model.events.AboutToRemoveEdgesEvent) ArrayList(java.util.ArrayList) CyEdge(org.cytoscape.model.CyEdge)

Example 63 with CyEdge

use of org.cytoscape.model.CyEdge in project cytoscape-impl by cytoscape.

the class CySubNetworkImpl method removeNodes.

@Override
public boolean removeNodes(final Collection<CyNode> nodes) {
    if (nodes == null || nodes.isEmpty())
        return false;
    eventHelper.fireEvent(new AboutToRemoveNodesEvent(this, nodes));
    CyTable nodeHiddenTable = getTable(CyNode.class, CyNetwork.HIDDEN_ATTRS);
    CyTable nodeDefaultTable = getTable(CyNode.class, CyNetwork.DEFAULT_ATTRS);
    CyTable edgeHiddenTable = getTable(CyEdge.class, CyNetwork.HIDDEN_ATTRS);
    CyTable edgeDefaultTable = getTable(CyEdge.class, CyNetwork.DEFAULT_ATTRS);
    List<Long> nodeSuids = new ArrayList<>();
    Set<Long> edgeSuids = new HashSet<>();
    for (CyNode node : nodes) {
        if (this.containsNode(node)) {
            Long nodeSuid = node.getSUID();
            if (nodeDefaultTable.rowExists(nodeSuid))
                nodeSuids.add(nodeSuid);
            for (CyEdge edge : getAdjacentEdgeIterable(node, Type.ANY)) {
                Long edgeSuid = edge.getSUID();
                if (edgeDefaultTable.rowExists(edgeSuid)) {
                    edgeSuids.add(edgeSuid);
                }
            }
        }
    }
    boolean ret = removeNodesInternal(nodes);
    nodeHiddenTable.deleteRows(nodeSuids);
    nodeDefaultTable.deleteRows(nodeSuids);
    edgeHiddenTable.deleteRows(edgeSuids);
    edgeDefaultTable.deleteRows(edgeSuids);
    if (ret) {
        parent.subnetworkNodesRemoved(nodes);
    }
    if (ret) {
        eventHelper.fireEvent(new RemovedNodesEvent(this));
    }
    return ret;
}
Also used : CyTable(org.cytoscape.model.CyTable) ArrayList(java.util.ArrayList) CyNode(org.cytoscape.model.CyNode) RemovedNodesEvent(org.cytoscape.model.events.RemovedNodesEvent) CyEdge(org.cytoscape.model.CyEdge) AboutToRemoveNodesEvent(org.cytoscape.model.events.AboutToRemoveNodesEvent) HashSet(java.util.HashSet)

Example 64 with CyEdge

use of org.cytoscape.model.CyEdge in project cytoscape-impl by cytoscape.

the class DefaultTablesNetwork method getRow.

public CyRow getRow(final CyIdentifiable entry, final String tableName) {
    if (entry == null)
        throw new NullPointerException("null entry");
    if (tableName == null)
        throw new NullPointerException("null table name");
    CyTable table;
    // The table returned should be immutable.
    if (entry instanceof CyNode && containsNode((CyNode) entry))
        table = networkTableManager.getTable(networkRef.get(), CyNode.class, tableName);
    else if (entry instanceof CyEdge && containsEdge((CyEdge) entry))
        table = networkTableManager.getTable(networkRef.get(), CyEdge.class, tableName);
    else if (entry instanceof CyNetwork && entry.equals(this)) {
        if (networkRef == null)
            throw new IllegalArgumentException("Network reference is null.  This should not be null.");
        final CyNetwork n = networkRef.get();
        table = networkTableManager.getTable(n, CyNetwork.class, tableName);
    } else
        throw new IllegalArgumentException("unrecognized (table entry): " + entry.toString() + "  (table name): " + tableName);
    if (table == null)
        throw new NullPointerException("Table does not exist: " + tableName);
    return table.getRow(entry.getSUID());
}
Also used : CyTable(org.cytoscape.model.CyTable) CyNetwork(org.cytoscape.model.CyNetwork) CyNode(org.cytoscape.model.CyNode) CyEdge(org.cytoscape.model.CyEdge)

Example 65 with CyEdge

use of org.cytoscape.model.CyEdge in project cytoscape-impl by cytoscape.

the class CySubNetworkTest method testAddExistingEdgeEventBeforeNetworkAdd.

@Test
public void testAddExistingEdgeEventBeforeNetworkAdd() {
    CyNode nx1 = root.addNode();
    CyNode nx2 = root.addNode();
    CyEdge ex1 = root.addEdge(nx1, nx2, false);
    CySubNetwork sub = root.addSubNetwork();
    sub.addNode(nx1);
    sub.addNode(nx2);
    sub.addEdge(ex1);
    Object payload = deh.getLastPayload();
    assertNull(payload);
}
Also used : CyNode(org.cytoscape.model.CyNode) CyEdge(org.cytoscape.model.CyEdge) Test(org.junit.Test)

Aggregations

CyEdge (org.cytoscape.model.CyEdge)302 CyNode (org.cytoscape.model.CyNode)231 CyNetwork (org.cytoscape.model.CyNetwork)103 ArrayList (java.util.ArrayList)77 Test (org.junit.Test)71 CyNetworkView (org.cytoscape.view.model.CyNetworkView)55 HashSet (java.util.HashSet)42 CyRow (org.cytoscape.model.CyRow)41 CyIdentifiable (org.cytoscape.model.CyIdentifiable)29 HashMap (java.util.HashMap)26 CySubNetwork (org.cytoscape.model.subnetwork.CySubNetwork)25 CyTable (org.cytoscape.model.CyTable)21 DummyCyEdge (org.cytoscape.model.DummyCyEdge)21 VisualStyle (org.cytoscape.view.vizmap.VisualStyle)18 DummyCyNode (org.cytoscape.model.DummyCyNode)17 View (org.cytoscape.view.model.View)16 List (java.util.List)13 CyEventHelper (org.cytoscape.event.CyEventHelper)12 CyGroup (org.cytoscape.group.CyGroup)12 VisualMappingManager (org.cytoscape.view.vizmap.VisualMappingManager)12