Search in sources :

Example 46 with TaskApplication

use of edu.cmu.cs.hcii.cogtool.model.TaskApplication 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 47 with TaskApplication

use of edu.cmu.cs.hcii.cogtool.model.TaskApplication 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)

Example 48 with TaskApplication

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

the class ProjectController method createExportScriptToCSVAction.

// Action for ExportScriptToCSV
protected IListenerAction createExportScriptToCSVAction() {
    return new IListenerAction() {

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

        public boolean performAction(Object actionParms) {
            ProjectSelectionState seln = (ProjectSelectionState) actionParms;
            Design design = seln.getSelectedDesign();
            if (design == null) {
                interaction.protestNoSelection();
                return false;
            }
            AUndertaking[] tasks = seln.getSelectedTasks(TaskSelectionState.PRUNE_SELECTION);
            if (tasks.length == 0) {
                interaction.protestNoSelection();
                return false;
            }
            // TODO: Only perform this action when one cell is selected
            // (i.e. one task is selected)
            // Also, since CogTool doesn't support multiple algorithms
            // yet, just use the first prediction algorithm in the map
            // to get the script I want; this may need to be changed.
            AUndertaking task = tasks[0];
            TaskApplication taskApp = project.getTaskApplication(task, design);
            if (taskApp == null) {
                interaction.protestNoSelection();
                return false;
            }
            Script script = taskApp.getScript(MODELGEN_ALG);
            if (script == null) {
                script = taskApp.getScript(IdentityModelGenerator.ONLY);
                if (script == null) {
                    interaction.protestNoSelection();
                    return false;
                }
            }
            return DemoScriptCmd.exportScriptToCSV(script, project, interaction, undoMgr);
        }
    };
}
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) 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)

Example 49 with TaskApplication

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

the class ProjectController method createGenerateACTRModelAction.

// createImportHumanCSVFileAction
protected IListenerAction createGenerateACTRModelAction() {
    return new IListenerAction() {

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

        public boolean performAction(Object prms) {
            ProjectSelectionState seln = (ProjectSelectionState) prms;
            // Must have selected tasks and design
            Design design = seln.getSelectedDesign();
            AUndertaking[] tasks = seln.getSelectedTasks(TaskSelectionState.PRUNE_SELECTION);
            for (AUndertaking task : tasks) {
                TaskApplication ta = project.getTaskApplication(task, design);
                Script s = DemoStateManager.ensureScript(ta, KLMCognitiveGenerator.ONLY);
                // TODO There's too much algorithm specific code
                //      in here; but for now it seems the expedient
                //      thing to do -- all this needs to be thought
                //      through for all back ends, and restructured
                String path = s.getAssociatedPath();
                String filename = null;
                if (path == null) {
                    filename = design.getName() + "-" + task.getName();
                } else {
                    filename = (new File(path)).getName();
                    if ((filename != null) && filename.endsWith(CogToolFileTypes.LISP_FILE_EXT)) {
                        filename = filename.substring(0, filename.length() - CogToolFileTypes.LISP_FILE_EXT.length());
                    }
                }
                File file = interaction.selectExportLocation(filename, CogToolFileTypes.LISP_FILE_EXT);
                if (file == null) {
                    return false;
                }
                s.setAssociatedPath(file.getAbsolutePath());
                // so we have to delete it.
                if (file.length() == 0) {
                    file.delete();
                }
                try {
                    IPredictionAlgo taAlg = ta.determineActiveAlgorithm(project);
                    if (!(taAlg instanceof ACTRPredictionAlgo)) {
                        throw new RcvrIllegalStateException("Can't generate ACT-R Model from a non ACT-R task.");
                    }
                    ACTRPredictionAlgo algo = (ACTRPredictionAlgo) taAlg;
                    algo.outputModel(design, task, s.getDemonstration().getStartFrame(), s, file, null);
                } catch (UnsupportedOperationException ex) {
                    throw new RcvrUnimplementedFnException(ex);
                } catch (IOException ex) {
                    throw new RcvrIOException(("IOException generating model file for task " + task.getName() + " in design " + design.getName()), ex);
                }
            }
            return false;
        }
    };
}
Also used : Script(edu.cmu.cs.hcii.cogtool.model.Script) IPredictionAlgo(edu.cmu.cs.hcii.cogtool.model.IPredictionAlgo) ProjectSelectionState(edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState) IOException(java.io.IOException) RcvrIOException(edu.cmu.cs.hcii.cogtool.util.RcvrIOException) RcvrIOException(edu.cmu.cs.hcii.cogtool.util.RcvrIOException) 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) RcvrIllegalStateException(edu.cmu.cs.hcii.cogtool.util.RcvrIllegalStateException) RcvrUnimplementedFnException(edu.cmu.cs.hcii.cogtool.util.RcvrUnimplementedFnException) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) File(java.io.File) ACTRPredictionAlgo(edu.cmu.cs.hcii.cogtool.model.ACTRPredictionAlgo)

Example 50 with TaskApplication

use of edu.cmu.cs.hcii.cogtool.model.TaskApplication 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)

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