Lines 224-244
Link Here
|
224 |
*/ |
224 |
*/ |
225 |
public ICommand reduce() { |
225 |
public ICommand reduce() { |
226 |
switch (size()) { |
226 |
switch (size()) { |
227 |
case 1: |
227 |
case 0: |
228 |
IUndoableOperation child = (IUndoableOperation) iterator() |
228 |
return this; |
|
|
229 |
case 1: |
230 |
IUndoableOperation child = (IUndoableOperation) iterator() |
229 |
.next(); |
231 |
.next(); |
230 |
|
232 |
|
231 |
if (child instanceof ICommand |
233 |
if (child instanceof ICommand && |
232 |
&& (child instanceof CompositeEMFOperation || child instanceof AbstractEMFOperation)) { |
234 |
child instanceof AbstractEMFOperation) { |
233 |
// return the single command if is a kind of EMF operation; |
235 |
// return the single command if is a kind of EMF operation; |
234 |
// otherwise this composite will be returned to preserve the |
236 |
// otherwise this composite will be returned to preserve the |
235 |
// EMF transaction behaviour. |
237 |
// EMF transaction behaviour. |
236 |
return ((ICommand) child).reduce(); |
238 |
return ((ICommand) child).reduce(); |
|
|
239 |
} |
240 |
default: |
241 |
if (!isTransactionNestingEnabled()) { |
242 |
List children = getChildren(); |
243 |
IUndoableOperation[] opChildren = (IUndoableOperation[]) children |
244 |
.toArray(new IUndoableOperation[children.size()]); |
245 |
children.clear(); |
246 |
for (int i = 0; i < opChildren.length; ++i) { |
247 |
doReduce(opChildren[i], children); |
237 |
} |
248 |
} |
|
|
249 |
} |
238 |
} |
250 |
} |
239 |
return this; |
251 |
return this; |
240 |
} |
252 |
} |
241 |
|
253 |
|
|
|
254 |
private void doReduce(IUndoableOperation operation, List children) { |
255 |
if (operation instanceof CompositeEMFOperation) { |
256 |
for (Iterator i = ((CompositeEMFOperation) operation).iterator(); i.hasNext();) { |
257 |
doReduce((IUndoableOperation) i.next(), children); |
258 |
} |
259 |
} else { |
260 |
children.add(operation); |
261 |
} |
262 |
} |
263 |
|
242 |
/** |
264 |
/** |
243 |
* Answers whether or not this composite operation has children. |
265 |
* Answers whether or not this composite operation has children. |
244 |
* |
266 |
* |