Search in sources :

Example 1 with CompoundCommand

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;
}
Also used : ICommand(org.whole.lang.commands.ICommand) CompoundCommand(org.whole.lang.commands.CompoundCommand)

Example 2 with CompoundCommand

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;
}
Also used : ICommand(org.whole.lang.commands.ICommand) CompoundCommand(org.whole.lang.commands.CompoundCommand)

Example 3 with CompoundCommand

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
}
Also used : IEntity(org.whole.lang.model.IEntity) FeatureDescriptor(org.whole.lang.reflect.FeatureDescriptor) ICommand(org.whole.lang.commands.ICommand) ArrayList(java.util.ArrayList) CompoundCommand(org.whole.lang.commands.CompoundCommand)

Aggregations

CompoundCommand (org.whole.lang.commands.CompoundCommand)3 ICommand (org.whole.lang.commands.ICommand)3 ArrayList (java.util.ArrayList)1 IEntity (org.whole.lang.model.IEntity)1 FeatureDescriptor (org.whole.lang.reflect.FeatureDescriptor)1