use of edu.cmu.cs.hcii.cogtool.ui.TaskSelectionState in project cogtool by cogtool.
the class ProjectController method createCopyTaskAction.
// createRenameDesignAction
// Action for CopyTask
protected IListenerAction createCopyTaskAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return TaskSelectionState.class;
}
public boolean performAction(Object prms) {
TaskSelectionState seln = (TaskSelectionState) prms;
AUndertaking[] tasks = seln.getSelectedTasks(TaskSelectionState.PRUNE_SELECTION | TaskSelectionState.ORDER_SELECTION);
// Can only copy to clipboard if one or more tasks are selected
if ((tasks != null) && (tasks.length > 0)) {
try {
ObjectSaver s = CogToolClipboard.startClipboardSave(CogToolClipboard.CopyTasks, CogToolClipboard.SAVE_TO_CLIPBOARD);
for (AUndertaking task : tasks) {
s.saveObject(task);
}
s.finish();
if (tasks.length == 1) {
interaction.setStatusMessage(TASK_COPIED);
} else {
interaction.setStatusMessage(TASKS_COPIED);
}
return true;
} catch (IOException e) {
throw new RcvrClipboardException(e);
} catch (OutOfMemoryError error) {
throw new RcvrOutOfMemoryException("Copying Tasks", error);
}
} else {
interaction.protestNoSelection();
}
return false;
}
};
}
use of edu.cmu.cs.hcii.cogtool.ui.TaskSelectionState in project cogtool by cogtool.
the class ProjectController method createNewTaskAction.
// Action for NewTask
protected IListenerAction createNewTaskAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return TaskSelectionState.class;
}
public boolean performAction(Object prms) {
TaskSelectionState selection = (TaskSelectionState) prms;
// Figure out what the selection is
AUndertaking[] selectedTasks = selection.getSelectedTasks(TaskSelectionState.ORDER_SELECTION);
Task newTask = null;
if ((selectedTasks == null) || (selectedTasks.length == 0)) {
// No task selection -- add a new root task
String newTaskName = computeNewTaskName(project, DEFAULT_TASK_PREFIX);
newTask = addTask(project, project.getUndertakings().size(), newTaskName);
} else {
// At least one selected task: add a new sibling after
// Multiple selected tasks:
// if all tasks have same parent,
// add new sibling after last selection
// if tasks do not have same parent,
// add new root task after last selected root
// but, if no selected root, add new root at end
// Get parent
TaskGroup parent = selection.getSelectedTaskParent();
if (parent == null) {
String newTaskName = computeNewTaskName(project, DEFAULT_TASK_PREFIX);
newTask = addTask(project, findLastSelectedRoot(selectedTasks), newTaskName);
} else {
String newTaskName = computeNewTaskName(parent, DEFAULT_TASK_PREFIX);
AUndertaking last = selectedTasks[selectedTasks.length - 1];
newTask = addTask(parent, parent.getUndertakings().indexOf(last) + 1, newTaskName);
}
}
// Task is automatically selected when added -- rename
// Cannot put this into the ui because of undo/redo
ui.initiateTaskRename(newTask);
return true;
}
};
}
use of edu.cmu.cs.hcii.cogtool.ui.TaskSelectionState in project cogtool by cogtool.
the class ProjectController method createPromoteTaskAction.
protected IListenerAction createPromoteTaskAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return TaskSelectionState.class;
}
public boolean performAction(Object prms) {
TaskSelectionState seln = (TaskSelectionState) prms;
AUndertaking[] tasks = seln.getSelectedTasks(TaskSelectionState.PRUNE_SELECTION | TaskSelectionState.ORDER_SELECTION);
if ((tasks == null) || (tasks.length == 0)) {
interaction.protestNoSelection();
return false;
}
List<String> errors = new ArrayList<String>();
String editLabel = (tasks.length > 1) ? PROMOTE_TASKS : PROMOTE_TASK;
CompoundUndoableEdit editSeq = new CompoundUndoableEdit(editLabel, ProjectLID.PromoteTask);
for (AUndertaking task : tasks) {
String promoteError = promoteTask(task, ProjectLID.PromoteTask, editSeq);
if (promoteError != null) {
errors.add(promoteError);
}
}
if (errors.size() > 0) {
interaction.reportProblems(editLabel, errors);
}
if (editSeq.isSignificant()) {
editSeq.end();
undoMgr.addEdit(editSeq);
}
return true;
}
};
}
use of edu.cmu.cs.hcii.cogtool.ui.TaskSelectionState in project cogtool by cogtool.
the class ProjectController method createCutTaskAction.
// Action for CutTask
protected IListenerAction createCutTaskAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return TaskSelectionState.class;
}
public boolean performAction(Object prms) {
TaskSelectionState selection = (TaskSelectionState) prms;
AUndertaking[] selectedTasks = selection.getSelectedTasks(TaskSelectionState.PRUNE_SELECTION);
// Can only cut if one or more tasks are currently selected.
if ((selectedTasks != null) && (selectedTasks.length > 0)) {
try {
ObjectSaver saver = CogToolClipboard.startClipboardSave(CogToolClipboard.CopyTasks, CogToolClipboard.SAVE_TO_CLIPBOARD);
deleteTasks(selectedTasks, saver, undoMgr);
// flush!
saver.finish();
return true;
} catch (IOException e) {
throw new RcvrClipboardException("Could not execute cut", e);
} catch (OutOfMemoryError error) {
throw new RcvrOutOfMemoryException("Cutting Tasks", error);
}
} else {
interaction.protestNoSelection();
}
return false;
}
};
}
use of edu.cmu.cs.hcii.cogtool.ui.TaskSelectionState in project cogtool by cogtool.
the class ProjectController method createDuplicateTasksAction.
protected IListenerAction createDuplicateTasksAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return TaskSelectionState.class;
}
public boolean performAction(Object prms) {
TaskSelectionState seln = (TaskSelectionState) prms;
AUndertaking[] tasks = seln.getSelectedTasks(TaskSelectionState.ORDER_SELECTION);
// Can only duplicate if one or more tasks are selected
if ((tasks != null) && (tasks.length > 0)) {
String presentationName = (tasks.length > 1) ? DUPLICATE_TASKS : DUPLICATE_TASK;
CompoundUndoableEdit editSeq = new CompoundUndoableEdit(presentationName, ProjectLID.DuplicateTask);
AUndertaking lastDuplicate = null;
for (AUndertaking task : tasks) {
TaskParent parent = project.getTaskParent(task);
List<AUndertaking> parentUndertakings = parent.getUndertakings();
int atIndex = parentUndertakings.indexOf(task) + 1;
lastDuplicate = duplicateTask(task, atIndex, parent, parentUndertakings, ProjectLID.DuplicateTask, presentationName, editSeq);
}
// Done with undo/redo steps; add the compound change
// to the undo manager.
editSeq.end();
undoMgr.addEdit(editSeq);
if (tasks.length == 1) {
ui.initiateTaskRename(lastDuplicate);
}
} else {
interaction.protestNoSelection();
}
return true;
}
};
}
Aggregations