Search in sources :

Example 6 with TaskApplication

use of edu.cmu.cs.hcii.cogtool.model.TaskApplication in project cogtool by cogtool.

the class ProjectController method exportCSVKludge.

public void exportCSVKludge() {
    for (Design d : project.getDesigns()) {
        if (d == null) {
            continue;
        }
        for (TaskApplication ta : project.taskApplicationsForDesign(d).values()) {
            if (ta == null) {
                continue;
            }
            Script s = ta.getScript(MODELGEN_ALG);
            if (s == null) {
                continue;
            }
            DemoScriptCmd.exportScriptToCSV(s, project, null, undoMgr);
        }
    }
    exportResultsToCSV();
    exportDesignToXML(null);
}
Also used : Design(edu.cmu.cs.hcii.cogtool.model.Design) ITaskDesign(edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign) Script(edu.cmu.cs.hcii.cogtool.model.Script) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication)

Example 7 with TaskApplication

use of edu.cmu.cs.hcii.cogtool.model.TaskApplication in project cogtool by cogtool.

the class ProjectController method demoteTask.

protected String demoteTask(final AUndertaking task, IUndoableEditSequence editSeq) {
    final TaskParent parent = project.getTaskParent(task);
    List<AUndertaking> siblings = parent.getUndertakings();
    final int indexInParent = siblings.indexOf(task);
    if (indexInParent == 0) {
        return cannotDemoteTaskError + ": " + task.getFullName();
    }
    final String oldTaskName = task.getName();
    final AUndertaking prevSibling = siblings.get(indexInParent - 1);
    final TaskGroup siblingAsTaskGroup = (prevSibling instanceof TaskGroup) ? (TaskGroup) prevSibling : new TaskGroup(prevSibling.getName(), GroupNature.SUM);
    if (siblingAsTaskGroup.getUndertakings().size() > 0) {
        AUndertaking firstTask = siblingAsTaskGroup.getUndertakings().get(0);
        if (firstTask.isSpawned()) {
            return cannotDemoteIntoGroupError;
        }
    }
    // Must treat sibling's task-applications as deleted if the
    // demotion changed it from a task to a task group
    final Map<ITaskDesign, TaskApplication> siblingAssocTAs = (siblingAsTaskGroup != prevSibling) ? project.taskApplicationsForRemovedTask(prevSibling) : null;
    // Remove task from parent and replace previousSibling with
    // new task group if not already one.
    parent.removeUndertaking(task);
    if (siblingAsTaskGroup != prevSibling) {
        parent.removeUndertaking(prevSibling);
        parent.addUndertaking(indexInParent - 1, siblingAsTaskGroup);
    }
    // Insert task as the last child of siblingAsTaskGroup
    makeTaskNameUnique(siblingAsTaskGroup, task);
    siblingAsTaskGroup.addUndertaking(task);
    // Create undoable edit
    IUndoableEdit edit = new AUndoableEdit(ProjectLID.DemoteTask) {

        protected Map<ITaskDesign, TaskApplication> siblingTAs = siblingAssocTAs;

        protected boolean recoverMgrs = true;

        @Override
        public String getPresentationName() {
            return DEMOTE_TASK;
        }

        @Override
        public void redo() {
            super.redo();
            recoverMgrs = true;
            siblingTAs = (siblingAsTaskGroup != prevSibling) ? project.taskApplicationsForRemovedTask(prevSibling) : null;
            // Remove task from parent and replace previousSibling with
            // new task group if not already one.
            parent.removeUndertaking(task);
            if (siblingAsTaskGroup != prevSibling) {
                parent.removeUndertaking(prevSibling);
                parent.addUndertaking(indexInParent - 1, siblingAsTaskGroup);
            }
            // Insert task as the last child of siblingAsTaskGroup
            makeTaskNameUnique(siblingAsTaskGroup, task);
            siblingAsTaskGroup.addUndertaking(task);
        }

        @Override
        public void undo() {
            super.undo();
            recoverMgrs = false;
            // Remove task from sibling group; rename back
            siblingAsTaskGroup.removeUndertaking(task);
            task.setName(oldTaskName);
            // Restore sibling as a task if necessary
            if (siblingAsTaskGroup != prevSibling) {
                parent.removeUndertaking(siblingAsTaskGroup);
                parent.addUndertaking(indexInParent - 1, prevSibling);
                project.restoreRemovedTaskApplications(siblingTAs);
            }
            // Add task back to parent
            parent.addUndertaking(indexInParent, task);
        }

        @Override
        public void die() {
            super.die();
            if (recoverMgrs && (siblingAsTaskGroup != prevSibling)) {
                recoverManagers(task, siblingTAs);
            }
        }
    };
    editSeq.addEdit(edit);
    return null;
}
Also used : ITaskDesign(edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign) TaskParent(edu.cmu.cs.hcii.cogtool.model.TaskParent) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) AUndoableEdit(edu.cmu.cs.hcii.cogtool.util.AUndoableEdit) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) IUndoableEdit(edu.cmu.cs.hcii.cogtool.util.IUndoableEdit) TaskGroup(edu.cmu.cs.hcii.cogtool.model.TaskGroup) Map(java.util.Map) HashMap(java.util.HashMap) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint)

