use of org.cytoscape.model.events.RemovedNodesEvent 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.events.RemovedNodesEvent in project cytoscape-impl by cytoscape.
the class CySubNetworkTest method testRemoveNodeEvents.
//
// A bunch of tests to validate that the proper events are fired
//
@Test
public void testRemoveNodeEvents() {
CySubNetwork sub = root.addSubNetwork();
CyNode nx1 = sub.addNode();
CyNode nx2 = sub.addNode();
CyNode nx3 = sub.addNode();
CyNode nx4 = sub.addNode();
List<CyNode> nodes = new ArrayList<CyNode>();
nodes.add(nx1);
nodes.add(nx2);
nodes.add(nx3);
nodes.add(nx4);
sub.removeNodes(nodes);
int aboutToRemoveInd = -1;
int removedInd = -1;
int ind = 0;
for (Object event : deh.getAllLastEvents()) {
if (event instanceof AboutToRemoveNodesEvent)
aboutToRemoveInd = ind;
else if (event instanceof RemovedNodesEvent)
removedInd = ind;
ind++;
}
// verify that we found the events in the list
assertTrue(aboutToRemoveInd >= 0);
assertTrue(removedInd >= 0);
// verify that the about to remove event came first
assertTrue(aboutToRemoveInd < removedInd);
}
Aggregations