~fredericp/zaluum/rt

« back to all changes in this revision

Viewing changes to org.zaluum.boxes.fsm.editor/src/org/zaluum/boxes/fsm/editor/CreateTransitionCommand.java

  • Committer: Frederic Perez Ordeig
  • Date: 2010-04-07 07:55:38 UTC
  • mfrom: (308.1.63 wip-scala)
  • Revision ID: frederic@zaluum.com-20100407075538-muaneuoz134fqu5o
merged

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**
2
 
 *  This file is part of Zaluum
3
 
 *   
4
 
 *  Zaluum is free software: you can redistribute it and/or modify
5
 
 *  it under the terms of the GNU Lesser General Public License as published by
6
 
 *  the Free Software Foundation, either version 3 of the License, or
7
 
 *  (at your option) any later version.
8
 
 *
9
 
 *  Zaluum is distributed in the hope that it will be useful,
10
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 
 *  GNU Lesser General Public License for more details.
13
 
 *
14
 
 *  You should have received a copy of the GNU Lesser General Public License
15
 
 *  along with Zaluum.  If not, see <http://www.gnu.org/licenses/>.
16
 
 *  
17
 
 *  Copyright   2008,2009       Frederic Perez Ordeig
18
 
 *  Copyright   2008,2009       Elias Hortas Garcia
19
 
 */
20
 
package org.zaluum.boxes.fsm.editor;
21
 
 
22
 
import org.eclipse.gef.commands.Command;
23
 
import org.zaluum.model.basicbox.State;
24
 
import org.zaluum.model.basicbox.Transition;
25
 
 
26
 
/**
27
 
 * @author frede
28
 
 *
29
 
 */
30
 
public class CreateTransitionCommand extends Command {
31
 
 
32
 
        private State target;
33
 
        private final State source;
34
 
        private Transition trans;
35
 
 
36
 
        public CreateTransitionCommand(State stateModel) {
37
 
                this.source = stateModel;
38
 
        }
39
 
 
40
 
        public void setTarget(State stateModel) {
41
 
                this.target = stateModel;
42
 
                
43
 
        }
44
 
        public boolean canExecute() {
45
 
                return !source.equals(target);
46
 
        };
47
 
        @Override
48
 
        public void execute() {
49
 
                redo();
50
 
        }
51
 
        
52
 
        @Override
53
 
        public void redo() {
54
 
                trans = Transition.create(source,target);
55
 
        }
56
 
        
57
 
        @Override
58
 
        public void undo() {
59
 
                source.removeSourceTransition(trans);
60
 
                target.removeTargetTransition(trans);
61
 
        }
62
 
}