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;
}
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;
}
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;
}
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());
}
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);
}
Aggregations