use of org.cytoscape.model.events.RemovedEdgesEvent 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.events.RemovedEdgesEvent in project cytoscape-impl by cytoscape.
the class CySubNetworkTest method testRemoveEdgeEvents.
@Test
public void testRemoveEdgeEvents() {
CySubNetwork sub = root.addSubNetwork();
CyNode nx1 = sub.addNode();
CyNode nx2 = sub.addNode();
CyNode nx3 = sub.addNode();
CyNode nx4 = sub.addNode();
CyEdge ex1 = sub.addEdge(nx1, nx2, true);
CyEdge ex2 = sub.addEdge(nx2, nx3, false);
CyEdge ex3 = sub.addEdge(nx3, nx4, true);
List<CyEdge> edges = new ArrayList<CyEdge>();
edges.add(ex1);
edges.add(ex2);
edges.add(ex3);
sub.removeEdges(edges);
int aboutToRemoveInd = -1;
int removedInd = -1;
int ind = 0;
for (Object event : deh.getAllLastEvents()) {
if (event instanceof AboutToRemoveEdgesEvent)
aboutToRemoveInd = ind;
else if (event instanceof RemovedEdgesEvent)
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