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.commonplugin.undo.undo; 005 /* 006 author :roozbeh 007 */ 008 009 import graphlab.platform.core.AbstractAction; 010 import graphlab.platform.core.BlackBoard; 011 import graphlab.plugins.commonplugin.undo.UndoableActionOccuredData; 012 import graphlab.ui.UIUtils; 013 014 public class UndoAction extends AbstractAction { 015 016 public static final String EVENT_KEY = UIUtils.getUIEventKey("Undo Action"); 017 018 019 public UndoAction(BlackBoard bb) { 020 super(bb); 021 listen4Event(EVENT_KEY); 022 blackboard.setData(UndoLogManager.EVENT_KEY, new UndoLogManager(bb)); 023 } 024 025 /** 026 * performs the undo operation for basic actions 027 */ 028 public static void undo(UndoableActionOccuredData uaod) { 029 uaod.undoableAction.undo(uaod); 030 031 } 032 033 public void performAction(String eventName, Object value) { 034 undo(blackboard); 035 } 036 037 /** 038 * undo the last undoabe operation done in the context of current blackboard 039 * 040 * @param blackboard 041 */ 042 public static void undo(BlackBoard blackboard) { 043 UndoLogManager logManager = blackboard.getData(UndoLogManager.EVENT_KEY); 044 UndoableActionOccuredData uaod = logManager.getNextUndoData(); 045 if (uaod != null) 046 undo(uaod); 047 } 048 049 }