OW2 Consortium orchestra

Rev

Rev 6512 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
6547 albertil 1
/**
2
 * Bull SAS / OW2 Orchestra
3
 * Copyright (C) 2010 Bull S.A.S, and individual contributors as indicated
4
 * by the @authors tag.
5
 *
6
 * This library is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU Lesser General Public
8
 * License as published by the Free Software Foundation; either
9
 * version 2.1 of the License, or any later version.
10
 *
11
 * This library is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
 * Lesser General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Lesser General Public
17
 * License along with this library; if not, write to the Free Software
18
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
19
 * USA
20
 */
21
package org.ow2.orchestra.designer.model {
22
import mx.collections.ArrayCollection;
23
 
24
import org.ow2.orchestra.designer.bpmn.model.ProcessModel;
25
import org.ow2.orchestra.designer.utils.DesignerUtil;
26
import org.ow2.orchestra.designer.vo.FileNavigatorProcess;
27
 
28
[Bindable]
29
public class ProcessEditorModel {
30
 
31
  //Path of the file on the server to store the process
32
  private var _fileNavigatorProcess:FileNavigatorProcess;
33
 
34
  //indicate if the process is editing in writing or no, by default true;
35
  private var _readWrite:Boolean;
36
 
37
  // Elements currently selected
38
  private var _selectedElements:ArrayCollection = new ArrayCollection();
39
 
40
  private var _processModel:ProcessModel;
41
 
42
  // For undo redo
43
  // Number of undo/redo elements to keep in memory
44
  private static const UNDO_REDO_QUEUE_LENGTH:int = 10;
45
  private var _undoState:ArrayCollection = new ArrayCollection();
46
  private var _redoState:ArrayCollection = new ArrayCollection();
47
 
48
 
49
  public function ProcessEditorModel() {
50
    _processModel = new ProcessModel();
51
    _readWrite = true;
52
  }
53
 
54
 
55
  public function get selectedElements():ArrayCollection {
56
    return _selectedElements;
57
  }
58
 
59
  public function set selectedElements(value:ArrayCollection):void {
60
    _selectedElements = value;
61
  }
62
 
63
  public function get processModel():ProcessModel {
64
    return _processModel;
65
  }
66
 
67
  public function set processModel(value:ProcessModel):void {
68
    _processModel = value;
69
    _selectedElements.removeAll();
70
  }
71
 
72
  public function get fileNavigatorProcess():FileNavigatorProcess {
73
    return DesignerModelLocator.getInstance().fileNavigatorModel.getProcess(_fileNavigatorProcess);
74
  }
75
 
76
  public function set fileNavigatorProcess(value:FileNavigatorProcess):void {
77
    _fileNavigatorProcess = value;
78
  }
79
 
80
  public function saveModelForUndo():void {
81
    _undoState.addItem(ProcessModel(DesignerUtil.copy(processModel)));
82
    if (_undoState.length > UNDO_REDO_QUEUE_LENGTH) {
83
      // undo max length is reached, remove the oldest process state
84
      _undoState.removeItemAt(0);
85
    }
86
    _redoState.removeAll();
87
  }
88
 
89
  public function undo():void {
90
    trace("Undo..");
91
    if (_undoState.length != 0) {
92
      _redoState.addItem(ProcessModel(DesignerUtil.copy(processModel)));
93
      processModel = ProcessModel(_undoState.removeItemAt(_undoState.length - 1));
94
      trace("Undo done");
95
    }
96
  }
97
 
98
  public function redo():void {
99
    if (_redoState.length != 0) {
100
      _undoState.addItem(ProcessModel(DesignerUtil.copy(processModel)));
101
      processModel = ProcessModel(_redoState.removeItemAt(_redoState.length - 1));
102
    }
103
  }
104
 
105
  public function set readWrite(readWrite:Boolean):void {
106
    _readWrite = readWrite;
107
  }
108
 
109
  public function get readWrite():Boolean {
110
    return _readWrite;
111
  }
112
}
113
}