Search in sources :

Example 76 with AUndertaking

use of edu.cmu.cs.hcii.cogtool.model.AUndertaking 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;
}
Also used : TaskParent(edu.cmu.cs.hcii.cogtool.model.TaskParent) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) AUndoableEdit(edu.cmu.cs.hcii.cogtool.util.AUndoableEdit) IUndoableEdit(edu.cmu.cs.hcii.cogtool.util.IUndoableEdit) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint)

Example 77 with AUndertaking

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

the class ProjectController method createSetAlgorithmAction.

protected IListenerAction createSetAlgorithmAction(final IPredictionAlgo alg, final CogToolLID lid, final String actionString) {
    return new IListenerAction() {

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

        public boolean performAction(Object actionParms) {
            ProjectSelectionState selState = (ProjectSelectionState) actionParms;
            Design design = selState.getSelectedDesign();
            AUndertaking[] tasks = selState.getSelectedTasks(TaskSelectionState.PRUNE_SELECTION);
            DemoStateManager demoMgr = DemoStateManager.getStateManager(project, design);
            // iterate through tasks and get set of TaskApplications
            final TaskApplication[] taskApps = new TaskApplication[tasks.length];
            final IPredictionAlgo[] oldAlgos = new IPredictionAlgo[tasks.length];
            for (int i = 0; i < tasks.length; i++) {
                // Make sure that the task application exists, and create it
                // if it does not.  No need to ensure a script.
                TaskApplication ta = ensureTaskApplication(tasks[i], design, null, demoMgr);
                taskApps[i] = ta;
                oldAlgos[i] = ta.getActiveAlgorithm();
                // now set the new algorithm
                ta.setActiveAlgorithm(alg);
            }
            undoMgr.addEdit(new AUndoableEdit(lid) {

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

                @Override
                public void redo() {
                    super.redo();
                    for (TaskApplication taskApp : taskApps) {
                        taskApp.setActiveAlgorithm(alg);
                    }
                }

                @Override
                public void undo() {
                    super.undo();
                    for (int i = 0; i < taskApps.length; i++) {
                        taskApps[i].setActiveAlgorithm(oldAlgos[i]);
                    }
                }
            });
            return true;
        }
    };
}
Also used : IPredictionAlgo(edu.cmu.cs.hcii.cogtool.model.IPredictionAlgo) ProjectSelectionState(edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) Design(edu.cmu.cs.hcii.cogtool.model.Design) ITaskDesign(edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign) IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) AUndoableEdit(edu.cmu.cs.hcii.cogtool.util.AUndoableEdit) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication)

Example 78 with AUndertaking

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

the class ProjectController method createScriptViewerAction.

protected IListenerAction createScriptViewerAction() {
    return new IListenerAction() {

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

        public boolean performAction(Object prms) {
            if (prms != null) {
                ProjectSelectionState seln = (ProjectSelectionState) prms;
                // Must have selected tasks and design
                Design design = seln.getSelectedDesign();
                AUndertaking[] tasks = seln.getSelectedTasks(TaskSelectionState.PRUNE_SELECTION);
                if ((design == null) || (tasks == null) || (tasks.length == 0)) {
                    return false;
                }
                boolean viewSuccessful = false;
                // Viewing a script only applies to task groups
                for (AUndertaking task : tasks) {
                    if (task.isTaskGroup()) {
                        TaskGroup group = (TaskGroup) task;
                        List<AUndertaking> childTasks = group.getUndertakings();
                        if (childTasks.size() > 0) {
                            AUndertaking firstTask = childTasks.get(0);
                            TaskApplication ta = project.getTaskApplication(firstTask, design);
                            if (ta != null) {
                                ITaskDesign td = project.getTaskDesign(task, design);
                                ScriptViewerController.openController(td, project);
                                viewSuccessful = true;
                            }
                        }
                    }
                }
                if (!viewSuccessful) {
                    interaction.setStatusMessage(L10N.get("PC.NoScriptsToView", "No scripts to view."));
                }
                return true;
            }
            interaction.protestNoSelection();
            return false;
        }
    };
}
Also used : Design(edu.cmu.cs.hcii.cogtool.model.Design) ITaskDesign(edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign) ITaskDesign(edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign) IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) ProjectSelectionState(edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) TaskGroup(edu.cmu.cs.hcii.cogtool.model.TaskGroup)

Example 79 with AUndertaking

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

the class ProjectController method createSetBackgroundComputeAction.

