Search in sources :

Example 16 with TaskGroup

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

Example 17 with TaskGroup

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

the class ProjectController method renameTask.

/**
     * The semantic application action to rename the given selected task from
     * the "old" name to the given "new" name.
     * Adds the appropriate undo/redo to the controller's undo manager.
     *
     * @param renamedTask the task to rename
     * @param newTaskName the new task name
     * @param oldTaskName the renamed task's old name
     * @param parent the name scope; if <code>null</code>, the project is
     *               the scope.
     * @author mlh
     */
protected boolean renameTask(final AUndertaking renamedTask, final String oldTaskName, final String newTaskName, TaskGroup parent) {
    // Check if newTaskName is empty; retry if user desires
    if (newTaskName.length() == 0) {
        if (interaction.protestEmptyTaskName()) {
            ui.initiateTaskRename(renamedTask);
            return true;
        }
        return false;
    }
    // Check uniqueness of new name; if not, complain
    if (isTaskNameUnique(newTaskName, oldTaskName, parent)) {
        // If renaming a group, use modifyTaskGroup
        if (renamedTask.isTaskGroup()) {
            TaskGroup group = (TaskGroup) renamedTask;
            // Just a rename; not changing nature
            modifyTaskGroup(group, oldTaskName, newTaskName, group.getNature(), group.getNature());
        } else if (!newTaskName.equals(oldTaskName)) {
            // Rename only if the name has changed
            renamedTask.setName(newTaskName);
            // Create undo/redo step and add to undo manager
            undoMgr.addEdit(new AUndoableEdit(ProjectLID.RenameTask) {

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

                @Override
                public void redo() {
                    super.redo();
                    renamedTask.setName(newTaskName);
                }

                @Override
                public void undo() {
                    super.undo();
                    renamedTask.setName(oldTaskName);
                }
            });
        }
        return true;
    }
    // Not unique; complain and retry if user desires
    if (interaction.protestNotUniqueTaskName()) {
        ui.initiateTaskRename(renamedTask);
        return true;
    }
    return false;
}
Also used : AUndoableEdit(edu.cmu.cs.hcii.cogtool.util.AUndoableEdit) TaskGroup(edu.cmu.cs.hcii.cogtool.model.TaskGroup)

Example 18 with TaskGroup

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

the class ResultDisplayPolicy method computeGroup.

// getTaskApplicationCell
/**
     * Recursively computes value of script results on a particular design
     * for tasks within a group.
     *
     * @param group the group whose resVal to calculate
     * @param d the design whose script results should be used here
     * @return the recursive value of script results on design d
     *         for tasks in the given TaskGroup; -1.0 if the group is empty
     */
public static double computeGroup(Project project, TaskGroup group, Design d) {
    List<AUndertaking> children = group.getUndertakings();
    if (children.size() == 0) {
        // trivial case
        return TimePredictionResult.UNSET_TIME;
    }
    GroupNature nature = group.getNature();
    boolean validReturnValue = false;
    double returnValue = 0.0d;
    double meanDivisor = 0.0d;
    for (AUndertaking child : children) {
        double stepValue = TimePredictionResult.UNSET_TIME;
        if (child.isTaskGroup()) {
            // recursive (TaskGroup) case
            stepValue = computeGroup(project, (TaskGroup) child, d);
        } else {
            // terminal case
            TaskApplication ta = project.getTaskApplication(child, d);
            if (ta != null) {
                APredictionResult result = ta.getResult(ta.getFirstModelGenerator(), ta.determineActiveAlgorithm(project));
                stepValue = getComputationResult(result);
            }
        }
        if ((nature == GroupNature.SUM) || (nature == GroupNature.MEAN)) {
            if (stepValue != TimePredictionResult.UNSET_TIME) {
                returnValue += stepValue;
                meanDivisor += 1.0d;
                validReturnValue = true;
            }
        } else if (nature == GroupNature.MIN) {
            if ((stepValue != TimePredictionResult.UNSET_TIME) && ((stepValue < returnValue) || (!validReturnValue))) {
                returnValue = stepValue;
                validReturnValue = true;
            }
        } else if (nature == GroupNature.MAX) {
            if (stepValue > returnValue) {
                returnValue = stepValue;
                validReturnValue = true;
            }
        }
    }
    if (validReturnValue) {
        if ((nature == GroupNature.MEAN) && (meanDivisor != 0.0d)) {
            returnValue /= meanDivisor;
        }
        return returnValue;
    }
    return TimePredictionResult.UNSET_TIME;
}
Also used : AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) APredictionResult(edu.cmu.cs.hcii.cogtool.model.APredictionResult) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) TaskGroup(edu.cmu.cs.hcii.cogtool.model.TaskGroup) GroupNature(edu.cmu.cs.hcii.cogtool.model.GroupNature)

Example 19 with TaskGroup

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

the class ResultDisplayPolicy method getTaskRowStrings.

public static String[] getTaskRowStrings(Project project, AUndertaking undertaking, String withSecs, int[] designOrder) {
    List<Design> projectDesigns = project.getDesigns();
    // Add 1 since the initial column is not a design.
    String[] entries = new String[projectDesigns.size() + 1];
    entries[0] = SWTStringUtil.insertEllipsis(undertaking.getName(), 300, StringUtil.EQUAL, SWTStringUtil.DEFAULT_FONT);
    Iterator<Design> designIter = projectDesigns.iterator();
    // advance index to "First result" position
    int index = 1;
    if (undertaking.isTaskGroup()) {
        // TODO: Store group results instead of recomputing?
        TaskGroup group = (TaskGroup) undertaking;
        while (designIter.hasNext()) {
            Design d = designIter.next();
            double result = computeGroup(project, group, d);
            updateDigits();
            String formattedResult = (result == TimePredictionResult.UNSET_TIME) ? "?" : (cellNumberFormat.format(result) + withSecs);
            int entryIndex = (designOrder != null) ? designOrder[index++] : index++;
            entries[entryIndex] = group.getNature().toString() + ": " + formattedResult;
        }
    } else {
        while (designIter.hasNext()) {
            Design d = designIter.next();
            TaskApplication ta = project.getTaskApplication(undertaking, d);
            int entryIndex = (designOrder != null) ? designOrder[index++] : index++;
            CognitiveModelGenerator gen = null;
            if (ta != null) {
                gen = ta.getFirstModelGenerator();
            }
            entries[entryIndex] = getTaskApplicationCell(project, ta, gen, true, withSecs);
        }
    }
    return entries;
}
Also used : Design(edu.cmu.cs.hcii.cogtool.model.Design) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) CognitiveModelGenerator(edu.cmu.cs.hcii.cogtool.model.CognitiveModelGenerator) TaskGroup(edu.cmu.cs.hcii.cogtool.model.TaskGroup)

Example 20 with TaskGroup

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

the class ScriptViewerUIModel method dispose.

/**
     * Dispose: clear the currentFrame of the window, and remove all handlers
     */
@Override
public void dispose() {
    TaskGroup group = (TaskGroup) taskDesign.getTask();
    Iterator<AUndertaking> tasks = group.getUndertakings().iterator();
    while (tasks.hasNext()) {
        AUndertaking childTask = tasks.next();
        TaskApplication tApp = project.getTaskApplication(childTask, design);
        if (tApp != null) {
            Script script = tApp.getOnlyScript();
            script.removeAllHandlers(this);
            script.getDemonstration().removeAllHandlers(this);
        }
    }
    super.dispose();
}
Also used : Script(edu.cmu.cs.hcii.cogtool.model.Script) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) TaskGroup(edu.cmu.cs.hcii.cogtool.model.TaskGroup)

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