use of edu.cmu.cs.hcii.cogtool.model.TaskGroup 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.model.TaskGroup in project cogtool by cogtool.
the class ProjectController method hcipaRenameTask.
protected boolean hcipaRenameTask(AUndertaking task, String oldName, String newName) {
// Check if newTaskName is empty; retry if user desires
if (oldName.length() == 0) {
if (interaction.protestEmptyTaskName()) {
ui.initiateTaskRename(task);
return true;
}
return false;
}
TaskGroup parent = task.getTaskGroup();
// Check uniqueness of new name; if not, complain
if (isTaskNameUnique(newName, oldName, parent)) {
// If renaming the group, change both labels
if (task.isTaskGroup()) {
TaskGroup group = (TaskGroup) task;
// Just a rename; not changing nature
undoMgr.addEdit(HCIPACmd.updateLabels(group, newName, RENAME_TASK));
} else if (!newName.equals(oldName)) {
if (parent == null) {
// Create task group; generate subtasks
AUndertaking[] subtasks = HCIPACmd.addHCIPATasks(project, task, newName, MODELGEN_ALG, RENAME_TASK, undoMgr);
ui.initiateTaskRename(subtasks[1], false);
} else {
if (parent.getUndertakings().indexOf(task) == 1) {
// changing function name
HCIPACmd.setFunctionName(project, task, newName, MODELGEN_ALG, RENAME_TASK, undoMgr);
return true;
}
// not the select function step, so rename normally
return renameTask(task, oldName, newName, parent);
}
}
return true;
}
// Not unique; complain and retry if user desires
if (interaction.protestNotUniqueTaskName()) {
ui.initiateTaskRename(task);
return true;
}
return false;
}
use of edu.cmu.cs.hcii.cogtool.model.TaskGroup in project cogtool by cogtool.
the class ProjectController method addTaskResults.
// Utility to help both copyResults and exportResultsToCSV
protected void addTaskResults(Iterator<AUndertaking> tasks, StringBuilder buffer, String separator) {
while (tasks.hasNext()) {
AUndertaking t = tasks.next();
String[] resultStrs = ResultDisplayPolicy.getTaskRowStrings(project, t, ResultDisplayPolicy.NO_SECS);
if (resultStrs.length > 0) {
buffer.append(CSVSupport.quoteCell(resultStrs[0]));
for (int i = 1; i < resultStrs.length; i++) {
buffer.append(separator);
buffer.append(CSVSupport.quoteCell(resultStrs[i]));
}
}
CSVSupport.addLineEnding(buffer);
if (t.isTaskGroup()) {
addTaskResults(((TaskGroup) t).getUndertakings().iterator(), buffer, separator);
}
}
}
use of edu.cmu.cs.hcii.cogtool.model.TaskGroup in project cogtool by cogtool.
the class ProjectController method duplicateTask.
protected AUndertaking duplicateTask(AUndertaking task, int atIndex, TaskParent parent, List<AUndertaking> siblings, CogToolLID lid, String presentationName, IUndoableEditSequence editSeq) {
String newTaskName = NamedObjectUtil.makeNameUnique(task.getName(), siblings);
IUndoableEdit edit;
AUndertaking duplicateTask = task.duplicate(newTaskName);
// Create undo/redo step
if (task.isTaskGroup()) {
SNIFACTExecContext context = (SNIFACTExecContext) task.getAttribute(WidgetAttributes.SNIFACT_CONTEXT_ATTR);
// duplicated as well.
if (!NullSafe.equals(context, WidgetAttributes.NO_CONTEXT)) {
duplicateTask.setAttribute(WidgetAttributes.SNIFACT_CONTEXT_ATTR, context.duplicate());
}
edit = createNewTaskGroupUndo(parent, atIndex, (TaskGroup) duplicateTask, null, null, new AUndertaking[0], lid, presentationName);
} else {
edit = createNewTaskUndo(parent, atIndex, duplicateTask, lid, presentationName);
}
editSeq.addEdit(edit);
parent.addUndertaking(atIndex, duplicateTask);
if (task.isTaskGroup()) {
duplicateTaskApplications((TaskGroup) task, (TaskGroup) duplicateTask);
} else {
duplicateTaskApplications(task, duplicateTask);
}
return duplicateTask;
}
use of edu.cmu.cs.hcii.cogtool.model.TaskGroup in project cogtool by cogtool.
the class ProjectController method mapProjectTasks.
protected void mapProjectTasks(AUndertaking task, TaskParent parent, Map<AUndertaking, AUndertaking> reuseTasks, IUndoableEditSequence editSeq, String presentationName) {
AUndertaking correspondingTask = parent.getUndertaking(task.getName());
if (correspondingTask != null) {
reuseTasks.put(task, correspondingTask);
if ((task instanceof TaskGroup) && (correspondingTask instanceof TaskGroup)) {
TaskGroup correspondingGroup = (TaskGroup) correspondingTask;
Iterator<AUndertaking> childTasks = ((TaskGroup) task).getUndertakings().iterator();
while (childTasks.hasNext()) {
AUndertaking childTask = childTasks.next();
mapProjectTasks(childTask, correspondingGroup, reuseTasks, editSeq, presentationName);
}
}
} else {
pasteTask(task, parent, parent.getUndertakings().size(), editSeq, presentationName);
}
}
Aggregations