|
Lines 36-42
Link Here
|
| 36 |
*/ |
36 |
*/ |
| 37 |
public class TriggerCommand extends ConditionalRedoCommand.Compound { |
37 |
public class TriggerCommand extends ConditionalRedoCommand.Compound { |
| 38 |
private final Command triggeringCommand; |
38 |
private final Command triggeringCommand; |
| 39 |
private final List triggers; |
39 |
private final List<Command> triggers; |
| 40 |
|
40 |
|
| 41 |
/** |
41 |
/** |
| 42 |
* Initializes me with a list of commands triggered not by the execution of |
42 |
* Initializes me with a list of commands triggered not by the execution of |
|
Lines 47-57
Link Here
|
| 47 |
* |
47 |
* |
| 48 |
* @param triggers the trigger commands that I encapsulate |
48 |
* @param triggers the trigger commands that I encapsulate |
| 49 |
*/ |
49 |
*/ |
| 50 |
public TriggerCommand(List triggers) { |
50 |
public TriggerCommand(List<? extends Command> triggers) { |
| 51 |
super(0, "Triggers", "Triggered Changes", triggers); //$NON-NLS-1$ //$NON-NLS-2$ |
51 |
super(0, "Triggers", "Triggered Changes", //$NON-NLS-1$ //$NON-NLS-2$ |
|
|
52 |
new java.util.ArrayList<Command>(triggers)); |
| 52 |
|
53 |
|
| 53 |
this.triggeringCommand = null; |
54 |
this.triggeringCommand = null; |
| 54 |
this.triggers = triggers; |
55 |
this.triggers = commandList; |
| 55 |
} |
56 |
} |
| 56 |
|
57 |
|
| 57 |
/** |
58 |
/** |
|
Lines 62-72
Link Here
|
| 62 |
* @param triggeringCommand the command that triggered further commands |
63 |
* @param triggeringCommand the command that triggered further commands |
| 63 |
* @param triggers the trigger commands that I encapsulate |
64 |
* @param triggers the trigger commands that I encapsulate |
| 64 |
*/ |
65 |
*/ |
| 65 |
public TriggerCommand(Command triggeringCommand, List triggers) { |
66 |
public TriggerCommand(Command triggeringCommand, List<? extends Command> triggers) { |
| 66 |
super(0, triggeringCommand.getLabel(), triggeringCommand.getDescription(), triggers); |
67 |
super(0, triggeringCommand.getLabel(), triggeringCommand.getDescription(), |
|
|
68 |
new java.util.ArrayList<Command>(triggers)); |
| 67 |
|
69 |
|
| 68 |
this.triggeringCommand = triggeringCommand; |
70 |
this.triggeringCommand = triggeringCommand; |
| 69 |
this.triggers = triggers; |
71 |
this.triggers = commandList; |
| 70 |
} |
72 |
} |
| 71 |
|
73 |
|
| 72 |
/** |
74 |
/** |
|
Lines 85-95
Link Here
|
| 85 |
* |
87 |
* |
| 86 |
* @return my triggers, as a list of {@link Command}s. Will not be empty |
88 |
* @return my triggers, as a list of {@link Command}s. Will not be empty |
| 87 |
*/ |
89 |
*/ |
| 88 |
public final List getTriggers() { |
90 |
public final List<Command> getTriggers() { |
| 89 |
return triggers; |
91 |
return triggers; |
| 90 |
} |
92 |
} |
| 91 |
|
93 |
|
| 92 |
// Documentation copied from the inherited specification |
94 |
// Documentation copied from the inherited specification |
|
|
95 |
@Override |
| 93 |
protected boolean prepare() { |
96 |
protected boolean prepare() { |
| 94 |
// we will check canExecute() as we go |
97 |
// we will check canExecute() as we go |
| 95 |
return !triggers.isEmpty(); |
98 |
return !triggers.isEmpty(); |
|
Lines 99-109
Link Here
|
| 99 |
* Executes all of my trigger commands, then prepends the original triggering |
102 |
* Executes all of my trigger commands, then prepends the original triggering |
| 100 |
* command (if any) so that it will be undone/redone with the others. |
103 |
* command (if any) so that it will be undone/redone with the others. |
| 101 |
*/ |
104 |
*/ |
|
|
105 |
@Override |
| 102 |
public void execute() { |
106 |
public void execute() { |
| 103 |
// execute just the triggers |
107 |
// execute just the triggers |
| 104 |
for (ListIterator iter = commandList.listIterator(); iter.hasNext();) { |
108 |
for (ListIterator<Command> iter = commandList.listIterator(); iter.hasNext();) { |
| 105 |
try { |
109 |
try { |
| 106 |
Command command = (Command) iter.next(); |
110 |
Command command = iter.next(); |
| 107 |
|
111 |
|
| 108 |
if (command.canExecute()) { |
112 |
if (command.canExecute()) { |
| 109 |
command.execute(); |
113 |
command.execute(); |
|
Lines 123-129
Link Here
|
| 123 |
// Iterate back over the executed commands to undo them. |
127 |
// Iterate back over the executed commands to undo them. |
| 124 |
// |
128 |
// |
| 125 |
while (iter.hasPrevious()) { |
129 |
while (iter.hasPrevious()) { |
| 126 |
Command command = (Command) iter.previous(); |
130 |
Command command = iter.previous(); |
| 127 |
if (command.canUndo()) { |
131 |
if (command.canUndo()) { |
| 128 |
command.undo(); |
132 |
command.undo(); |
| 129 |
} else { |
133 |
} else { |
|
Lines 147-153
Link Here
|
| 147 |
// then replace the command-list with a new list that includes |
151 |
// then replace the command-list with a new list that includes |
| 148 |
// the |
152 |
// the |
| 149 |
// originally executed command (for undo/redo) |
153 |
// originally executed command (for undo/redo) |
| 150 |
commandList = new java.util.ArrayList(triggers.size() + 1); |
154 |
commandList = new java.util.ArrayList<Command>(triggers.size() + 1); |
| 151 |
commandList.add(triggeringCommand); |
155 |
commandList.add(triggeringCommand); |
| 152 |
commandList.addAll(triggers); |
156 |
commandList.addAll(triggers); |
| 153 |
} |
157 |
} |
|
Lines 157-163
Link Here
|
| 157 |
* Extends the inherited implementation by disposing my triggering command, |
161 |
* Extends the inherited implementation by disposing my triggering command, |
| 158 |
* also (if any). |
162 |
* also (if any). |
| 159 |
*/ |
163 |
*/ |
| 160 |
public void dispose() { |
164 |
@Override |
|
|
165 |
public void dispose() { |
| 161 |
super.dispose(); |
166 |
super.dispose(); |
| 162 |
|
167 |
|
| 163 |
if (triggeringCommand != null) { |
168 |
if (triggeringCommand != null) { |