Example 8 with TaskApplication

use of edu.cmu.cs.hcii.cogtool.model.TaskApplication in project cogtool by cogtool.

the class ProjectController method duplicateTaskApplications.

protected void duplicateTaskApplications(AUndertaking originalTask, AUndertaking taskCopy) {
    // The undo edit for adding the Task will remove and restore
    // the task-applications; all we need to do here is duplicate
    // the task applications.
    Iterator<Design> allDesigns = project.getDesigns().iterator();
    while (allDesigns.hasNext()) {
        Design design = allDesigns.next();
        TaskApplication originalTA = project.getTaskApplication(originalTask, design);
        if (originalTA != null) {
            TaskApplication dupTA = originalTA.duplicate(taskCopy, design);
            DemoStateManager demoMgr = DemoStateManager.getStateManager(project, design);
            project.setTaskApplication(dupTA);
            demoMgr.trackEdits(dupTA.getDemonstration());
        }
    }
}
Also used : Design(edu.cmu.cs.hcii.cogtool.model.Design) ITaskDesign(edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication)

Example 9 with TaskApplication

use of edu.cmu.cs.hcii.cogtool.model.TaskApplication in project cogtool by cogtool.

the class ProjectController method createSetAlgorithmHumanAction.

protected IListenerAction createSetAlgorithmHumanAction() {
    return new IListenerAction() {

        public Class<?> getParameterClass() {
            return ProjectSelectionState.class;
        }

        public boolean performAction(Object actionParms) {
            ProjectSelectionState parms = (ProjectSelectionState) actionParms;
            final TaskApplication ta = project.getTaskApplication(parms.getSelectedTask(), parms.getSelectedDesign());
            final IPredictionAlgo oldAlgo = ta.determineActiveAlgorithm(project);
            ta.setActiveAlgorithm(HumanDataAlgo.ONLY);
            undoMgr.addEdit(new AUndoableEdit(ProjectLID.SetAlgorithmHuman) {

                @Override
                public String getPresentationName() {
                    return L10N.get("UNDO.PM.SetHumanAlgorithm", "Set Algorithm to Human Data");
                }

                @Override
                public void redo() {
                    super.redo();
                    ta.setActiveAlgorithm(HumanDataAlgo.ONLY);
                }

                @Override
                public void undo() {
                    super.undo();
                    ta.setActiveAlgorithm(oldAlgo);
                }
            });
            return true;
        }
    };
}
Also used : IPredictionAlgo(edu.cmu.cs.hcii.cogtool.model.IPredictionAlgo) IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) ProjectSelectionState(edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState) AUndoableEdit(edu.cmu.cs.hcii.cogtool.util.AUndoableEdit) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication)

Example 10 with TaskApplication

use of edu.cmu.cs.hcii.cogtool.model.TaskApplication in project cogtool by cogtool.

the class ProjectController method deleteTasks.

// modifyTaskGroup
/**
     * Utility to delete the specified tasks.
     * If an object saver is specified (that is, not <code>null</code>),
     * the deleted tasks are serialized as well.
     *
     * @param tasksToDelete the subtasks to delete
     * @param saver if not null, the saver to use for serializing the
     *              deleted tasks (used saving to the system clipboard for the
     *              "cut" action)
     * @param editSequence to hold the undoable edit
     * @throws RcvrClipboardException if the saver is given and serialization
     *         failed for some reason; NOTE!!! Delete will have succeeded!
     * @author mlh
     */
