Search in sources :

Example 71 with AUndertaking

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

the class ProjectController method createDuplicateTasksAction.

protected IListenerAction createDuplicateTasksAction() {
    return new IListenerAction() {

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

        public boolean performAction(Object prms) {
            TaskSelectionState seln = (TaskSelectionState) prms;
            AUndertaking[] tasks = seln.getSelectedTasks(TaskSelectionState.ORDER_SELECTION);
            // Can only duplicate if one or more tasks are selected
            if ((tasks != null) && (tasks.length > 0)) {
                String presentationName = (tasks.length > 1) ? DUPLICATE_TASKS : DUPLICATE_TASK;
                CompoundUndoableEdit editSeq = new CompoundUndoableEdit(presentationName, ProjectLID.DuplicateTask);
                AUndertaking lastDuplicate = null;
                for (AUndertaking task : tasks) {
                    TaskParent parent = project.getTaskParent(task);
                    List<AUndertaking> parentUndertakings = parent.getUndertakings();
                    int atIndex = parentUndertakings.indexOf(task) + 1;
                    lastDuplicate = duplicateTask(task, atIndex, parent, parentUndertakings, ProjectLID.DuplicateTask, presentationName, editSeq);
                }
                // Done with undo/redo steps; add the compound change
                // to the undo manager.
                editSeq.end();
                undoMgr.addEdit(editSeq);
                if (tasks.length == 1) {
                    ui.initiateTaskRename(lastDuplicate);
                }
            } else {
                interaction.protestNoSelection();
            }
            return true;
        }
    };
}
Also used : IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) TaskParent(edu.cmu.cs.hcii.cogtool.model.TaskParent) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) TaskSelectionState(edu.cmu.cs.hcii.cogtool.ui.TaskSelectionState) CompoundUndoableEdit(edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint)

Example 72 with AUndertaking

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

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

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

the class ProjectController method createNewTaskGroupAction.

// createNewTaskUndo
// Action for NewTaskGroup
protected IListenerAction createNewTaskGroupAction() {
    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.PRUNE_SELECTION | TaskSelectionState.ORDER_SELECTION);
            TaskGroup newGroup = null;
            if ((selectedTasks == null) || (selectedTasks.length == 0)) {
                String newGroupName = computeNewTaskName(project, DEFAULT_TASK_GROUP_PREFIX);
                // No task selection -- add a new root task group
                newGroup = addTaskGroup(project, project.getUndertakings().size(), newGroupName, selectedTasks);
            } else {
                // One selected task: create new group at selected position
                // Multiple selected tasks:
                //   if all tasks have same parent,
                //          create new group after last selection
                //   if tasks do not have same parent,
                //          add new root group after last selected root
                //          but, if no selected root, new root at end
                // Get parent
                TaskGroup parent = selection.getSelectedTaskParent();
                if (parent == null) {
                    String newGroupName = computeNewTaskName(project, DEFAULT_TASK_GROUP_PREFIX);
                    newGroup = addTaskGroup(project, findLastSelectedRoot(selectedTasks), newGroupName, selectedTasks);
                } else {
                    String newGroupName = computeNewTaskName(parent, DEFAULT_TASK_GROUP_PREFIX);
                    AUndertaking last = selectedTasks[selectedTasks.length - 1];
                    newGroup = addTaskGroup(parent, parent.getUndertakings().indexOf(last) + 1, newGroupName, selectedTasks);
                }
            }
            // Task is automatically selected when added -- rename
            // Cannot put this into the ui because of undo/redo
            ui.initiateTaskRename(newGroup);
            return true;
        }
    };
}
Also used : 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 75 with AUndertaking

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

the class ProjectController method assignActions.

/**
     * Registers the set of <code>IListenerAction</code> instances
     * that implement the semantic actions that are possible.
     * <p>
     * For this class, this consists of the actions for a project editor.
     *
     * @author mlh
     */