protected IListenerAction createSetBackgroundComputeAction(final Boolean bkg, final ProjectLID lid, final String actionName) {
    return new IListenerAction() {

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

        public boolean performAction(Object actionParms) {
            ProjectSelectionState selState = (ProjectSelectionState) actionParms;
            Design design = selState.getSelectedDesign();
            AUndertaking[] tasks = selState.getSelectedTasks(TaskSelectionState.PRUNE_SELECTION);
            // iterate through tasks and get set of TaskApplications
            final TaskApplication[] taskApps = new TaskApplication[tasks.length];
            final Boolean[] oldBkgSettings = new Boolean[tasks.length];
            DemoStateManager demoMgr = DemoStateManager.getStateManager(project, design);
            for (int i = 0; i < tasks.length; i++) {
                // Make sure that the task application exists, and create it
                // if it does not.  No need to ensure a script.
                TaskApplication ta = ensureTaskApplication(tasks[i], design, null, demoMgr);
                taskApps[i] = ta;
                oldBkgSettings[i] = ta.getComputeInBackground();
                // now set the compute in background flag
                ta.setComputeInBackground(bkg);
            }
            undoMgr.addEdit(new AUndoableEdit(lid) {

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

                @Override
                public void redo() {
                    super.redo();
                    for (TaskApplication taskApp : taskApps) {
                        taskApp.setComputeInBackground(bkg);
                    }
                }

                @Override
                public void undo() {
                    super.undo();
                    for (int i = 0; i < taskApps.length; i++) {
                        taskApps[i].setComputeInBackground(oldBkgSettings[i]);
                    }
                }
            });
            return true;
        }
    };
}
Also used : ProjectSelectionState(edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) Design(edu.cmu.cs.hcii.cogtool.model.Design) ITaskDesign(edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign) IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) AUndoableEdit(edu.cmu.cs.hcii.cogtool.util.AUndoableEdit) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication)

Example 80 with AUndertaking

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

the class ProjectController method importDesign.

protected void importDesign(TaskParent parent, DesignSelectionState prms, Design newDesign, Collection<Demonstration> demonstrations, Set<AUndertaking> newUndertakings, IUndoableEditSequence editSeq) {
    makeDesignNameUnique(newDesign);
    ProjectCmd.addNewDesign(project, newDesign, prms.getSelectedDesign(), importXMLPresentation, editSeq);
    // Add taskapplications/tasks as well for demonstrations
    if ((demonstrations != null) && (demonstrations.size() > 0)) {
        DemoStateManager demoMgr = DemoStateManager.getStateManager(project, newDesign);
        Iterator<Demonstration> demoIt = demonstrations.iterator();
        while (demoIt.hasNext()) {
            Demonstration demo = demoIt.next();
            TaskApplication taskApp = demo.getTaskApplication();
            AUndertaking demoTask = taskApp.getTask();
            if (demoTask.getTaskGroup() == null && !newUndertakings.contains(demoTask)) {
                // If the taskApp's task is not already part of the
                // project, add it.  Regardless, any project root task
                // with the same name should be the same at this point!
                AUndertaking rootTask = parent.getUndertaking(demoTask.getName());
                if (rootTask == null) {
                    parent.addUndertaking(demoTask);
                    editSeq.addEdit(createNewTaskUndo(parent, Project.AT_END, demoTask, ProjectLID.ImportXML, importXMLPresentation));
                } else if (rootTask != demoTask) {
                    throw new RcvrIllegalStateException("Unexpected root task difference");
                }
            }
            project.setTaskApplication(taskApp);
            demoMgr.trackEdits(demo);
        }
    }
}
Also used : RcvrIllegalStateException(edu.cmu.cs.hcii.cogtool.util.RcvrIllegalStateException) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) Demonstration(edu.cmu.cs.hcii.cogtool.model.Demonstration)

Aggregations

AUndertaking (edu.cmu.cs.hcii.cogtool.model.AUndertaking)89 TaskApplication (edu.cmu.cs.hcii.cogtool.model.TaskApplication)38 TaskGroup (edu.cmu.cs.hcii.cogtool.model.TaskGroup)35 IListenerAction (edu.cmu.cs.hcii.cogtool.util.IListenerAction)30 Design (edu.cmu.cs.hcii.cogtool.model.Design)28 ITaskDesign (edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign)24 DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)18 ProjectSelectionState (edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState)17 AUndoableEdit (edu.cmu.cs.hcii.cogtool.util.AUndoableEdit)14 Script (edu.cmu.cs.hcii.cogtool.model.Script)13 CompoundUndoableEdit (edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit)13 IOException (java.io.IOException)12 TaskSelectionState (edu.cmu.cs.hcii.cogtool.ui.TaskSelectionState)11 IPredictionAlgo (edu.cmu.cs.hcii.cogtool.model.IPredictionAlgo)10 IUndoableEdit (edu.cmu.cs.hcii.cogtool.util.IUndoableEdit)10 RcvrIOException (edu.cmu.cs.hcii.cogtool.util.RcvrIOException)10 Demonstration (edu.cmu.cs.hcii.cogtool.model.Demonstration)9 TaskParent (edu.cmu.cs.hcii.cogtool.model.TaskParent)9 TreeItem (org.eclipse.swt.widgets.TreeItem)9 ArrayList (java.util.ArrayList)7