Search in sources :

Example 31 with TaskGroup

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

the class ProjectController method createImportAction.

protected IListenerAction createImportAction() {
    return new IListenerAction() {

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

        public boolean performAction(Object prms) {
            boolean computeScripts = CogToolPref.COMPSCR.getBoolean();
            if (importFile == null) {
                importFile = interaction.selectXMLFile(true, null);
            } else {
                computeScripts = importFileComputes;
            }
            if (importFile == null) {
                return false;
            }
            CompoundUndoableEdit editSeq = new CompoundUndoableEdit(importXMLPresentation, ProjectLID.ImportXML);
            Map<Design, Collection<Demonstration>> parsedDesigns = null;
            Set<AUndertaking> newUndertakings = null;
            TaskParent parent = project;
            try {
                if (CogToolPref.HCIPA.getBoolean()) {
                    TaskGroup importGroup = new TaskGroup(importFile.getName(), GroupNature.SUM);
                    parent = importGroup;
                    project.addUndertaking(importGroup);
                    editSeq.addEdit(createNewTaskUndo(project, Project.AT_END, importGroup, ProjectLID.ImportXML, importXMLPresentation));
                }
                ImportCogToolXML importer = new ImportCogToolXML();
                if (!importer.importXML(importFile, parent, MODELGEN_ALG) || (importer.getDesigns().size() == 0)) {
                    List<String> errors = importer.getObjectFailures();
                    if ((errors != null) && (errors.size() > 0)) {
                        interaction.reportProblems(importXMLPresentation, errors);
                    } else {
                        interaction.reportProblem(importXMLPresentation, xmlParseFailed);
                    }
                    return false;
                }
                List<String> warnings = importer.getGenerationWarnings();
                if (warnings.size() > 0) {
                    interaction.reportWarnings(importXMLPresentation, warnings);
                }
                parsedDesigns = importer.getDesigns();
                newUndertakings = importer.getNewUndertakings();
            } catch (ImportCogToolXML.ImportFailedException ex) {
                throw new RcvrXMLParsingException("Missing XML component", ex);
            } catch (GraphicsUtil.ImageException ex) {
                throw new RcvrImageException("Image error during loading XML", ex);
            } catch (IOException ex) {
                throw new RcvrXMLParsingException("IO error loading XML", ex);
            } catch (SAXException ex) {
                throw new RcvrXMLParsingException("Error parsing XML", ex);
            } catch (SecurityException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IllegalArgumentException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } finally {
                importFile = null;
                importFileComputes = false;
            }
            for (AUndertaking u : newUndertakings) {
                parent.addUndertaking(u);
                final AUndertaking uu = u;
                final TaskParent pp = parent;
                editSeq.addEdit(new AUndoableEdit(ProjectLID.ImportXML) {

                    @Override
                    public void redo() {
                        super.redo();
                        pp.addUndertaking(uu);
                    }

                    @Override
                    public void undo() {
                        super.undo();
                        pp.removeUndertaking(uu);
                    }
                });
            }
            Iterator<Map.Entry<Design, Collection<Demonstration>>> designDemos = parsedDesigns.entrySet().iterator();
            while (designDemos.hasNext()) {
                Map.Entry<Design, Collection<Demonstration>> entry = designDemos.next();
                importDesign(parent, (DesignSelectionState) prms, entry.getKey(), entry.getValue(), newUndertakings, editSeq);
            }
            editSeq.end();
            undoMgr.addEdit(editSeq);
            if (computeScripts) {
                //compute predictions for imported project
                ProjectContextSelectionState seln = new ProjectContextSelectionState(project);
                seln.addSelectedDesigns(project.getDesigns());
                ui.selectAllTasks();
                recomputeScripts(seln);
                ui.deselectAllTasks();
            }
            return true;
        }
    };
}
Also used : ProjectContextSelectionState(edu.cmu.cs.hcii.cogtool.ui.ProjectContextSelectionState) SAXException(org.xml.sax.SAXException) Design(edu.cmu.cs.hcii.cogtool.model.Design) ITaskDesign(edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign) URLCrawlEntry(edu.cmu.cs.hcii.cogtool.model.URLCrawlEntry) ImportCogToolXML(edu.cmu.cs.hcii.cogtool.model.ImportCogToolXML) IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) RcvrImageException(edu.cmu.cs.hcii.cogtool.util.RcvrImageException) TaskParent(edu.cmu.cs.hcii.cogtool.model.TaskParent) AUndoableEdit(edu.cmu.cs.hcii.cogtool.util.AUndoableEdit) ProjectSelectionState(edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState) CompoundUndoableEdit(edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit) IOException(java.io.IOException) RcvrIOException(edu.cmu.cs.hcii.cogtool.util.RcvrIOException) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) Collection(java.util.Collection) GraphicsUtil(edu.cmu.cs.hcii.cogtool.util.GraphicsUtil) RcvrXMLParsingException(edu.cmu.cs.hcii.cogtool.util.RcvrXMLParsingException) Demonstration(edu.cmu.cs.hcii.cogtool.model.Demonstration) TaskGroup(edu.cmu.cs.hcii.cogtool.model.TaskGroup) Map(java.util.Map) HashMap(java.util.HashMap)

