Search in sources :

Example 66 with AUndertaking

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

the class HCIPACmd method updateLabels.

public static IUndoableEdit updateLabels(final TaskGroup group, final String newName, final String undoRenameLabel) {
    final String oldName = group.getName();
    final AUndertaking t = group.getUndertakings().get(0);
    group.setName(newName);
    t.setName(IDENTIFY_LABEL + newName);
    return new AUndoableEdit(ProjectLID.HCIPARenameTask) {

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

        @Override
        public void redo() {
            super.redo();
            group.setName(newName);
            t.setName(IDENTIFY_LABEL + newName);
        }

        @Override
        public void undo() {
            super.undo();
            group.setName(oldName);
            t.setName(IDENTIFY_LABEL + oldName);
        }
    };
}
Also used : AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) AUndoableEdit(edu.cmu.cs.hcii.cogtool.util.AUndoableEdit)

Example 67 with AUndertaking

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

the class ProjectController method createDuplicateTaskAppAction.

protected IListenerAction createDuplicateTaskAppAction() {
    return new IListenerAction() {

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

        public boolean performAction(Object p) {
            if (p != null) {
                ProjectUI.MoveCopyTaskApplicationParms parms = (ProjectUI.MoveCopyTaskApplicationParms) p;
                // Must have selected tasks and design
                if ((parms.design == null) || (parms.fromTask == null) || (parms.toTask == null)) {
                    interaction.protestNoSelection();
                    return false;
                }
                final AUndertaking fromTask = parms.fromTask;
                final AUndertaking toTask = parms.toTask;
                TaskApplication taskApp = project.getTaskApplication(fromTask, parms.design);
                if (taskApp == null) {
                    interaction.protestNoTaskApplication();
                    return false;
                }
                final TaskApplication oldTaskApp = project.removeTaskApplication(parms.toTask, parms.design);
                final TaskApplication newTaskApp = taskApp.duplicate(toTask, parms.design);
                DemoStateManager demoMgr = DemoStateManager.getStateManager(project, parms.design);
                project.setTaskApplication(newTaskApp);
                demoMgr.trackEdits(newTaskApp.getDemonstration());
                IUndoableEdit edit = new AUndoableEdit(ProjectLID.DuplicateTaskApplication) {

                    protected boolean recoverMgrs = false;

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

                    @Override
                    public void redo() {
                        super.redo();
                        if (oldTaskApp != null) {
                            project.removeTaskApplication(oldTaskApp);
                        }
                        project.setTaskApplication(newTaskApp);
                        recoverMgrs = false;
                    }

                    @Override
                    public void undo() {
                        super.undo();
                        project.removeTaskApplication(newTaskApp);
                        if (oldTaskApp != null) {
                            project.setTaskApplication(oldTaskApp);
                        }
                        recoverMgrs = true;
                    }

                    @Override
                    public void die() {
                        if (recoverMgrs) {
                            recoverManagers(newTaskApp);
                        }
                    }
                };
                undoMgr.addEdit(edit);
            }
            return true;
        }
    };
}
Also used : ProjectUI(edu.cmu.cs.hcii.cogtool.ui.ProjectUI) 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) IUndoableEdit(edu.cmu.cs.hcii.cogtool.util.IUndoableEdit)

Example 68 with AUndertaking

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

the class ProjectController method duplicateTaskApplications.

protected void duplicateTaskApplications(TaskGroup originalGroup, TaskGroup groupCopy) {
    Iterator<AUndertaking> originalChildren = originalGroup.getUndertakings().iterator();
    Iterator<AUndertaking> copyChildren = groupCopy.getUndertakings().iterator();
    // Iterate in parallel
    while (originalChildren.hasNext() && copyChildren.hasNext()) {
        AUndertaking originalTask = originalChildren.next();
        AUndertaking taskCopy = copyChildren.next();
        if (originalTask instanceof TaskGroup) {
            duplicateTaskApplications((TaskGroup) originalTask, (TaskGroup) taskCopy);
        } else {
            duplicateTaskApplications(originalTask, taskCopy);
        }
    }
}
Also used : AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) TaskGroup(edu.cmu.cs.hcii.cogtool.model.TaskGroup)

Example 69 with AUndertaking

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

the class ProjectController method recomputeScripts.

