Search in sources :

Example 11 with TaskGroup

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;
        }
    };
}
Also used : Task(edu.cmu.cs.hcii.cogtool.model.Task) IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) TaskSelectionState(edu.cmu.cs.hcii.cogtool.ui.TaskSelectionState) TaskGroup(edu.cmu.cs.hcii.cogtool.model.TaskGroup)

Example 12 with TaskGroup

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;
}
Also used : TaskGroup(edu.cmu.cs.hcii.cogtool.model.TaskGroup)

Example 13 with TaskGroup

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);
        }
    }
}
Also used : AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) TaskGroup(edu.cmu.cs.hcii.cogtool.model.TaskGroup) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint)

Example 14 with TaskGroup

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;
}
Also used : AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) IUndoableEdit(edu.cmu.cs.hcii.cogtool.util.IUndoableEdit) SNIFACTExecContext(edu.cmu.cs.hcii.cogtool.model.SNIFACTExecContext) TaskGroup(edu.cmu.cs.hcii.cogtool.model.TaskGroup)

Example 15 with TaskGroup

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);
    }
}
Also used : AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) TaskGroup(edu.cmu.cs.hcii.cogtool.model.TaskGroup)

Aggregations

TaskGroup (edu.cmu.cs.hcii.cogtool.model.TaskGroup)43 AUndertaking (edu.cmu.cs.hcii.cogtool.model.AUndertaking)35 TaskApplication (edu.cmu.cs.hcii.cogtool.model.TaskApplication)16 Design (edu.cmu.cs.hcii.cogtool.model.Design)10 ITaskDesign (edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign)9 DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)8 IListenerAction (edu.cmu.cs.hcii.cogtool.util.IListenerAction)8 AUndoableEdit (edu.cmu.cs.hcii.cogtool.util.AUndoableEdit)7 Script (edu.cmu.cs.hcii.cogtool.model.Script)6 TaskParent (edu.cmu.cs.hcii.cogtool.model.TaskParent)6 CompoundUndoableEdit (edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit)6 ProjectSelectionState (edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState)5 IUndoableEdit (edu.cmu.cs.hcii.cogtool.util.IUndoableEdit)5 CognitiveModelGenerator (edu.cmu.cs.hcii.cogtool.model.CognitiveModelGenerator)4 GroupNature (edu.cmu.cs.hcii.cogtool.model.GroupNature)4 TaskSelectionState (edu.cmu.cs.hcii.cogtool.ui.TaskSelectionState)4 HashMap (java.util.HashMap)4 Demonstration (edu.cmu.cs.hcii.cogtool.model.Demonstration)3 SNIFACTExecContext (edu.cmu.cs.hcii.cogtool.model.SNIFACTExecContext)3 AlertHandler (edu.cmu.cs.hcii.cogtool.util.AlertHandler)3