Search in sources :

Example 81 with AUndertaking

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

the class SWTListGroupScript method getFirstTaskDemo.

protected static Demonstration getFirstTaskDemo(Project project, Project.ITaskDesign td) {
    TaskGroup group = (TaskGroup) td.getTask();
    AUndertaking firstTask = group.getUndertakings().get(0);
    TaskApplication ta = project.getTaskApplication(firstTask, td.getDesign());
    return ta.getDemonstration();
}
Also used : AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) TaskGroup(edu.cmu.cs.hcii.cogtool.model.TaskGroup)

Example 82 with AUndertaking

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

the class DemoScriptCmd method exportScriptToCSV.

public static boolean exportScriptToCSV(Script script, Project project, Interaction interaction, IUndoableEditSequence editSeq) {
    Demonstration demo = script.getDemonstration();
    TaskApplication ta = demo.getTaskApplication();
    Design design = ta.getDesign();
    AUndertaking task = ta.getTask();
    String name = project.getName();
    name += "_" + design.getName();
    name += "_" + task.getName();
    File dest = null;
    if (interaction != null) {
        dest = interaction.selectCSVFileDest(name);
    } else {
        dest = new File(CogTool.exportCSVKludgeDir, name + ".txt");
    }
    if (dest == null) {
        return false;
    }
    FileWriter fw = null;
    BufferedWriter buffer = null;
    try {
        fw = new FileWriter(dest);
        buffer = new BufferedWriter(fw);
        CSVSupport.writeCell("Format version:", buffer);
        CSVSupport.addSeparator(buffer);
        CSVSupport.writeCell(FORMAT_VERSION, buffer);
        CSVSupport.addLineEnding(buffer);
        Date now = new Date();
        String date = DateFormat.getDateTimeInstance().format(now);
        CSVSupport.writeCell("Date and Time:", buffer);
        CSVSupport.addSeparator(buffer);
        CSVSupport.writeCell(date, buffer);
        CSVSupport.addLineEnding(buffer);
        CSVSupport.writeCell("Project Name:", buffer);
        CSVSupport.addSeparator(buffer);
        CSVSupport.writeCell(project.getName(), buffer);
        CSVSupport.addLineEnding(buffer);
        CSVSupport.writeCell("Design Name:", buffer);
        CSVSupport.addSeparator(buffer);
        CSVSupport.writeCell(design.getName(), buffer);
        CSVSupport.addLineEnding(buffer);
        CSVSupport.writeCell("Task Hierarchy:", buffer);
        String taskName = task.getFullName();
        String[] cells = taskName.split(":");
        for (String cell : cells) {
            CSVSupport.addSeparator(buffer);
            CSVSupport.writeCell(cell, buffer);
        }
        CSVSupport.addLineEnding(buffer);
        CSVSupport.addSeparator(buffer);
        CSVSupport.addLineEnding(buffer);
        buffer.write("\"Frame\",\"Action\",\"Widget-Name\"," + "\"Displayed-Label\",\"Widget-Type\"");
        CSVSupport.addLineEnding(buffer);
        IWidget lastMovedToWidget = null;
        Iterator<DefaultModelGeneratorState> stepStates = script.getStepStates().iterator();
        while (stepStates.hasNext()) {
            DefaultModelGeneratorState stepState = stepStates.next();
            AScriptStep step = stepState.getScriptStep();
            TransitionSource stepFocus = step.getStepFocus();
            String frameName = step.getCurrentFrame().getName();
            String actionName = KeyDisplayUtil.convertActionToMenuText(step.getLocalizedString());
            if ((!(step instanceof LookAtScriptStep)) && (!(step instanceof ThinkScriptStep)) && (!(step instanceof TextActionSegment))) {
                actionName = step.getLocalizedActionString(actionName, lastMovedToWidget);
            }
            lastMovedToWidget = stepState.getLastMovedToWidget();
            String widgetName = "";
            String widgetType = "";
            String widgetTitle = "";
            if (stepFocus != null) {
                widgetName = stepFocus.getName();
                if (stepFocus instanceof IWidget) {
                    IWidget w = (IWidget) stepFocus;
                    widgetType = w.getWidgetType().toString();
                    String s = w.getTitle();
                    if (s != null) {
                        widgetTitle = s;
                    }
                }
            }
            CSVSupport.writeCell(frameName, buffer);
            CSVSupport.addSeparator(buffer);
            CSVSupport.writeCell(actionName, buffer);
            CSVSupport.addSeparator(buffer);
            CSVSupport.writeCell(widgetName, buffer);
            CSVSupport.addSeparator(buffer);
            CSVSupport.writeCell(widgetTitle, buffer);
            CSVSupport.addSeparator(buffer);
            CSVSupport.writeCell(widgetType, buffer);
            CSVSupport.addLineEnding(buffer);
        }
        Frame resultFrame = demo.getResultFrame();
        if (resultFrame != null) {
            CSVSupport.writeCell(resultFrame.getName(), buffer);
        }
        if (interaction != null) {
            interaction.setStatusMessage(L10N.get("DSO.ExportCompletedPre", "Export completed to ") + dest + L10N.get("DSO.ExportCompletePost", "."));
        }
    } catch (IOException e) {
        if (interaction != null) {
            interaction.reportProblem("File I/O Error", e.getMessage());
        } else {
            e.printStackTrace();
        }
        return false;
    } finally {
        try {
            if (buffer != null) {
                buffer.close();
            }
            if (fw != null) {
                fw.close();
            }
        } catch (IOException e) {
            if (interaction != null) {
                interaction.reportProblem("File I/O Error on Close", e.getMessage());
            } else {
                e.printStackTrace();
            }
            return false;
        }
    }
    return true;
}
Also used : Frame(edu.cmu.cs.hcii.cogtool.model.Frame) FileWriter(java.io.FileWriter) IOException(java.io.IOException) AScriptStep(edu.cmu.cs.hcii.cogtool.model.AScriptStep) Date(java.util.Date) BufferedWriter(java.io.BufferedWriter) ThinkScriptStep(edu.cmu.cs.hcii.cogtool.model.ThinkScriptStep) Design(edu.cmu.cs.hcii.cogtool.model.Design) TransitionSource(edu.cmu.cs.hcii.cogtool.model.TransitionSource) TextActionSegment(edu.cmu.cs.hcii.cogtool.model.TextActionSegment) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) LookAtScriptStep(edu.cmu.cs.hcii.cogtool.model.LookAtScriptStep) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) Demonstration(edu.cmu.cs.hcii.cogtool.model.Demonstration) File(java.io.File) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget) DefaultModelGeneratorState(edu.cmu.cs.hcii.cogtool.model.DefaultModelGeneratorState)

