Search in sources :

Example 16 with AUndertaking

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

the class ProjectController method duplicateTask.

protected AUndertaking duplicateTask(AUndertaking task, int atIndex, TaskParent parent, List<AUndertaking> siblings, CogToolLID lid, String presentationName, IUndoableEditSequence editSeq) {
    String newTaskName = NamedObjectUtil.makeNameUnique(task.getName(), siblings);
    IUndoableEdit edit;
    AUndertaking duplicateTask = task.duplicate(newTaskName);
    // Create undo/redo step
    if (task.isTaskGroup()) {
        SNIFACTExecContext context = (SNIFACTExecContext) task.getAttribute(WidgetAttributes.SNIFACT_CONTEXT_ATTR);
        // duplicated as well.
        if (!NullSafe.equals(context, WidgetAttributes.NO_CONTEXT)) {
            duplicateTask.setAttribute(WidgetAttributes.SNIFACT_CONTEXT_ATTR, context.duplicate());
        }
        edit = createNewTaskGroupUndo(parent, atIndex, (TaskGroup) duplicateTask, null, null, new AUndertaking[0], lid, presentationName);
    } else {
        edit = createNewTaskUndo(parent, atIndex, duplicateTask, lid, presentationName);
    }
    editSeq.addEdit(edit);
    parent.addUndertaking(atIndex, duplicateTask);
    if (task.isTaskGroup()) {
        duplicateTaskApplications((TaskGroup) task, (TaskGroup) duplicateTask);
    } else {
        duplicateTaskApplications(task, duplicateTask);
    }
    return duplicateTask;
}
Also used : AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) IUndoableEdit(edu.cmu.cs.hcii.cogtool.util.IUndoableEdit) SNIFACTExecContext(edu.cmu.cs.hcii.cogtool.model.SNIFACTExecContext) TaskGroup(edu.cmu.cs.hcii.cogtool.model.TaskGroup)

Example 17 with AUndertaking

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

the class ProjectController method saveDesignToClipboard.

// createPasteAction
// Support for copying design and associated TA's to clipboard
protected void saveDesignToClipboard(Design design, ObjectSaver saver) {
    try {
        saver.saveObject(design);
        Iterator<AUndertaking> rootTasks = project.getUndertakings().iterator();
        while (rootTasks.hasNext()) {
            AUndertaking childTask = rootTasks.next();
            saver.saveObject(childTask);
        }
        Map<ITaskDesign, TaskApplication> associatedTAs = project.taskApplicationsForDesign(design);
        Iterator<TaskApplication> taskApps = associatedTAs.values().iterator();
        while (taskApps.hasNext()) {
            TaskApplication ta = taskApps.next();
            saver.saveObject(ta);
        }
    } catch (IOException ex) {
        throw new RcvrClipboardException(ex);
    }
}
Also used : ITaskDesign(edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) RcvrClipboardException(edu.cmu.cs.hcii.cogtool.util.RcvrClipboardException) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) IOException(java.io.IOException) RcvrIOException(edu.cmu.cs.hcii.cogtool.util.RcvrIOException)

Example 18 with AUndertaking

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

the class ProjectController method recomputeScripts.