@Override
public void assignActions() {
    super.assignActions();
    ui.setAction(ProjectLID.Undo, new UndoController.UndoAction(undoMgr, interaction));
    ui.setAction(ProjectLID.Redo, new UndoController.RedoAction(undoMgr, interaction));
    ui.setAction(ProjectLID.DeselectAll, new IListenerAction() {

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

        public boolean performAction(Object prms) {
            SelectionState selection = (SelectionState) prms;
            selection.deselectAll();
            return true;
        }
    });
    ui.setAction(ProjectLID.CopyResultsToClipboard, createCopyResultsAction());
    ui.setAction(ProjectLID.Paste, createPasteAction());
    ui.setAction(ProjectLID.CaptureBehavior, createCaptureAction());
    ui.setAction(ProjectLID.CopyDesign, createCopyDesignAction());
    ui.setAction(ProjectLID.CopyTask, createCopyTaskAction());
    ui.setAction(ProjectLID.CutDesign, createCutDesignAction());
    ui.setAction(ProjectLID.CutTask, createCutTaskAction());
    ui.setAction(ProjectLID.SelectAll, new AListenerAction() {

        public boolean performAction(Object prms) {
            ui.selectAllTasks();
            return true;
        }
    });
    ui.setAction(ProjectLID.NewDesign, createNewDesignAction());
    ui.setAction(ProjectLID.NewDesignFromImport, createNewDesignForImport());
    ui.setAction(ProjectLID.AddDesignDevices, createAddDesignDevicesAction());
    ui.setAction(ProjectLID.NewProjectNewDesign, createNameProjectNewDesignAction());
    ui.setAction(ProjectLID.EditDesign, createEditDesignAction());
    ui.setAction(ProjectLID.EditTask, new IListenerAction() {

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

        public boolean performAction(Object prms) {
            TaskSelectionState selection = (TaskSelectionState) prms;
            int selectedTaskCount = selection.getSelectedTaskCount();
            if (selectedTaskCount == 1) {
                AUndertaking selectedTask = selection.getSelectedTask();
                ui.initiateTaskRename(selectedTask);
                return true;
            }
            if (selectedTaskCount == 0) {
                interaction.protestNoSelection();
            } else {
                interaction.protestTooManySelectedTasks();
            }
            return false;
        }
    });
    ui.setAction(ProjectLID.RenameDesign, createRenameDesignAction());
    ui.setAction(ProjectLID.InitiateTaskRename, createInitiateTaskRenameAction());
    ui.setAction(ProjectLID.HCIPARenameTask, new IListenerAction() {

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

        public boolean performAction(Object prms) {
            ProjectUI.TaskRenameEvent evt = (ProjectUI.TaskRenameEvent) prms;
            return hcipaRenameTask(evt.task, evt.task.getName(), evt.newName);
        }
    });
    ui.setAction(ProjectLID.RenameTask, new IListenerAction() {

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

        public boolean performAction(Object prms) {
            ProjectUI.TaskRenameEvent evt = (ProjectUI.TaskRenameEvent) prms;
            return renameTask(evt.task, evt.task.getName(), evt.newName, evt.parent);
        }
    });
    ui.setAction(ProjectLID.EditScript, createScriptEditorAction());
    ui.setAction(ProjectLID.ViewGroupScript, createScriptViewerAction());
    ui.setAction(ProjectLID.DeleteDesign, createDeleteDesignAction());
    ui.setAction(ProjectLID.DeleteTask, createDeleteTaskAction());
    ui.setAction(ProjectLID.NewTask, createNewTaskAction());
    ui.setAction(ProjectLID.NewTaskGroup, createNewTaskGroupAction());
    ui.setAction(ProjectLID.ReorderDesigns, createReorderDesignsAction());
    ui.setAction(ProjectLID.ShowSum, createShowNatureAction(GroupNature.SUM, ProjectLID.ShowSum));
    ui.setAction(ProjectLID.ShowMean, createShowNatureAction(GroupNature.MEAN, ProjectLID.ShowMean));
    ui.setAction(ProjectLID.ShowMin, createShowNatureAction(GroupNature.MIN, ProjectLID.ShowMin));
    ui.setAction(ProjectLID.ShowMax, createShowNatureAction(GroupNature.MAX, ProjectLID.ShowMax));
    ui.setAction(ProjectLID.RegenerateScript, createRegenerateScriptAction());
    ui.setAction(ProjectLID.RecomputeScript, createRecomputeScriptAction());
    ui.setAction(ProjectLID.ShowModelVisualization, createShowModelVisualizationAction());
    ui.setAction(ProjectLID.DisplayTraces, createDisplayTraces());
    ui.setAction(ProjectLID.ExportTraces, createExportTraces());
    ui.setAction(ProjectLID.ExportForSanlab, createExportForSanlab());
    ui.setAction(ProjectLID.ExportActrModelFile, createExportActrModelFile());
    ui.setAction(ProjectLID.ExportDesignToHTML, createExportDesignToHTMLAction());
    ui.setAction(ProjectLID.ExportToHCIPA, createExportToHCIPAAction());
    ui.setAction(ProjectLID.ExportResultsToCSV, createExportResultsToCSVAction());
    ui.setAction(ProjectLID.ImportXML, createImportAction());
    /*for(CogToolLID lid : ProjectLID.getCollection())
        {
            this.ui.setAction(lid,
                              createImportAction());
        }*/
    /*this.ui.setAction(ProjectLID.ImportXML,
        new IListenerAction() {

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

<<<<<<< .mine

          public boolean performAction(Object prms)
          {
              Class convClass =  (Class)prms;

              createImportAction(convClass);
              return true;
          }
      });*/
    ui.setAction(ProjectLID.ImportWebCrawl, createImportWebCrawlAction());
    ui.setAction(ProjectLID.ExportScriptToCSV, createExportScriptToCSVAction());
    ui.setAction(ProjectLID.ExportToXML, createExportDesignToXML());
    ui.setAction(ProjectLID.DuplicateDesign, createDuplicateDesignAction());
    ui.setAction(ProjectLID.DuplicateTask, createDuplicateTasksAction());
    ui.setAction(ProjectLID.ImportHumanCSVFile, createImportHumanCSVFileAction());
    ui.setAction(ProjectLID.SetAlgorithmACTR6, createSetAlgorithmAction(ACTR6PredictionAlgo.ONLY, ProjectLID.SetAlgorithmACTR6, SET_ALG_ACTR6));
    ui.setAction(ProjectLID.SetAlgorithmSNIFACT, createSetAlgorithmAction(SNIFACTPredictionAlgo.ONLY, ProjectLID.SetAlgorithmSNIFACT, SET_ALG_SNIFACT));
    ui.setAction(ProjectLID.SetAlgorithmHuman, createSetAlgorithmHumanAction());
    ui.setAction(ProjectLID.EditACTRModelFile, createEditACTRModelAction());
    ui.setAction(ProjectLID.SetBackgroundComputationDefault, createSetBackgroundComputeAction(TaskApplication.USE_PROJECT_DEFAULT, ProjectLID.SetBackgroundComputationDefault, SET_RUN_PROJECT_DEFAULT));
    ui.setAction(ProjectLID.SetBackgroundComputationTrue, createSetBackgroundComputeAction(TaskApplication.RUN_IN_BACKGROUND, ProjectLID.SetBackgroundComputationTrue, SET_RUN_BACKGROUND));
    ui.setAction(ProjectLID.SetBackgroundComputationFalse, createSetBackgroundComputeAction(TaskApplication.RUN_IN_FOREGROUND, ProjectLID.SetBackgroundComputationFalse, SET_RUN_FOREGROUND));
    ui.setAction(ProjectLID.GenerateACTRModelFile, createGenerateACTRModelAction());
    ui.setAction(ProjectLID.SetProjDefaultAlgoACTR, createSetProjDefaultAlg(ProjectLID.SetProjDefaultAlgoACTR, SET_PROJ_DEFAULT_ACTR, ACTR6PredictionAlgo.ONLY));
    ui.setAction(ProjectLID.SetProjDefaultAlgoSNIFACT, createSetProjDefaultAlg(ProjectLID.SetProjDefaultAlgoSNIFACT, SET_PROJ_DEFAULT_SNIFACT, SNIFACTPredictionAlgo.ONLY));
    ui.setAction(ProjectLID.SetProjExecBackground, createSetProjDefaultExecBkg(ProjectLID.SetProjExecBackground, SET_RUN_BKG_DEFAULT, true));
    ui.setAction(ProjectLID.SetProjExecForeground, createSetProjDefaultExecBkg(ProjectLID.SetProjExecForeground, SET_RUN_FG_DEFAULT, false));
    ui.setAction(ProjectLID.ChangeTaskPosition, createChangeTaskPositionAction());
    ui.setAction(ProjectLID.DuplicateTaskFull, createDuplicateTaskFullAction());
    ui.setAction(ProjectLID.Ungroup, createUngroupAction());
    ui.setAction(ProjectLID.PromoteTask, createPromoteTaskAction());
    ui.setAction(ProjectLID.DemoteTask, createDemoteTaskAction());
    ui.setAction(ProjectLID.MoveTaskEarlier, createMoveTaskEarlierAction());
    ui.setAction(ProjectLID.MoveTaskLater, createMoveTaskLaterAction());
    ui.setAction(ProjectLID.GenerateDictionary, createGenerateDictionaryAction());
    ui.setAction(ProjectLID.EditDictionary, createOpenDictionaryAction());
    ui.setAction(ProjectLID.ExportDictToCSV, createExportDictionaryAction());
    ui.setAction(ProjectLID.ImportDict, createImportDictionaryAction());
    ui.setAction(ProjectLID.MoveTaskApplication, createMoveTaskAppAction());
    ui.setAction(ProjectLID.DuplicateTaskApplication, createDuplicateTaskAppAction());
}
Also used : ProjectUI(edu.cmu.cs.hcii.cogtool.ui.ProjectUI) IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) AListenerAction(edu.cmu.cs.hcii.cogtool.util.AListenerAction) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) TaskSelectionState(edu.cmu.cs.hcii.cogtool.ui.TaskSelectionState) TaskSelectionState(edu.cmu.cs.hcii.cogtool.ui.TaskSelectionState) ProjectSelectionState(edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState) SelectionState(edu.cmu.cs.hcii.cogtool.ui.SelectionState) DesignSelectionState(edu.cmu.cs.hcii.cogtool.ui.DesignSelectionState) ProjectContextSelectionState(edu.cmu.cs.hcii.cogtool.ui.ProjectContextSelectionState)

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