Example 83 with AUndertaking

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

the class ScriptViewerUI method dispose.

@Override
public void dispose() {
    CogTool.selectionPhase.removeDelayedWork(delayedStateSelection);
    CogTool.repaintPhase.removeDelayedWork(delayedRepainting);
    uiModel.dispose();
    TaskGroup group = (TaskGroup) taskDesign.getTask();
    Iterator<AUndertaking> tasks = group.getUndertakings().iterator();
    while (tasks.hasNext()) {
        AUndertaking t = tasks.next();
        TaskApplication tApp = project.getTaskApplication(t, design);
        if (tApp == null) {
            continue;
        }
        Script script = tApp.getOnlyScript();
        script.removeAllHandlers(this);
        script.getDemonstration().removeAllHandlers(this);
    }
    selection.removeAllHandlers(this);
    view.removeSWTListSelectionHandler(SWTselectionChangeHandler);
    super.dispose();
}
Also used : Script(edu.cmu.cs.hcii.cogtool.model.Script) SWTListGroupScript(edu.cmu.cs.hcii.cogtool.view.SWTListGroupScript) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) TaskGroup(edu.cmu.cs.hcii.cogtool.model.TaskGroup)

Example 84 with AUndertaking

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

the class ProjectUI method setUpDragAndDrop.