protected boolean recomputeScripts(AUndertaking task, Design design, DemoStateManager demoStateMgr, ComputeMessages computeMsgs, IUndoableEditSequence editSequence) {
    if (CogToolPref.isTracingOverride == null && !CogToolPref.IS_TRACING.getBoolean()) {
        Boolean answer = getInteraction().confirmNoTracing();
        if (answer == null) {
            // canceled
            return false;
        } else if (answer.booleanValue()) {
            CogToolPref.IS_TRACING.setBoolean(true);
        }
    }
    if (task.isTaskGroup()) {
        if (!NullSafe.equals(WidgetAttributes.NO_CONTEXT, task.getAttribute(WidgetAttributes.SNIFACT_CONTEXT_ATTR))) {
            return computeSnifAct(design, task, editSequence, null);
        }
        Iterator<AUndertaking> allTasks = ((TaskGroup) task).getUndertakings().iterator();
        CompoundUndoableEdit groupEditSeq = new CompoundUndoableEdit(RECOMPUTE_SCRIPTS, ProjectLID.RecomputeScript);
        while (allTasks.hasNext()) {
            if (!recomputeScripts(allTasks.next(), design, demoStateMgr, computeMsgs, groupEditSeq)) {
                return false;
            }
        }
        if (groupEditSeq.isSignificant()) {
            groupEditSeq.end();
            editSequence.addEdit(groupEditSeq);
        }
        return true;
    }
    TaskApplication ta = project.getTaskApplication(task, design);
    if (ta != null) {
        IPredictionAlgo activeAlg = ta.determineActiveAlgorithm(project);
        if (activeAlg == SNIFACTPredictionAlgo.ONLY) {
            return computeSnifAct(design, task, editSequence, null);
        }
        if (computeMsgs.canComputeScript(ta, demoStateMgr, editSequence)) {
            if (!activeAlg.allowsComputation()) {
                interaction.setStatusMessage(algDisallowsComputation);
                interaction.reportProblem(RECOMPUTE_SCRIPTS, algDisallowsComputation);
                return false;
            } else if (!ta.getDemonstration().isStartFrameChosen()) {
                // nothing to compute
                interaction.setStatusMessage(noStartFrameChosen);
                return false;
            }
            IUndoableEdit edit = ComputePredictionCmd.computeAllPredictions(project, ta, activeAlg, ta.determineComputeInBackground(project), interaction);
            if (edit != null) {
                ta.setActiveAlgorithm(activeAlg);
                editSequence.addEdit(edit);
            } else {
                interaction.setStatusMessage(computeHadNoResult);
            }
        } else {
            interaction.setStatusMessage(cannotRecomputeInvalid);
        }
    } else {
        if (project.getDefaultAlgo() == SNIFACTPredictionAlgo.ONLY) {
            return computeSnifAct(design, task, editSequence, null);
        }
        interaction.setStatusMessage(cannotRecomputeNoDemo);
    }
    return true;
}
Also used : IPredictionAlgo(edu.cmu.cs.hcii.cogtool.model.IPredictionAlgo) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) CompoundUndoableEdit(edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) IUndoableEdit(edu.cmu.cs.hcii.cogtool.util.IUndoableEdit)

Example 19 with AUndertaking

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

the class ProjectController method mapProjectTasks.

protected void mapProjectTasks(AUndertaking task, TaskParent parent, Map<AUndertaking, AUndertaking> reuseTasks, IUndoableEditSequence editSeq, String presentationName) {
    AUndertaking correspondingTask = parent.getUndertaking(task.getName());
    if (correspondingTask != null) {
        reuseTasks.put(task, correspondingTask);
        if ((task instanceof TaskGroup) && (correspondingTask instanceof TaskGroup)) {
            TaskGroup correspondingGroup = (TaskGroup) correspondingTask;
            Iterator<AUndertaking> childTasks = ((TaskGroup) task).getUndertakings().iterator();
            while (childTasks.hasNext()) {
                AUndertaking childTask = childTasks.next();
                mapProjectTasks(childTask, correspondingGroup, reuseTasks, editSeq, presentationName);
            }
        }
    } else {
        pasteTask(task, parent, parent.getUndertakings().size(), editSeq, presentationName);
    }
}
Also used : AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) TaskGroup(edu.cmu.cs.hcii.cogtool.model.TaskGroup)

Example 20 with AUndertaking

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

the class ProjectController method createPasteAction.

