001    // GraphLab Project: http://graphlab.sharif.edu
002    // Copyright (C) 2008 Mathematical Science Department of Sharif University of Technology
003    // Distributed under the terms of the GNU General Public License (GPL): http://www.gnu.org/licenses/
004    package graphlab.plugins.main.core.actions.edge;
005    
006    import graphlab.graph.atributeset.GraphAttrSet;
007    import graphlab.graph.graph.EdgeModel;
008    import graphlab.graph.graph.GraphModel;
009    import graphlab.platform.core.AbstractAction;
010    import graphlab.platform.core.BlackBoard;
011    import graphlab.plugins.commonplugin.undo.Undoable;
012    import graphlab.plugins.commonplugin.undo.UndoableActionOccuredData;
013    
014    /**
015     * @author  Ruzbeh
016     */
017    public class DeleteEdge extends AbstractAction implements Undoable {
018        public DeleteEdge(BlackBoard bb) {
019            super(bb);
020            listen4Event(EdgeSelectData.EVENT_KEY);
021        }
022    
023        public void performAction(String eventName, Object value) {
024    //        GraphSelectPointData gpd = blackboard.getLog(GraphSelectPointData.name).getLast();
025    //        GraphModel graph = gpd.g;
026            EdgeSelectData esd = blackboard.getData(EdgeSelectData.EVENT_KEY);
027            GraphModel g = blackboard.getData(GraphAttrSet.name);
028    
029            EdgeModel e = esd.edge;
030            UndoableActionOccuredData uaod = new UndoableActionOccuredData(this);
031            uaod.properties.put("DeletedEdge", e);
032            uaod.properties.put("Graph", g);
033    
034            blackboard.setData(UndoableActionOccuredData.EVENT_KEY, uaod);
035            g.removeEdge(e);
036    
037    
038        }
039    
040        public void undo(UndoableActionOccuredData uaod) {
041            EdgeModel e = (EdgeModel) uaod.properties.get("DeletedEdge");
042            GraphModel g = (GraphModel) uaod.properties.get("Graph");
043            g.insertEdge(e);
044            uaod.properties.put("Done?", true);
045        }
046    
047        public void redo(UndoableActionOccuredData uaod) {
048            EdgeModel e = (EdgeModel) uaod.properties.get("DeletedEdge");
049            GraphModel g = (GraphModel) uaod.properties.get("Graph");
050            g.removeEdge(e);
051        }
052    }