1 /**
  2  * Object that is used to undo actions when figures/connectors are created
  3  * @this {CreateCommand} 
  4  * @constructor
  5  * @param property {Null}
  6  * @param previousValue {Number} the figure/connector ID to delete
  7  * @param currentValue {Array} [createFigureFunction,Event]
  8  */
  9 function CreateCommand(objectId, typeOfObject, property, previousValue, currentValue){
 10     this.objectId = objectId;
 11     this.typeOfObject = typeOfObject;
 12     this.property = property;
 13     this.previousValue = previousValue;
 14     this.currentValue = currentValue;
 15     this.oType = "Create Action";
 16 }
 17 
 18 CreateCommand.prototype = {
 19     /**This method got called every time the Command must execute*/
 20     redo : function(){
 21         this._doAction(this.currentValue);
 22     },
 23     
 24     
 25     /**This method should be called every time the Command should be undone*/
 26     undo : function(){
 27         this._doAction(this.previousValue);
 28     },
 29     
 30     _doAction:function(value){
 31         if(this.typeOfObject == History.OBJECT_FIGURE){
 32             if(value instanceof Array){//we are redoing
 33                 createFigureFunction = value[0];
 34                 state = STATE_FIGURE_CREATE;
 35                 value[1].noAddUndo = true;
 36                 onMouseDown(value[1]);
 37                 stack.figureGetById(selectedFigureId).figureId = this.objectId;
 38                 stack.figureGetById(selectedFigureId).id = this.objectId;
 39                 selectedFigureId = this.objectId;
 40             }
 41             else {
 42                 stack.figureRemoveById(value);
 43                 selectedFigureId = -1;
 44                 state = STATE_NONE;
 45             }
 46         }
 47         else if(this.typeOfObject == History.OBJECT_CONNECTOR){
 48             if(value instanceof Array){//we are redoing
 49                 state = STATE_CONNECTOR_PICK_FIRST;
 50                 connectorType = this.property;
 51                 value[0].noAddUndo = true;
 52                 onMouseDown(value[0]);
 53                 var con = CONNECTOR_MANAGER.connectorGetById(selectedConnectorId);
 54                 state = STATE_CONNECTOR_PICK_SECOND;
 55                 value[1].noAddUndo = true;
 56                 onMouseUp(value[1]);
 57                 con.id = this.objectId;
 58                 var conPoints = CONNECTOR_MANAGER.connectionPointGetAllByParent(selectedConnectorId);
 59                 for(var i = 0; i < conPoints.length; i++){
 60                     conPoints[i].parentId = this.objectId;
 61                 }
 62                 for(var i = 0; i < History.COMMANDS.length; i++){
 63                     if(History.COMMANDS[i].typeOfObject == History.OBJECT_CONNECTION_POINT){
 64                         if(History.COMMANDS[i].property.equals(con.turningPoints[0])){
 65                             var cps = CONNECTOR_MANAGER.connectionPointGetAllByParent(this.objectId);
 66                             History.COMMANDS[i].objectId = cps[0].id;
 67                         }
 68                         else if(History.COMMANDS[i].property.equals(con.turningPoints[con.turningPoints.length - 1])){
 69                             var cps = CONNECTOR_MANAGER.connectionPointGetAllByParent(this.objectId);
 70                             History.COMMANDS[i].objectId = cps[cps.length - 1].id;
 71                         }
 72                     }
 73                 }
 74                 con.id = this.objectId;
 75                 selectedConnectorId = this.objectId;
 76                 state = STATE_CONNECTOR_SELECTED;
 77             }
 78             else
 79             {
 80                 //CONNECTOR_MANAGER.connectionPointRemoveAllByParent(this.objectId)
 81                 CONNECTOR_MANAGER.connectorRemoveById(this.objectId);
 82                 selectedConnectorId = -1;
 83                 state = STATE_NONE;
 84             }
 85         }
 86     }
 87 }