Example 32 with TaskGroup

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

the class SEDemoController method insertStep.

protected boolean insertStep(final AScriptStep newDemoStep, AScriptStep beforeStep, CogToolLID lid, final String presentationName) {
    Set<AScriptStep> newDemoSteps = Collections.singleton(newDemoStep);
    Set<AScriptStep> emptyDemoSteps = // None are being replaced!
    new HashSet<AScriptStep>();
    Demonstration demo = script.getDemonstration();
    final int atIndex = demo.insertStep(newDemoStep, beforeStep);
    final Collection<ComputationUndoRedo> scriptsUndoRedos = DemoScriptCmd.regenerateScripts(demo, atIndex, beforeStep, interaction);
    if (CogToolPref.HCIPA.getBoolean()) {
        TaskApplication ta = script.getDemonstration().getTaskApplication();
        AUndertaking t = ta.getTask();
        Design d = ta.getDesign();
        // Starting with the script after t, update all of the scripts in
        // the task group to reflect the new state
        TaskGroup grp = t.getTaskGroup();
        if (grp != null) {
            List<AUndertaking> tasks = grp.getUndertakings();
            int startIndex = tasks.indexOf(t);
            Script prevScript = script;
            for (int i = startIndex + 1; i < tasks.size(); i++) {
                t = tasks.get(i);
                ta = project.getTaskApplication(t, d);
                if (ta == null) {
                    continue;
                }
                Script s = ta.getScript(script.getModelGenerator());
                Demonstration curDemo = s.getDemonstration();
                HCIPACmd.copyState(prevScript, curDemo);
                scriptsUndoRedos.addAll(DemoScriptCmd.regenerateScripts(curDemo, 0, curDemo.getStepAt(0), interaction));
                prevScript = s;
            }
        }
    }
    IUndoableEdit edit = new DemoStateManager.ADemoUndoableEdit(lid, demo, newDemoSteps, emptyDemoSteps, demoStateMgr) {

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

        @Override
        public void redo() {
            super.redo();
            demo.insertStep(newDemoStep, atIndex);
            DemoScriptCmd.redoAllChanges(scriptsUndoRedos);
        }

        @Override
        public void undo() {
            super.undo();
            demo.removeStep(atIndex);
            DemoScriptCmd.undoAllChanges(scriptsUndoRedos);
        }
    };
    CompoundUndoableEdit editSequence = new CompoundUndoableEdit(presentationName, lid);
    editSequence.addEdit(edit);
    if (CogToolPref.REGENERATE_AUTOMATICALLY.getBoolean()) {
        DemoScriptCmd.regenerateScripts(project, demo, demoStateMgr, interaction, editSequence);
    }
    editSequence.end();
    undoMgr.addEdit(editSequence);
    return true;
}
Also used : Script(edu.cmu.cs.hcii.cogtool.model.Script) ComputationUndoRedo(edu.cmu.cs.hcii.cogtool.controller.DemoScriptCmd.ComputationUndoRedo) CompoundUndoableEdit(edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit) AScriptStep(edu.cmu.cs.hcii.cogtool.model.AScriptStep) Design(edu.cmu.cs.hcii.cogtool.model.Design) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) IUndoableEdit(edu.cmu.cs.hcii.cogtool.util.IUndoableEdit) Demonstration(edu.cmu.cs.hcii.cogtool.model.Demonstration) TaskGroup(edu.cmu.cs.hcii.cogtool.model.TaskGroup) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 33 with TaskGroup

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

