use of edu.cmu.cs.hcii.cogtool.model.TaskParent in project cogtool by cogtool.
the class ProjectController method moveTaskAction.
protected boolean moveTaskAction(TaskSelectionState seln, boolean moveEarlier) {
AUndertaking[] tasks = seln.getSelectedTasks(TaskSelectionState.PRUNE_SELECTION | TaskSelectionState.ORDER_SELECTION);
if ((tasks == null) || (tasks.length == 0)) {
interaction.protestNoSelection();
return false;
}
if (tasks.length > 1) {
interaction.protestTooManySelectedTasks();
return false;
}
final AUndertaking task = tasks[0];
final TaskParent parent = project.getTaskParent(task);
List<AUndertaking> siblings = parent.getUndertakings();
int siblingCount = siblings.size();
if (siblingCount == 1) {
interaction.setStatusMessage(taskIsOnlyChild);
} else {
final int oldTaskIndex = siblings.indexOf(task);
IUndoableEdit edit;
if (moveEarlier) {
if (oldTaskIndex == 0) {
interaction.protestCannotMoveEarlier();
return false;
}
parent.removeUndertaking(task);
parent.addUndertaking(oldTaskIndex - 1, task);
edit = new AUndoableEdit(ProjectLID.MoveTaskEarlier) {
@Override
public String getPresentationName() {
return MOVE_TASK_EARLIER;
}
@Override
public void redo() {
super.redo();
parent.removeUndertaking(task);
parent.addUndertaking(oldTaskIndex - 1, task);
}
@Override
public void undo() {
super.undo();
parent.removeUndertaking(task);
parent.addUndertaking(oldTaskIndex, task);
}
};
} else {
if (oldTaskIndex == siblingCount - 1) {
interaction.protestCannotMoveLater();
return false;
}
parent.removeUndertaking(task);
parent.addUndertaking(oldTaskIndex + 1, task);
edit = new AUndoableEdit(ProjectLID.MoveTaskEarlier) {
@Override
public String getPresentationName() {
return MOVE_TASK_LATER;
}
@Override
public void redo() {
super.redo();
parent.removeUndertaking(task);
parent.addUndertaking(oldTaskIndex + 1, task);
}
@Override
public void undo() {
super.undo();
parent.removeUndertaking(task);
parent.addUndertaking(oldTaskIndex, task);
}
};
}
undoMgr.addEdit(edit);
}
return true;
}
use of edu.cmu.cs.hcii.cogtool.model.TaskParent in project cogtool by cogtool.
the class ProjectController method removeChildTasks.
/**
* Remove child tasks, recording their old parents and indexes
* of each child in their respective parent. To restore,
* add back to the old parents in reverse.
* <p>
* Fills in the oldParents and indexes arrays only if not <code>null</code>.
* <p>
* It is assumed that the oldParents and indexes arrays are the
* exact same size as the children array.
*
* @param children the tasks to be removed
* @param oldParents if not <code>null</code>, to hold the corresponding
* parent for each removed task
* @param indexes if not <code>null</code>, to hold the index of
* each removed task in its corresponding parent
* @author mlh
*/
protected void removeChildTasks(AUndertaking[] children, TaskParent[] oldParents, int[] indexes) {
for (int i = 0; i < children.length; i++) {
TaskParent parent = project.getTaskParent(children[i]);
// Save old index for undo
if (indexes != null) {
indexes[i] = parent.getUndertakings().indexOf(children[i]);
}
// Remove from old parent
parent.removeUndertaking(children[i]);
if (oldParents != null) {
oldParents[i] = parent;
}
}
}
Aggregations