protected void deleteTasks(final AUndertaking[] tasksToDelete, ObjectSaver saver, IUndoableEditSequence editSequence) {
    @SuppressWarnings("unchecked") final Map<ITaskDesign, TaskApplication>[] assocTAs = new Map[tasksToDelete.length];
    RcvrClipboardException firstException = null;
    // Delete each task and serialize if desired
    for (int i = 0; i < tasksToDelete.length; i++) {
        assocTAs[i] = project.taskApplicationsForRemovedTask(tasksToDelete[i]);
        if (saver != null) {
            try {
                saver.saveObject(tasksToDelete[i]);
            } catch (IOException ex) {
                if (firstException != null) {
                    firstException = new RcvrClipboardException("Could not save object" + " to clipboard.", ex);
                }
            }
        }
    }
    final TaskParent[] oldParents = new TaskParent[tasksToDelete.length];
    final int[] indexes = new int[tasksToDelete.length];
    removeChildTasks(tasksToDelete, oldParents, indexes);
    // Create undo/redo step and add to undo manager
    IUndoableEdit edit = new AUndoableEdit(ProjectLID.DeleteTask) {

        protected Map<ITaskDesign, TaskApplication>[] associatedTAs = assocTAs;

        protected boolean recoverMgrs = true;

        @Override
        public String getPresentationName() {
            return (tasksToDelete.length > 1) ? DELETE_TASKS : DELETE_TASK;
        }

        @Override
        public void redo() {
            super.redo();
            recoverMgrs = true;
            for (int i = 0; i < tasksToDelete.length; i++) {
                associatedTAs[i] = project.taskApplicationsForRemovedTask(tasksToDelete[i]);
            }
            removeChildTasks(tasksToDelete, null, null);
        }

        @Override
        public void undo() {
            super.undo();
            recoverMgrs = false;
            // Un-delete children; IMPORTANT: reverse order!
            for (int i = tasksToDelete.length - 1; 0 <= i; i--) {
                // Add to old parent at old index
                oldParents[i].addUndertaking(indexes[i], tasksToDelete[i]);
                project.restoreRemovedTaskApplications(associatedTAs[i]);
            }
        }

        @Override
        public void die() {
            super.die();
            if (recoverMgrs) {
                for (int i = 0; i < tasksToDelete.length; i++) {
                    recoverManagers(tasksToDelete[i], associatedTAs[i]);
                }
            }
        }
    };
    editSequence.addEdit(edit);
    if (firstException != null) {
        throw firstException;
    }
}
Also used : ITaskDesign(edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign) RcvrClipboardException(edu.cmu.cs.hcii.cogtool.util.RcvrClipboardException) IOException(java.io.IOException) RcvrIOException(edu.cmu.cs.hcii.cogtool.util.RcvrIOException) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) TaskParent(edu.cmu.cs.hcii.cogtool.model.TaskParent) AUndoableEdit(edu.cmu.cs.hcii.cogtool.util.AUndoableEdit) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) IUndoableEdit(edu.cmu.cs.hcii.cogtool.util.IUndoableEdit) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

TaskApplication (edu.cmu.cs.hcii.cogtool.model.TaskApplication)63 AUndertaking (edu.cmu.cs.hcii.cogtool.model.AUndertaking)38 ITaskDesign (edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign)22 Design (edu.cmu.cs.hcii.cogtool.model.Design)20 Script (edu.cmu.cs.hcii.cogtool.model.Script)20 IListenerAction (edu.cmu.cs.hcii.cogtool.util.IListenerAction)17 TaskGroup (edu.cmu.cs.hcii.cogtool.model.TaskGroup)16 IPredictionAlgo (edu.cmu.cs.hcii.cogtool.model.IPredictionAlgo)15 AUndoableEdit (edu.cmu.cs.hcii.cogtool.util.AUndoableEdit)14 ProjectSelectionState (edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState)12 IOException (java.io.IOException)12 CognitiveModelGenerator (edu.cmu.cs.hcii.cogtool.model.CognitiveModelGenerator)11 Demonstration (edu.cmu.cs.hcii.cogtool.model.Demonstration)11 DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)10 IUndoableEdit (edu.cmu.cs.hcii.cogtool.util.IUndoableEdit)10 RcvrIOException (edu.cmu.cs.hcii.cogtool.util.RcvrIOException)10 APredictionResult (edu.cmu.cs.hcii.cogtool.model.APredictionResult)8 File (java.io.File)8 RcvrIllegalStateException (edu.cmu.cs.hcii.cogtool.util.RcvrIllegalStateException)7 DefaultModelGeneratorState (edu.cmu.cs.hcii.cogtool.model.DefaultModelGeneratorState)5