the class ProjectController method createUngroupAction.

protected IListenerAction createUngroupAction() {
    return new IListenerAction() {

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

        public boolean performAction(Object prms) {
            TaskSelectionState seln = (TaskSelectionState) prms;
            AUndertaking[] tasks = seln.getSelectedTasks(TaskSelectionState.PRUNE_SELECTION | TaskSelectionState.ORDER_SELECTION | TaskSelectionState.TASK_GROUPS_ONLY);
            if ((tasks == null) || (tasks.length == 0)) {
                interaction.protestNoSelection();
                return false;
            }
            CompoundUndoableEdit editSeq = new CompoundUndoableEdit(L10N.get("PC.Ungroup", "Ungroup"), ProjectLID.Ungroup);
            for (AUndertaking task : tasks) {
                if (task.isTaskGroup()) {
                    TaskGroup group = (TaskGroup) task;
                    List<AUndertaking> childTasks = group.getUndertakings();
                    int numChildTasks = childTasks.size();
                    if (numChildTasks > 0) {
                        AUndertaking[] promoteTasks = new AUndertaking[numChildTasks];
                        childTasks.toArray(promoteTasks);
                        for (int j = numChildTasks - 1; j >= 0; j--) {
                            promoteTask(promoteTasks[j], ProjectLID.Ungroup, editSeq);
                        }
                    }
                }
            }
            deleteTasks(tasks, null, editSeq);
            if (editSeq.isSignificant()) {
                editSeq.end();
                undoMgr.addEdit(editSeq);
            }
            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) CompoundUndoableEdit(edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit) TaskGroup(edu.cmu.cs.hcii.cogtool.model.TaskGroup) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint)

Example 34 with TaskGroup

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

the class HCIPACmd method addHCIPATasks.

/**
     * Returns the created subtasks
     */
public static AUndertaking[] addHCIPATasks(Project project, AUndertaking task, String taskName, CognitiveModelGenerator modelGen, String undoRedoLabel, IUndoableEditSequence editSeq) {
    AUndertaking[] subtasks = new AUndertaking[6];
    String[] subtaskNames = new String[] { IDENTIFY_LABEL + taskName, FUNCTION_LABEL, L10N.get("HC.AccessLabel", "3) Access Step"), L10N.get("HC.EnterLabel", "4) Enter Step"), L10N.get("HC.ConfirmLabel", "5) Confirm & Save Step"), L10N.get("HC.MonitorLabel", "6) Monitor Step") };
    TaskGroup group = new TaskGroup(taskName, GroupNature.SUM);
    for (int i = 0; i < 6; i++) {
        subtasks[i] = new Task(subtaskNames[i]);
        subtasks[i].setSpawned(true);
        group.addUndertaking(i, subtasks[i]);
    }
    Iterator<Design> designs = project.getDesigns().iterator();
    while (designs.hasNext()) {
        initHCIPATaskDesign(project, taskName, subtasks, designs.next(), modelGen);
    }
    TaskParent parent = task.getTaskGroup();
    if (parent == null) {
        parent = project;
    }
    editSeq.addEdit(replaceTask(project, parent, task, group, undoRedoLabel));
    return subtasks;
}
Also used : Design(edu.cmu.cs.hcii.cogtool.model.Design) ITaskDesign(edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign) Task(edu.cmu.cs.hcii.cogtool.model.Task) TaskParent(edu.cmu.cs.hcii.cogtool.model.TaskParent) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) TaskGroup(edu.cmu.cs.hcii.cogtool.model.TaskGroup)

Example 35 with TaskGroup

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

the class ProjectController method interactToRenameTask.