// See http://www.eclipse.org/articles/Article-SWT-DND/DND-in-SWT.html
// for more documentation of SWT drag-and-drop support.
protected void setUpDragAndDrop() {
    DragSource treeAsSource = new DragSource(tree, DND.DROP_MOVE | DND.DROP_COPY);
    TaskDnDTransfer taskTransfer = TaskDnDTransfer.getInstance();
    TaskAppDnDTransfer taskAppTransfer = TaskAppDnDTransfer.getInstance();
    Transfer[] types = new Transfer[] { taskTransfer, taskAppTransfer };
    treeAsSource.setTransfer(types);
    // DropSourceEvent fields:
    // dataType:
    //   the Transfer type of the data the target prefers to receive;
    //   useful in dragSetData
    // detail:
    //   the operation the target performed; one of:
    //      DROP_MOVE - move from source to target; remove from source
    //      DROP_COPY - copy the source to target; leave the source
    //      DROP_LINK - create a link of the source at the target
    //   useful in dragFinished in case the source needs to be removed
    // doit:
    //   in dragStart, determines if the operation should proceed
    //   in dragFinished, may be set to indicate if the operation succeeded
    // image:
    //   may be set to the Image displayed during drag
    // x, y: position within the Tree
    DragSourceListener srcListener = new TreeDragSourceEffect(tree) {

        @Override
        public void dragStart(DragSourceEvent evt) {
            // If the Transfer type cannot be determined until the drag
            // starts, the setTransfer() call can be invoked here.
            // Set evt.doit to false here if action is inappropriate.
            // Reset, just in case no drag-and-drop should happen
            currentDnDSource = null;
            // Must be in first column!
            TreeColumn column = findColumn(evt.x);
            TreeItem row = tree.getItem(new Point(evt.x, evt.y));
            if ((column != null) && (column.getData() == null)) {
                if ((row != null) && (row.getData() != null)) {
                    if (((AUndertaking) row.getData()).isSpawned()) {
                        evt.doit = false;
                        return;
                    }
                }
                if (selection.getSelectedTaskCount() == 0) {
                    if (row != null) {
                        selection.setSelectedItem(row);
                        currentDnDSource = tree;
                        currentDnDColumn = 0;
                    }
                } else {
                    currentDnDSource = tree;
                    currentDnDColumn = 0;
                }
            } else {
                // Must be in cell with a valid TaskApplication!
                if ((column != null) && (column.getData() != null)) {
                    if ((row != null) && (row.getData() != null)) {
                        Design design = (Design) column.getData();
                        AUndertaking task = (AUndertaking) row.getData();
                        TaskApplication taskApp = project.getTaskApplication(task, design);
                        if (taskApp != null) {
                            if (!taskApp.getDemonstration().isEditable()) {
                                evt.doit = false;
                                return;
                            }
                            // set some highlighting of the source cell
                            selection.setSelectedCell(row, column);
                            contextSelection.setSelectedDesign(design);
                            contextSelection.addSelectedTask(task);
                            currentDnDRow = row;
                            currentDnDSource = tree;
                            currentDnDColumn = tree.indexOf(column);
                            // do not do superclass work!
                            return;
                        }
                    }
                }
                evt.doit = false;
            }
            super.dragStart(evt);
        }

        @Override
        public void dragSetData(DragSourceEvent evt) {
            // Based on the requested Transfer data type, set evt.data
            //                    if (taskTransfer.isSupportedType(evt.dataType)) {
            //                        evt.data = "This is the requested data";
            //                    }
            super.dragSetData(evt);
        }

        @Override
        public void dragFinished(DragSourceEvent evt) {
            // Operation was performed by the drop target; clean up
            // If needed, evt.detail should be the operation performed.
            super.dragFinished(evt);
            currentDnDSource = null;
            currentDnDColumn = -1;
            currentDnDRow = null;
            currentDndTaskAppDropRow = null;
        }
    };
    treeAsSource.addDragListener(srcListener);
    DropTarget treeAsTarget = new DropTarget(tree, DND.DROP_MOVE | DND.DROP_COPY);
    treeAsTarget.setTransfer(types);
    // DropTargetEvent fields:
    // currentDataType:
    //   the Transfer type of the data the target prefers to receive;
    //   can be set -- see the method comments below
    // dataTypes:
    //   the array of Transfer types the source can "send"
    // detail:
    //   the operation the user is trying to perform; one of:
    //      DROP_MOVE - move from source to target; remove from source
    //      DROP_COPY - copy the source to target; leave the source
    //      DROP_LINK - create a link of the source at the target
    //      DROP_DEFAULT - indicator that target must choose operation
    //      DROP_NONE - indicator that user is trying an unsupported op
    //   may be set to the operation the target feels is correct
    //   (thus, if initially DEFAULT, then the operation that would be
    //   performed; if initially DEFAULT and not changed, it will appear
    //   to the user as a MOVE -- also, set to NONE if target determines
    //   operation is not permitted)
    // feedback:
    //   bitwise OR'ing of feedback effects displayed to the user;
    //   can be set using the following constants:
    //      FEEDBACK_SELECT - item under cursor is selected
    //      FEEDBACK_SCROLL - allows scrolling to make items visible
    //      FEEDBACK_EXPAND - allows tree items to be expanded
    //      FEEDBACK_INSERT_BEFORE - insertion mark before item under cursor
    //      FEEDBACK_INSERT_AFTER - insertion mark after item under cursor
    //      FEEDBACK_NONE - no feedback
    // item:
    //   TreeItem or TableItem under the cursor, if applicable
    // operations:
    //   bitwise OR'ing of the operations that the DragSource can support
    treeAsTarget.addDropListener(new TreeDropTargetEffect(tree) {

        protected static final int DRAG_FEEDBACK = DND.FEEDBACK_EXPAND | DND.FEEDBACK_INSERT_BEFORE | DND.FEEDBACK_SCROLL;

        protected static final int DRAG_APP_FEEDBACK = DND.FEEDBACK_EXPAND | DND.FEEDBACK_SCROLL;

        protected int requestedOp = DND.DROP_MOVE;

        @Override
        public void dragEnter(DropTargetEvent evt) {
            // Set evt.detail to DND.DROP_NONE when the operation is a no-op
            // or if the presented type is unacceptable.  Other choices
            // that make sense: DND.DROP_MOVE, DND.DROP_COPY
            // evt.currentDataType is the type preferred by the target.
            // evt.dataTypes contains types provided by the source.
            super.dragEnter(evt);
            if (currentDnDSource != getControl()) {
                evt.detail = DND.DROP_NONE;
            } else {
                requestedOp = evt.detail;
            }
        }

        @Override
        public void dragLeave(DropTargetEvent evt) {
            if (currentDndTaskAppDropRow != null) {
                currentDndTaskAppDropRow.setBackground(currentDnDColumn, ProjectUIModel.unselectedTaskBackgroundColor);
            }
            super.dragLeave(evt);
        }

        @Override
        public void dragOperationChanged(DropTargetEvent evt) {
            // change evt.currentDataType if desired here.
            if ((evt.detail != DND.DROP_MOVE) && (evt.detail != DND.DROP_COPY)) {
                evt.detail = DND.DROP_NONE;
            }
            requestedOp = evt.detail;
            super.dragOperationChanged(evt);
        }

        @Override
        public void dragOver(DropTargetEvent evt) {
            if (currentDndTaskAppDropRow != null) {
                currentDndTaskAppDropRow.setBackground(currentDnDColumn, ProjectUIModel.unselectedTaskBackgroundColor);
            }
            Point toTreeEvtLoc = tree.toControl(evt.x, evt.y);
            //System.out.println("dragOver; set feedback here?");
            if (currentDnDSource != getControl()) {
                evt.detail = DND.DROP_NONE;
                evt.feedback = DND.FEEDBACK_NONE;
            } else if (currentDnDColumn == 0) {
                // Moving tasks
                evt.feedback = DRAG_FEEDBACK;
                evt.detail = requestedOp;
                TreeItem row = tree.getItem(toTreeEvtLoc);
                if ((row != null) && (row.getData() != null)) {
                    if (((AUndertaking) row.getData()).isSpawned()) {
                        evt.detail = DND.DROP_NONE;
                        evt.feedback = DND.FEEDBACK_NONE;
                    }
                }
            } else {
                // Moving task applications
                evt.feedback = DRAG_APP_FEEDBACK;
                TreeColumn column = findColumn(toTreeEvtLoc.x);
                if (column == null) {
                    evt.detail = DND.DROP_NONE;
                } else {
                    Design design = (Design) column.getData();
                    if (design != contextSelection.getSelectedDesign()) {
                        evt.detail = DND.DROP_NONE;
                    } else {
                        TreeItem row = tree.getItem(toTreeEvtLoc);
                        if ((row == null) || (row.getData() == null)) {
                            evt.detail = DND.DROP_NONE;
                        } else {
                            AUndertaking task = (AUndertaking) row.getData();
                            if (task.isTaskGroup() || task.isSpawned() || contextSelection.isTaskSelected(task)) {
                                evt.detail = DND.DROP_NONE;
                            } else {
                                evt.detail = requestedOp;
                                currentDndTaskAppDropRow = row;
                                currentDndTaskAppDropRow.setBackground(currentDnDColumn, CONTEXT_COLOR);
                            }
                        }
                    }
                }
            }
            super.dragOver(evt);
        }

        @Override
        public void dropAccept(DropTargetEvent evt) {
            // Can change evt.detail if desired here.
            // Provide one last chance to define the type of data that
            // will be returned in the drop event; thus, change
            // evt.currentDataType if desired here
            super.dropAccept(evt);
        }

        @Override
        public void drop(DropTargetEvent evt) {
            // When the drop operation is completed, update the
            // evt.detail field with the operation performed.
            // Do the operation!
            AUndertaking beforeTask = null;
            if (evt.item != null) {
                beforeTask = (AUndertaking) evt.item.getData();
            }
            if (requestedOp == DND.DROP_COPY) {
                if (currentDnDColumn == 0) {
                    ProjectUI.ChangeTaskPositionParms parms = new ProjectUI.ChangeTaskPositionParms(selection, beforeTask, true);
                    if (performAction(ProjectLID.DuplicateTaskFull, parms, true)) {
                        evt.detail = DND.DROP_COPY;
                    }
                } else {
                    AUndertaking fromTask = (AUndertaking) currentDnDRow.getData();
                    AUndertaking toTask = (AUndertaking) currentDndTaskAppDropRow.getData();
                    TreeColumn column = tree.getColumn(currentDnDColumn);
                    Design design = (Design) column.getData();
                    ProjectUI.MoveCopyTaskApplicationParms parms = new ProjectUI.MoveCopyTaskApplicationParms(fromTask, toTask, design);
                    selection.setSelectedCell(currentDndTaskAppDropRow, column);
                    if (performAction(ProjectLID.DuplicateTaskApplication, parms, true)) {
                        uiModel.redisplayAllResults();
                        evt.detail = DND.DROP_COPY;
                    }
                }
            } else if (requestedOp == DND.DROP_MOVE) {
                if (currentDnDColumn == 0) {
                    ProjectUI.ChangeTaskPositionParms parms = new ProjectUI.ChangeTaskPositionParms(selection, beforeTask, false);
                    if (performAction(ProjectLID.ChangeTaskPosition, parms, true)) {
                        evt.detail = DND.DROP_MOVE;
                    }
                } else {
                    AUndertaking fromTask = (AUndertaking) currentDnDRow.getData();
                    AUndertaking toTask = (AUndertaking) currentDndTaskAppDropRow.getData();
                    TreeColumn column = tree.getColumn(currentDnDColumn);
                    Design design = (Design) column.getData();
                    ProjectUI.MoveCopyTaskApplicationParms parms = new ProjectUI.MoveCopyTaskApplicationParms(fromTask, toTask, design);
                    selection.setSelectedCell(currentDndTaskAppDropRow, column);
                    if (performAction(ProjectLID.MoveTaskApplication, parms, true)) {
                        uiModel.redisplayAllResults();
                        evt.detail = DND.DROP_MOVE;
                    }
                }
            }
            super.drop(evt);
        }
    });
}
Also used : TreeItem(org.eclipse.swt.widgets.TreeItem) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) DragSource(org.eclipse.swt.dnd.DragSource) Point(org.eclipse.swt.graphics.Point) DragSourceListener(org.eclipse.swt.dnd.DragSourceListener) TreeDropTargetEffect(org.eclipse.swt.dnd.TreeDropTargetEffect) Point(org.eclipse.swt.graphics.Point) DragSourceEvent(org.eclipse.swt.dnd.DragSourceEvent) Design(edu.cmu.cs.hcii.cogtool.model.Design) TreeColumn(org.eclipse.swt.widgets.TreeColumn) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) Transfer(org.eclipse.swt.dnd.Transfer) ByteArrayTransfer(org.eclipse.swt.dnd.ByteArrayTransfer) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) DropTarget(org.eclipse.swt.dnd.DropTarget) TreeDragSourceEffect(org.eclipse.swt.dnd.TreeDragSourceEffect)