// Action for Paste
protected IListenerAction createPasteAction() {
    return new IListenerAction() {

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

        public boolean performAction(Object prms) {
            ProjectSelectionState seln = (ProjectSelectionState) prms;
            try {
                // Check for CogTool objects to paste
                Collection<Object> objects = CogToolClipboard.fetchCogToolObjects(project);
                // designs and tasks only
                int numObjectsPasted = 0;
                if ((objects != null) && (objects.size() > 0)) {
                    // Paste tasks as children of the selected TaskGroup
                    AUndertaking[] selectedTasks = seln.getSelectedTasks(TaskSelectionState.ORDER_SELECTION);
                    TaskGroup taskParent = seln.getSelectedTaskParent();
                    int index;
                    // index at which new pasted Tasks will be placed.
                    if (taskParent != null) {
                        AUndertaking last = selectedTasks[selectedTasks.length - 1];
                        index = taskParent.getUndertakings().indexOf(last) + 1;
                    } else {
                        index = findLastSelectedRoot(selectedTasks);
                    }
                    // Create undo support
                    String presentationName = PASTE;
                    CompoundUndoableEdit editSeq = new CompoundUndoableEdit(presentationName, ProjectLID.Paste);
                    // If task applications are pasted, they will have
                    // null Design fields; they should "arrive" after
                    // the Design being pasted at the same time!
                    Design newDesign = null;
                    // Existing tasks are to be re-used if the paste
                    // is within the same project as the copy/cut.
                    Map<AUndertaking, AUndertaking> reuseTasks = null;
                    Iterator<Object> objIt = objects.iterator();
                    while (objIt.hasNext()) {
                        Object o = objIt.next();
                        // unique name and create and place the design.
                        if (o instanceof Design) {
                            newDesign = (Design) o;
                            makeDesignNameUnique(newDesign);
                            // Add an undo step after creating/placing
                            ProjectCmd.addNewDesign(project, newDesign, seln.getSelectedDesign(), presentationName, editSeq);
                            numObjectsPasted++;
                        } else // or to the Project.  Create and place.
                        if (o instanceof AUndertaking) {
                            AUndertaking task = (AUndertaking) o;
                            // project or pasting copied tasks
                            if (reuseTasks == null) {
                                pasteTask(task, taskParent, index++, editSeq, presentationName);
                                numObjectsPasted++;
                            } else {
                                // In this case, a copied design is
                                // being pasted into the same project.
                                // Map each undertaking to the
                                // corresponding one in the current project
                                mapProjectTasks(task, project, reuseTasks, editSeq, presentationName);
                            }
                        } else // along when copying an Design.
                        if (o instanceof TaskApplication) {
                            TaskApplication taskApp = (TaskApplication) o;
                            if (reuseTasks != null) {
                                AUndertaking reuseTask = reuseTasks.get(taskApp.getTask());
                                if (reuseTask != null) {
                                    taskApp.setTask(reuseTask);
                                }
                            }
                            // The undo edit for adding the Design will
                            // remove and restore the task-applications;
                            // simply add to the project.
                            project.setTaskApplication(taskApp);
                        } else if (o instanceof CogToolClipboard.ProjectScope) {
                            CogToolClipboard.ProjectScope projectScope = (CogToolClipboard.ProjectScope) o;
                            // a copied design into the same project
                            if (projectScope.getProject() != null) {
                                reuseTasks = new HashMap<AUndertaking, AUndertaking>();
                            }
                        }
                    }
                    // Done with undo/redo steps; add the compound change
                    // to the undo manager.
                    editSeq.end();
                    undoMgr.addEdit(editSeq);
                    interaction.setStatusMessage(numObjectsPasted + " " + pasteComplete);
                } else {
                    interaction.setStatusMessage(nothingPasted);
                }
                return true;
            } catch (IOException e) {
                throw new RcvrClipboardException(e);
            } catch (SAXException e) {
                throw new RcvrClipboardException(e);
            } catch (ParserConfigurationException e) {
                throw new RcvrClipboardException(e);
            } catch (ClipboardUtil.ClipboardException e) {
                throw new RcvrClipboardException(e);
            }
        }
    };
}
Also used : ProjectSelectionState(edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState) HashMap(java.util.HashMap) CogToolClipboard(edu.cmu.cs.hcii.cogtool.CogToolClipboard) RcvrClipboardException(edu.cmu.cs.hcii.cogtool.util.RcvrClipboardException) CompoundUndoableEdit(edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit) IOException(java.io.IOException) RcvrIOException(edu.cmu.cs.hcii.cogtool.util.RcvrIOException) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) SAXException(org.xml.sax.SAXException) 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) ClipboardUtil(edu.cmu.cs.hcii.cogtool.util.ClipboardUtil) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) 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