1 package cz.cuni.amis.pogamut.sposh.elements;
2
3 import cz.cuni.amis.pogamut.sposh.exceptions.CycleException;
4 import cz.cuni.amis.pogamut.sposh.exceptions.DuplicateNameException;
5 import cz.cuni.amis.pogamut.sposh.exceptions.FubarException;
6 import cz.cuni.amis.pogamut.sposh.exceptions.InvalidNameException;
7 import cz.cuni.amis.pogamut.sposh.executor.IWorkExecutor;
8 import java.awt.datatransfer.DataFlavor;
9 import java.util.Collections;
10 import java.util.List;
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 public class TriggeredAction extends PoshDummyElement implements IReferenceElement, INamedElement {
30
31 private PrimitiveCall actionCall;
32 public static final DataFlavor dataFlavor = new DataFlavor(TriggeredAction.class, "triggered_action");
33 public static final String taName = "taName";
34 public static final String taArgs = "taAruments";
35
36 TriggeredAction(String actionName) {
37 this.actionCall = new PrimitiveCall(actionName);
38 }
39
40 TriggeredAction(PrimitiveCall actionCall) {
41 this.actionCall = actionCall;
42 }
43
44 @Override
45 public List<PoshElement> getChildDataNodes() {
46 return Collections.<PoshElement>emptyList();
47 }
48
49 @Override
50 public String toString() {
51 return actionCall.toString();
52 }
53
54 @Override
55 public String getName() {
56 return actionCall.getName();
57 }
58
59 public PrimitiveCall getActionCall() {
60 return actionCall;
61 }
62
63
64
65
66
67
68
69
70 public void setActionName(String newName) throws InvalidNameException, CycleException {
71 newName = newName.trim();
72
73 if (!newName.matches(IDENT_PATTERN)) {
74 throw InvalidNameException.create(newName);
75 }
76
77 String oldName = this.getName();
78 this.actionCall = new PrimitiveCall(newName, actionCall.getParameters());
79
80 if (getRootNode() != null && getRootNode().isCycled()) {
81 this.actionCall = new PrimitiveCall(oldName, actionCall.getParameters());
82 throw CycleException.createFromName(newName);
83 }
84 firePropertyChange(taName, oldName, newName);
85 }
86
87
88
89
90
91
92
93
94
95 @Override
96 public void rename(String newName) throws InvalidNameException, CycleException, DuplicateNameException {
97 throw new UnsupportedOperationException("Not yet implemented");
98 }
99
100 @Override
101 public boolean moveChild(int newIndex, PoshElement child) {
102 throw new UnsupportedOperationException();
103 }
104
105 @Override
106 public DataFlavor getDataFlavor() {
107 return dataFlavor;
108 }
109
110 @Override
111 public LapType getType() {
112 return LapType.ACTION;
113 }
114
115
116
117
118
119
120
121 public void synchronize(TriggeredAction source) throws CycleException {
122 try {
123 this.setActionName(source.getName());
124 Arguments sourceArguments = source.getActionCall().getParameters();
125 setArguments(new Arguments(sourceArguments));
126 } catch (InvalidNameException ex) {
127 throw new FubarException("Name of the source action \"" + source.getName() + "\" is not valid for this action.", ex);
128 }
129 }
130
131
132
133
134 public void setArguments(Arguments newArguments) {
135 String actionName = actionCall.getName();
136 Arguments oldArguments = actionCall.getParameters();
137 this.actionCall = new PrimitiveCall(actionName, newArguments);
138
139
140
141 firePropertyChange(taArgs, oldArguments, newArguments);
142 }
143
144
145
146
147
148
149 @Override
150 public Arguments getArguments() {
151 return this.actionCall.getParameters();
152 }
153 }