use of org.whole.lang.commands.CompoundCommand in project whole by wholeplatform.
the class HistoryManager method mergeHistory.
// assume that subHistory will be replaced by the returned one
public IHistoryManager mergeHistory(IHistoryManager subHistory) {
int size = subHistory.getUndoSize();
if (size > 0 && !subHistory.equals(this)) {
ICommand[] changes = subHistory.getUndoCommands().toArray(new ICommand[size]);
ICommand command = new CompoundCommand(nextExecutionTime(), changes);
addCommand(command);
}
return this;
}
use of org.whole.lang.commands.CompoundCommand in project whole by wholeplatform.
the class HistoryManager method compound.
protected CompoundCommand compound(int beginIndex) {
CompoundCommand command = null;
int size = lastExecutedIndex + 1 - beginIndex;
if (size > 0) {
List<ICommand> subList = history.subList(beginIndex, lastExecutedIndex + 1);
command = new CompoundCommand(nextExecutionTime(), reduce(subList).toArray(new ICommand[0]));
subList.clear();
addCommand(command);
}
return command;
}
use of org.whole.lang.commands.CompoundCommand in project whole by wholeplatform.
the class HistoryManager method reduce.
// TODO called by model to delta Stream if changes.size > model.size
protected List<ICommand> reduce(List<ICommand> commands) {
if (commands.isEmpty())
return commands;
List<ICommand> list = new ArrayList<ICommand>();
for (int i = 0, size = commands.size(); i < size; i++) {
ICommand command = commands.get(i);
if (CommandKind.COMPOUND == command.getKind()) {
for (ICommand child : ((CompoundCommand) command).commands) list.add(child);
} else
list.add(command);
}
int index = list.size() - 1;
while (index > 0) {
ICommand lastCommand = list.get(index--);
if (CommandKind.CHANGE == lastCommand.getKind()) {
IEntity lastSource = lastCommand.getSource();
FeatureDescriptor lastSourceFD = lastCommand.getSourceFeatureDescriptor();
int firstIndex = index;
while (firstIndex >= 0) {
ICommand firstCommand = list.get(firstIndex);
if (CommandKind.CHANGE != firstCommand.getKind() || firstCommand.getSource() != lastSource || firstCommand.getSourceFeatureDescriptor() != lastSourceFD)
break;
else
firstIndex--;
}
if (firstIndex < index) {
if (lastSourceFD == null)
lastCommand.setOldObject(list.get(firstIndex + 1).getOldObject());
else
lastCommand.setOldEntity(list.get(firstIndex + 1).getOldEntity());
for (int i = firstIndex + 1; i <= index; i++) list.remove(firstIndex + 1).dispose();
index = firstIndex;
}
}
}
return list;
// iterate over model tree to exclude overridden commands
// for each command discard overridden prevCommands
}
Aggregations