protected boolean recomputeScripts(ProjectSelectionState seln) {
    Design design = seln.getSelectedDesign();
    AUndertaking[] tasks = seln.getSelectedTasks(TaskSelectionState.PRUNE_SELECTION);
    ComputeMessages computeMsgs = new ComputeMessages();
    String editLabel = ui.hasMultipleScripts(seln) ? RECOMPUTE_SCRIPTS : RECOMPUTE_SCRIPT;
    CompoundUndoableEdit editSequence = new CompoundUndoableEdit(editLabel, ProjectLID.RecomputeScript);
    editSequence.setManager(undoMgr);
    if (design != null) {
        DemoStateManager demoStateMgr = DemoStateManager.getStateManager(project, design);
        if ((tasks != null) && (tasks.length > 0)) {
            for (int i = 0; i < tasks.length; i++) {
                if (!recomputeScripts(tasks[i], design, demoStateMgr, computeMsgs, editSequence)) {
                    return false;
                }
            }
        } else {
            Iterator<AUndertaking> allTasks = project.getUndertakings().iterator();
            while (allTasks.hasNext()) {
                if (!recomputeScripts(allTasks.next(), design, demoStateMgr, computeMsgs, editSequence)) {
                    return false;
                }
            }
        }
    } else if ((tasks != null) && (tasks.length > 0)) {
        for (int i = 0; i < tasks.length; i++) {
            Iterator<Design> allDesigns = project.getDesigns().iterator();
            while (allDesigns.hasNext()) {
                design = allDesigns.next();
                DemoStateManager demoStateMgr = DemoStateManager.getStateManager(project, design);
                if (!recomputeScripts(tasks[i], design, demoStateMgr, computeMsgs, editSequence)) {
                    return false;
                }
            }
        }
    }
    if (editSequence.isSignificant()) {
        editSequence.end();
        undoMgr.addEdit(editSequence);
    }
    computeMsgs.presentMessages();
    return true;
}
Also used : Design(edu.cmu.cs.hcii.cogtool.model.Design) ITaskDesign(edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) Iterator(java.util.Iterator) CompoundUndoableEdit(edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint)

Example 70 with AUndertaking

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

the class ProjectController method createScriptEditorAction.

// Action for EditScript
protected IListenerAction createScriptEditorAction() {
    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;
                }
                DemoStateManager demoMgr = DemoStateManager.getStateManager(project, design);
                // Editing a script only applies to tasks, not task groups
                for (int i = 0; i < tasks.length; i++) {
                    if (!tasks[i].isTaskGroup()) {
                        CognitiveModelGenerator gen = MODELGEN_ALG;
                        TaskGroup group = tasks[i].getTaskGroup();
                        if (group != null) {
                            Object isSnifAct = group.getAttribute(WidgetAttributes.SNIFACT_CONTEXT_ATTR);
                            if (isSnifAct != null) {
                                gen = IdentityModelGenerator.ONLY;
                            }
                        }
                        // If no script set exists for this cell, create
                        TaskApplication ta = ensureTaskApplication(tasks[i], design, gen, demoMgr);
                        Demonstration demo = ta.getDemonstration();
                        if (CogToolPref.HCIPA.getBoolean()) {
                            HCIPACmd.checkStartFrame(project, ta, gen);
                        }
                        // Determine which window to open/create
                        if ((demo.getStartFrame() == null) || !demo.isStartFrameChosen()) {
                            // No start frame; present ui to choose one
                            SEFrameChooserController.openController(ta, gen, project);
                        } else {
                            // Start frame chosen; go straight to demo ui
                            try {
                                SEDemoController.openController(ta, gen, project);
                            } catch (GraphicsUtil.ImageException ex) {
                                interaction.protestInvalidImageFile();
                            }
                        }
                    }
                // Else do nothing when a TaskGroup cell is "edited"
                }
                return true;
            }
            interaction.protestNoSelection();
            return false;
        }
    };
}
Also used : ProjectSelectionState(edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState) CognitiveModelGenerator(edu.cmu.cs.hcii.cogtool.model.CognitiveModelGenerator) 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) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) GraphicsUtil(edu.cmu.cs.hcii.cogtool.util.GraphicsUtil) Demonstration(edu.cmu.cs.hcii.cogtool.model.Demonstration) TaskGroup(edu.cmu.cs.hcii.cogtool.model.TaskGroup)

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