Example 85 with AUndertaking

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

the class ProjectUI method setViewEnabledState.

/**
     * Enables or disables LIDs as appropriate
     * @param sel the selection state on which to base enabling/disabling
     * @param availability NORMAL or CONTEXT
     * @see ListenerIdentifierMap
     */
protected void setViewEnabledState(ProjectSelectionState sel, Boolean availability) {
    boolean hasDesign = sel.getSelectedDesign() != null;
    setEnabled(CogToolLID.AddDesignDevices, availability, hasDesign);
    String scriptLabel = "";
    scriptLabel = hasMultipleScripts(sel) ? " " + SCRIPTS_LABEL : " " + SCRIPT_LABEL;
    String label = "";
    int selectedTaskCount = sel.getSelectedTaskCount();
    boolean isSnifActTask = snifActTasksSelected(sel, TaskSelectionState.PRUNE_SELECTION);
    boolean isSnifActGroup = snifActTasksSelected(sel, TaskSelectionState.TASK_GROUPS_ONLY);
    if (selectedTaskCount > 0) {
        AUndertaking[] tasks = sel.getSelectedTasks(TaskSelectionState.ORDER_SELECTION);
        boolean allGroups = true;
        for (int i = 0; i < tasks.length; i++) {
            if (!tasks[i].isTaskGroup()) {
                allGroups = false;
            }
        }
        if (allGroups) {
            label = (selectedTaskCount > 1) ? (" " + TASK_GROUPS_LABEL) : (" " + TASK_GROUP_LABEL);
        } else {
            label = (selectedTaskCount > 1) ? (" " + TASKS_LABEL) : (" " + TASK_LABEL);
        }
    }
    if (hasDesign) {
        label = " " + DESIGN_LABEL;
        setEnabled(CogToolLID.ExportToXML, ListenerIdentifierMap.ALL, MenuUtil.ENABLED, L10N.get("PR.ExportDesignXMLLabel", "Export Design to XML"));
    } else {
        setEnabled(CogToolLID.ExportToXML, ListenerIdentifierMap.ALL, MenuUtil.ENABLED, EXPORT_PROJECT_LABEL);
    }
    String cutCopyLabel = (editor.getEditor() != null) ? "" : label;
    String regenerateString = regenerateTitle;
    boolean requiresRegeneration = selectionRequiresRegeneration(sel);
    if (requiresRegeneration) {
        regenerateString += scriptLabel;
    }
    setEnabled(CogToolLID.RegenerateScript, availability, requiresRegeneration, regenerateString);
    AUndertaking[] tasks = sel.getSelectedTasks(TaskSelectionState.PRUNE_SELECTION);
    boolean singleTask = selectedTaskCount == 1;
    boolean cellSelected = hasDesign && singleTask;
    boolean anySelection = hasDesign || (selectedTaskCount > 0);
    setEnabled(CogToolLID.ExportDesignToHTML, availability, hasDesign);
    setEnabled(ProjectLID.ExportDictToCSV, availability, hasDesign);
    setEnabled(ProjectLID.ImportDict, availability, hasDesign);
    setEnabled(CogToolLID.CaptureBehavior, availability, true);
    if (cellSelected) {
        setEnabled(CogToolLID.Paste, availability, false);
        setEnabled(CogToolLID.Duplicate, availability, false, MenuFactory.DUPLICATE_STRING);
        setEnabled(CogToolLID.Rename, availability, false, MenuFactory.RENAME_STRING);
        setEnabled(CogToolLID.Cut, availability, false, MenuFactory.CUT_STRING);
        setEnabled(CogToolLID.Copy, availability, false, MenuFactory.COPY_STRING);
        setEnabled(CogToolLID.Delete, availability, false, MenuFactory.DELETE_STRING);
        String editLabel = MenuFactory.EDIT_STRING + " " + SCRIPT_LABEL;
        boolean editEnabled = true;
        if (tasks[0].isTaskGroup()) {
            if (GroupNature.SUM.equals(((TaskGroup) tasks[0]).getNature())) {
                editLabel = VIEW_SCRIPTS;
            } else {
                editLabel = MenuFactory.EDIT_STRING;
                editEnabled = false;
            }
        }
        setEnabled(CogToolLID.Edit, availability, editEnabled, editLabel);
        if (isSnifActTask) {
            // If it's a task generated by a run of SNIF-ACT (and therefore
            // put in a group that has that attribute), the algorithm in its
            // cell should never be changed.
            setEnabled(ProjectLID.SetAlgorithmACTR6, availability, false);
            setEnabled(ProjectLID.SetAlgorithmSNIFACT, availability, false);
            setEnabled(ProjectLID.SetAlgorithmDefault, availability, false);
            setEnabled(ProjectLID.SetAlgorithmHuman, availability, false);
            setEnabled(ProjectLID.SetBackgroundComputationDefault, availability, false);
            setEnabled(ProjectLID.SetBackgroundComputationFalse, availability, false);
            setEnabled(ProjectLID.SetBackgroundComputationTrue, availability, false);
        }
    } else if (isSnifActTask) {
        setEnabled(CogToolLID.Paste, availability, false);
        setEnabled(CogToolLID.Duplicate, availability, false, MenuFactory.DUPLICATE_STRING);
        setEnabled(CogToolLID.Cut, availability, false, MenuFactory.CUT_STRING);
        setEnabled(CogToolLID.Copy, availability, false, MenuFactory.COPY_STRING);
        setEnabled(CogToolLID.Rename, availability, hasDesign || singleTask, MenuFactory.RENAME_STRING + label);
        setEnabled(CogToolLID.NewTask, availability, false);
        setEnabled(CogToolLID.NewTaskGroup, availability, false);
    } else {
        setEnabled(CogToolLID.NewTask, availability, true);
        setEnabled(CogToolLID.NewTaskGroup, availability, true);
        setEnabled(CogToolLID.Paste, availability, true);
        String dupString = MenuFactory.DUPLICATE_STRING;
        if (anySelection) {
            dupString += label;
        }
        setEnabled(CogToolLID.Duplicate, availability, anySelection, dupString);
        // Edit enabled if only a single design selected
        String editString = MenuFactory.EDIT_STRING;
        if (hasDesign) {
            editString += label;
        }
        setEnabled(CogToolLID.Edit, availability, hasDesign, editString);
        // Rename enabled if a single selection
        boolean enabled = hasDesign || singleTask;
        String renameString = MenuFactory.RENAME_STRING;
        if (enabled) {
            renameString += label;
        }
        setEnabled(CogToolLID.Rename, availability, enabled, renameString);
        // Cut, Copy, Delete, DeselectAll should be enabled
        //   if there is any selection (task or design)
        setEnabled(CogToolLID.Cut, availability, anySelection, MenuFactory.CUT_STRING + cutCopyLabel);
        setEnabled(CogToolLID.Copy, availability, anySelection, MenuFactory.COPY_STRING + cutCopyLabel);
        setEnabled(CogToolLID.Delete, availability, anySelection, MenuFactory.DELETE_STRING + label);
        setEnabled(CogToolLID.DeselectAll, availability, anySelection);
    }
    boolean showRecompute = anySelection && taskHasComputableScripts(sel);
    if (!showRecompute && hasDesign && sel.getSelectedTaskCount() == 1) {
        Design design = sel.getSelectedDesign();
        TaskApplication taskApp = project.getTaskApplication(sel.getSelectedTask(), design);
        if (taskApp != null && taskApp.getActiveAlgorithm() instanceof SNIFACTPredictionAlgo) {
            showRecompute = true;
        }
    }
    String recomputeString = recomputeTitle;
    if (showRecompute) {
        recomputeString += scriptLabel;
    }
    // If the user wants to call recompute let them.
    setEnabled(CogToolLID.RecomputeScript, availability, showRecompute, recomputeString);
    // The export trace is only available when a script is
    // computed && there are traces to export.
    boolean hasComputedResult = selectionHasComputedResult(sel);
    boolean showExport = anySelection && //hasComputedResult &&
    selectionHasTraces(sel);
    setEnabled(ProjectLID.ExportTraces, availability, showExport);
    setEnabled(ProjectLID.DisplayTraces, availability, showExport);
    setEnabled(ProjectLID.ExportForSanlab, availability, showExport);
    // Show Visualization should only be available when a script is
    // computed/valid && there are ResultSteps to visualize.
    boolean showVis = anySelection && hasComputedResult && selectionHasResultSteps(sel);
    setEnabled(ProjectLID.ShowModelVisualization, availability, showVis);
    // The export device and script lisp files
    // is only available when a script is valid
    // valid IE: not null, not invalid
    boolean showExportFiles = anySelection && selectionHasScripts(sel) && hasComputedResult;
    setEnabled(ProjectLID.ExportActrModelFile, availability, showExportFiles);
    // Default to off; fix if truly enabled
    setEnabled(ProjectLID.MoveTaskEarlier, ListenerIdentifierMap.ALL, false);
    setEnabled(ProjectLID.MoveTaskLater, ListenerIdentifierMap.ALL, false);
    setEnabled(ProjectLID.PromoteTask, ListenerIdentifierMap.ALL, false);
    setEnabled(ProjectLID.DemoteTask, ListenerIdentifierMap.ALL, false);
    // Allow "vertical" movement if effectively only one task is selected
    if ((tasks != null) && !hasDesign) {
        if (singleTask) {
            boolean spawned = tasks[0].isSpawned();
            TaskGroup parent = tasks[0].getTaskGroup();
            List<AUndertaking> siblings;
            if (parent != null) {
                setEnabled(ProjectLID.PromoteTask, ListenerIdentifierMap.ALL, !spawned);
                siblings = parent.getUndertakings();
            } else {
                siblings = project.getUndertakings();
            }
            int siblingCount = siblings.size();
            int atIndex = siblings.indexOf(tasks[0]);
            if (siblingCount > 1) {
                boolean notFirstChild = (atIndex > 0);
                setEnabled(ProjectLID.DemoteTask, ListenerIdentifierMap.ALL, notFirstChild && !spawned);
                setEnabled(ProjectLID.MoveTaskEarlier, ListenerIdentifierMap.ALL, notFirstChild && !spawned);
                setEnabled(ProjectLID.MoveTaskLater, ListenerIdentifierMap.ALL, (atIndex < siblingCount - 1) && !spawned);
            }
        } else if (tasks.length > 1) {
            // Too many tasks selected to check conditions;
            // let the controller handle the error cases.
            setEnabled(ProjectLID.PromoteTask, ListenerIdentifierMap.ALL, !isSnifActTask);
            setEnabled(ProjectLID.DemoteTask, ListenerIdentifierMap.ALL, !isSnifActTask);
        }
    }
    // Stuff that is enabled only when a script exists.
    boolean canExport = false;
    if (hasDesign) {
        Design design = sel.getSelectedDesign();
        for (AUndertaking task : tasks) {
            if (taskHasScripts(task, design)) {
                canExport = true;
            }
        }
    }
    setEnabled(CogToolLID.ExportScriptToCSV, availability, canExport);
    // Enable "Show XXX" options if any task groups are selected
    boolean enabled = false;
    int numTaskGroups = 0;
    TaskGroup group = null;
    for (AUndertaking task : tasks) {
        if (task.isTaskGroup()) {
            enabled = true;
            numTaskGroups++;
            group = (TaskGroup) task;
        }
    }
    setEnabled(ProjectLID.Ungroup, availability, enabled && !isSnifActGroup);
    setEnabled(CogToolLID.ShowSum, availability, enabled && !isSnifActGroup);
    setEnabled(CogToolLID.ShowMean, availability, enabled);
    setEnabled(CogToolLID.ShowMin, availability, enabled);
    setEnabled(CogToolLID.ShowMax, availability, enabled);
    setSelected(CogToolLID.ShowSum, availability, false);
    setSelected(CogToolLID.ShowMean, availability, false);
    setSelected(CogToolLID.ShowMin, availability, false);
    setSelected(CogToolLID.ShowMax, availability, false);
    if (enabled) {
        if (numTaskGroups == 1) {
            GroupNature nature = group.getNature();
            CogToolLID id = null;
            if (nature == GroupNature.SUM) {
                id = CogToolLID.ShowSum;
            } else if (nature == GroupNature.MEAN) {
                id = CogToolLID.ShowMean;
            } else if (nature == GroupNature.MIN) {
                id = CogToolLID.ShowMin;
            } else if (nature == GroupNature.MAX) {
                id = CogToolLID.ShowMax;
            }
            setSelected(id, availability, true);
        }
    }
    IPredictionAlgo defaultAlgo = project.getDefaultAlgo();
    // enabled state for default algorithm settings
    setSelected(ProjectLID.SetProjDefaultAlgoACTR, availability, defaultAlgo == ACTR6PredictionAlgo.ONLY);
    setSelected(ProjectLID.SetProjDefaultAlgoSNIFACT, availability, defaultAlgo == SNIFACTPredictionAlgo.ONLY);
    setSelected(ProjectLID.SetProjExecBackground, availability, project.getDefaultRunInBackground());
    setSelected(ProjectLID.SetProjExecForeground, availability, !project.getDefaultRunInBackground());
    // (TODO: same level/contiguous/subtrees for Group Tasks???)
    // if the user has named the task (created the group), he can export
    boolean canExportHCIPA = false;
    if ((tasks != null) && (tasks.length > 0)) {
        // Must have selected a top-level group
        for (AUndertaking task : tasks) {
            if (task.isTaskGroup() && (task.getTaskGroup() == null)) {
                canExportHCIPA = true;
            }
        }
    } else if (hasDesign) {
        // At least one top-level task must be a group
        Iterator<AUndertaking> allTasks = project.getUndertakings().iterator();
        while (allTasks.hasNext()) {
            AUndertaking u = allTasks.next();
            if (u.isTaskGroup()) {
                canExportHCIPA = true;
            }
        }
    }
    setEnabled(ProjectLID.ExportToHCIPA, availability, canExportHCIPA);
    if (hasDesign) {
        ISimilarityDictionary dict = (ISimilarityDictionary) sel.getSelectedDesign().getAttribute(WidgetAttributes.DICTIONARY_ATTR);
        String newLabel = NullSafe.equals(dict, WidgetAttributes.NO_DICTIONARY) ? L10N.get("WT.GenerateDictionary", "Generate Dictionary...") : L10N.get("WT.UpdateDictionary", "Update Dictionary...");
        setEnabled(ProjectLID.GenerateDictionary, availability, !isSnifActTask, newLabel);
    } else if (tasks.length > 0) {
        List<Design> designs = project.getDesigns();
        String newLabel = designs.size() > 1 ? L10N.get("WT.UpdateDictionaries", "Update Dictionaries...") : L10N.get("WT.UpdateDictionary", "Update Dictionary...");
        setEnabled(ProjectLID.GenerateDictionary, availability, !isSnifActTask, newLabel);
    }
}
Also used : IPredictionAlgo(edu.cmu.cs.hcii.cogtool.model.IPredictionAlgo) Point(org.eclipse.swt.graphics.Point) Design(edu.cmu.cs.hcii.cogtool.model.Design) CogToolLID(edu.cmu.cs.hcii.cogtool.CogToolLID) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) Iterator(java.util.Iterator) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) SNIFACTPredictionAlgo(edu.cmu.cs.hcii.cogtool.model.SNIFACTPredictionAlgo) List(java.util.List) ISimilarityDictionary(edu.cmu.cs.hcii.cogtool.model.ISimilarityDictionary) TaskGroup(edu.cmu.cs.hcii.cogtool.model.TaskGroup) GroupNature(edu.cmu.cs.hcii.cogtool.model.GroupNature)

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