/**
     * Interact with the user to solicit a new name for an
     * <code>AUndertaking</code>.  The new name must not be empty and must be
     * unique within the <code>TaskGroup</code> that contains the given task
     * or, if not a child, unique among the top-level tasks for the
     * <code>Project</code>.
     * <p>
     * For a task that is an <code>TaskGroup</code>, the user is also
     * allowed to change the group's <code>GroupNature</code>.
     * <p>
     * Currently unused.
     *
     * @param selectedDesign the design to rename
     * @author mlh
     */
protected boolean interactToRenameTask(AUndertaking selectedTask, TaskSelectionState selection) {
    String oldTaskName = selectedTask.getName();
    ProjectInteraction.TaskRequestData requestData = new ProjectInteraction.TaskRequestData();
    requestData.taskName = oldTaskName;
    requestData.flags = ProjectInteraction.TaskRequestData.ASK_NOTHING;
    GroupNature oldNature = GroupNature.MEAN;
    // If an TaskGroup, allow the user to specify a new GroupNature.
    if (selectedTask.isTaskGroup()) {
        requestData.flags = ProjectInteraction.TaskRequestData.ASK_NATURE;
        oldNature = ((TaskGroup) selectedTask).getNature();
    }
    requestData.nature = oldNature;
    // cancels or specifies a non-empty name that is unique.
    while (true) {
        if (!interaction.requestNewTaskName(requestData)) {
            // canceled!
            return false;
        }
        if (requestData.taskName.equals("")) {
            if (!interaction.protestEmptyTaskName()) {
                return false;
            }
        } else {
            TaskGroup parent = selection.getSelectedTaskParent();
            if (isTaskNameUnique(requestData.taskName, oldTaskName, parent)) {
                if (selectedTask.isTaskGroup() && (requestData.nature != oldNature)) {
                    modifyTaskGroup((TaskGroup) selectedTask, oldTaskName, requestData.taskName, oldNature, requestData.nature);
                    return true;
                }
                return renameTask(selectedTask, oldTaskName, requestData.taskName, parent);
            } else {
                if (!interaction.protestNotUniqueTaskName()) {
                    return false;
                }
            }
        }
    }
// If one ever gets here, uncomment the next line (Java!!)
// return false;
}
Also used : ProjectInteraction(edu.cmu.cs.hcii.cogtool.ui.ProjectInteraction) TaskGroup(edu.cmu.cs.hcii.cogtool.model.TaskGroup) GroupNature(edu.cmu.cs.hcii.cogtool.model.GroupNature)

Aggregations

TaskGroup (edu.cmu.cs.hcii.cogtool.model.TaskGroup)43 AUndertaking (edu.cmu.cs.hcii.cogtool.model.AUndertaking)35 TaskApplication (edu.cmu.cs.hcii.cogtool.model.TaskApplication)16 Design (edu.cmu.cs.hcii.cogtool.model.Design)10 ITaskDesign (edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign)9 DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)8 IListenerAction (edu.cmu.cs.hcii.cogtool.util.IListenerAction)8 AUndoableEdit (edu.cmu.cs.hcii.cogtool.util.AUndoableEdit)7 Script (edu.cmu.cs.hcii.cogtool.model.Script)6 TaskParent (edu.cmu.cs.hcii.cogtool.model.TaskParent)6 CompoundUndoableEdit (edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit)6 ProjectSelectionState (edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState)5 IUndoableEdit (edu.cmu.cs.hcii.cogtool.util.IUndoableEdit)5 CognitiveModelGenerator (edu.cmu.cs.hcii.cogtool.model.CognitiveModelGenerator)4 GroupNature (edu.cmu.cs.hcii.cogtool.model.GroupNature)4 TaskSelectionState (edu.cmu.cs.hcii.cogtool.ui.TaskSelectionState)4 HashMap (java.util.HashMap)4 Demonstration (edu.cmu.cs.hcii.cogtool.model.Demonstration)3 SNIFACTExecContext (edu.cmu.cs.hcii.cogtool.model.SNIFACTExecContext)3 AlertHandler (edu.cmu.cs.hcii.cogtool.util.AlertHandler)3