|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| package org.ericmignot.modeler.action; |
|
19 |
| |
|
20 |
| import java.util.HashMap; |
|
21 |
| import java.util.Iterator; |
|
22 |
| import java.util.Map; |
|
23 |
| |
|
24 |
| import org.ericmignot.modeler.data.BusinessObject; |
|
25 |
| import org.ericmignot.modeler.util.action.ActionException; |
|
26 |
| import org.ericmignot.modeler.util.action.NotifyableAction; |
|
27 |
| |
|
28 |
| public class UpdateAction extends NotifyableAction |
|
29 |
| { |
|
30 |
| private BusinessObject businessObject; |
|
31 |
| private Map oldValues; |
|
32 |
| private Map newValues; |
|
33 |
| |
|
34 |
2
| public UpdateAction(BusinessObject businessObject, Map newValues)
|
|
35 |
| { |
|
36 |
2
| this.businessObject = businessObject;
|
|
37 |
2
| this.newValues = newValues;
|
|
38 |
| |
|
39 |
2
| this.oldValues = new HashMap();
|
|
40 |
2
| Iterator iterator = newValues.keySet().iterator();
|
|
41 |
2
| while (iterator.hasNext())
|
|
42 |
| { |
|
43 |
4
| String fieldName = (String) iterator.next();
|
|
44 |
4
| String oldValue = (String) this.businessObject.getFieldValue(fieldName);
|
|
45 |
4
| this.oldValues.put(fieldName, oldValue);
|
|
46 |
| } |
|
47 |
| } |
|
48 |
| |
|
49 |
2
| public Object execute(Object actionParameter) throws ActionException
|
|
50 |
| { |
|
51 |
2
| Map source = this.newValues;
|
|
52 |
2
| Iterator iterator = source.keySet().iterator();
|
|
53 |
2
| while (iterator.hasNext())
|
|
54 |
| { |
|
55 |
4
| String fieldName = (String) iterator.next();
|
|
56 |
4
| String fieldValue = (String) source.get(fieldName);
|
|
57 |
4
| this.businessObject.setFieldValue(fieldName, fieldValue);
|
|
58 |
| } |
|
59 |
2
| return this.businessObject;
|
|
60 |
| } |
|
61 |
| |
|
62 |
1
| public Object cancel(Object actionParameter) throws ActionException
|
|
63 |
| { |
|
64 |
1
| Map source = this.oldValues;
|
|
65 |
1
| Iterator iterator = source.keySet().iterator();
|
|
66 |
1
| while (iterator.hasNext())
|
|
67 |
| { |
|
68 |
2
| String fieldName = (String) iterator.next();
|
|
69 |
2
| String fieldValue = (String) source.get(fieldName);
|
|
70 |
2
| this.businessObject.setFieldValue(fieldName, fieldValue);
|
|
71 |
| } |
|
72 |
1
| return this.businessObject;
|
|
73 |
| } |
|
74 |
| |
|
75 |
| |
|
76 |
| } |