Search in sources :

Example 1 with RemovedEdgesEvent

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;
}
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 2 with RemovedEdgesEvent

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);
}
Also used : RemovedEdgesEvent(org.cytoscape.model.events.RemovedEdgesEvent) ArrayList(java.util.ArrayList) AboutToRemoveEdgesEvent(org.cytoscape.model.events.AboutToRemoveEdgesEvent) CyNode(org.cytoscape.model.CyNode) CyEdge(org.cytoscape.model.CyEdge) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)2 CyEdge (org.cytoscape.model.CyEdge)2 AboutToRemoveEdgesEvent (org.cytoscape.model.events.AboutToRemoveEdgesEvent)2 RemovedEdgesEvent (org.cytoscape.model.events.RemovedEdgesEvent)2 CyNode (org.cytoscape.model.CyNode)1 CyTable (org.cytoscape.model.CyTable)1 Test (org.junit.Test)1