1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.sf.magicproject.action.context;
20
21 import java.util.ArrayList;
22 import java.util.List;
23
24 import net.sf.magicproject.clickable.targetable.Targetable;
25 import net.sf.magicproject.stack.StackManager;
26 import net.sf.magicproject.test.Test;
27
28 /***
29 * @author <a href="mailto:fabdouglas@users.sourceforge.net">Fabrice Daugan </a>
30 * @since 0.86
31 */
32 public class TargetList implements ActionContext {
33
34 /***
35 * Create a new instance of this class.
36 */
37 public TargetList() {
38 super();
39 }
40
41 /***
42 * Add yhe specified target to the list of this context.
43 *
44 * @param target
45 * the target to add
46 * @param test
47 * the attached test validating the target
48 */
49 public void add(Targetable target, Test test) {
50 if (targetList == null) {
51 targetList = new ArrayList<Targetable>();
52 this.testList = new ArrayList<Test>();
53 }
54 targetList.add(target);
55 testList.add(test);
56 }
57
58 /***
59 * Add the specified targets to the list of this context.
60 *
61 * @param targetList
62 * the targets to add
63 * @param testList
64 * the attached tests validating the targets
65 */
66 public void addAll(List<Targetable> targetList, List<Test> testList) {
67 if (this.targetList == null) {
68 this.targetList = new ArrayList<Targetable>();
69 this.testList = new ArrayList<Test>();
70 }
71 this.targetList.addAll(targetList);
72 this.testList.addAll(testList);
73 }
74
75 /***
76 * The targets added by this context.
77 */
78 public List<Targetable> targetList;
79
80 /***
81 * The restriction test used to add the targets.
82 */
83 public List<Test> testList;
84
85 /***
86 * Rollback the target list content.
87 */
88 public void rollback() {
89 for (int index = 0; index < targetList.size(); index++) {
90 StackManager.getInstance().getTargetedList().removeTargeted(
91 targetList.get(index));
92 }
93 }
94
95 /***
96 * Replay the target list operation.
97 *
98 * @param eventOption
99 * is the event mode : Force, default, none. Depending this value,
100 * the added target will be rechecked before resolution process
101 * @param raiseEvent
102 * if false, is any case, no event can be triggered.
103 */
104 public void replay(int eventOption, boolean raiseEvent) {
105 for (int index = 0; index < targetList.size(); index++) {
106 StackManager.getInstance().getTargetedList().addTarget(eventOption,
107 targetList.get(index), testList.get(index), raiseEvent);
108 }
109 }
110 }