Search in sources :

Example 1 with TaskGroup

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

the class ScriptViewerUI method addSelectionChangeListeners.

/**
     * Add the selection Change event listeners.
     */
protected void addSelectionChangeListeners() {
    SWTselectionChangeHandler = new SelectionListener() {

        public void widgetSelected(SelectionEvent evt) {
            SWTList swtList = view.getScriptEditorList();
            TableItem[] selectedItems = swtList.getSelectionObject();
            for (TableItem selectedItem : selectedItems) {
                // TODO: Currently supports only single selection.
                Object data = selectedItem.getData();
                if (data instanceof Frame) {
                    selection.setSelectedState(null);
                } else {
                    selection.setSelectedState(selectedItem);
                }
            }
            setViewEnabledState(selection, ListenerIdentifierMap.NORMAL);
        // Let selection change handle changing the frame
        }

        public void widgetDefaultSelected(SelectionEvent evt) {
            SWTList swtList = view.getScriptEditorList();
            TableItem[] selectedItems = swtList.getSelectionObject();
            // TODO: Currently supports only single selection.
            for (TableItem selectedItem : selectedItems) {
                Object data = selectedItem.getData();
                if (data instanceof DefaultModelGeneratorState) {
                    Script s = (Script) selectedItem.getData(SWTListGroupScript.SCRIPT_DATA_KEY);
                    DefaultModelGeneratorState stepState = (DefaultModelGeneratorState) data;
                    // In case we need this; not a context selection
                    // in truth, but we can re-use the structure.
                    contextSelection.setSelectedState(stepState);
                    performAction(ProjectLID.EditScript, s);
                }
            }
        }
    };
    view.addSWTListSelectionHandler(SWTselectionChangeHandler);
    AlertHandler selectionChangeHandler = new AlertHandler() {

        public void handleAlert(EventObject alert) {
            SEDemoSelectionState.StepStateSelectionChange event = (SEDemoSelectionState.StepStateSelectionChange) alert;
            if (event != null) {
                if (event.selected) {
                    DefaultModelGeneratorState stepState = event.changedState;
                    Frame resultFrame = null;
                    Script script = getSelectedScript(stepState);
                    AUndertaking t = script.getDemonstration().getTaskApplication().getTask();
                    if (stepState != null) {
                        resultFrame = stepState.getScriptStep().getCurrentFrame();
                    } else if (script != null) {
                        resultFrame = script.getDemonstration().getResultFrame();
                    }
                    DefaultModelGeneratorState overrideState = script.getPreviousState(stepState);
                    if (overrideState == null) {
                        TaskGroup group = (TaskGroup) task;
                        List<AUndertaking> siblingTasks = group.getUndertakings();
                        int currentTaskIndex = siblingTasks.indexOf(t);
                        CognitiveModelGenerator modelGen = script.getModelGenerator();
                        while ((overrideState == null) && (0 <= --currentTaskIndex)) {
                            AUndertaking prevSibling = siblingTasks.get(currentTaskIndex);
                            TaskApplication ta = project.getTaskApplication(prevSibling, design);
                            if (ta != null) {
                                script = ta.getScript(modelGen);
                                if (script != null) {
                                    overrideState = script.getLastState();
                                }
                            }
                        }
                    }
                    uiModel.setCurrentOverride(script, overrideState);
                    try {
                        setCurrentFrame(resultFrame);
                    } catch (GraphicsUtil.ImageException ex) {
                        throw new RcvrImageException("Changing current demonstration frame", ex);
                    }
                }
            }
        }
    };
    selection.addHandler(this, SEDemoSelectionState.StepStateSelectionChange.class, selectionChangeHandler);
}
Also used : Script(edu.cmu.cs.hcii.cogtool.model.Script) SWTListGroupScript(edu.cmu.cs.hcii.cogtool.view.SWTListGroupScript) Frame(edu.cmu.cs.hcii.cogtool.model.Frame) TableItem(org.eclipse.swt.widgets.TableItem) CognitiveModelGenerator(edu.cmu.cs.hcii.cogtool.model.CognitiveModelGenerator) EventObject(java.util.EventObject) SWTList(edu.cmu.cs.hcii.cogtool.view.SWTList) RcvrImageException(edu.cmu.cs.hcii.cogtool.util.RcvrImageException) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) SelectionEvent(org.eclipse.swt.events.SelectionEvent) EventObject(java.util.EventObject) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) AlertHandler(edu.cmu.cs.hcii.cogtool.util.AlertHandler) GraphicsUtil(edu.cmu.cs.hcii.cogtool.util.GraphicsUtil) TaskGroup(edu.cmu.cs.hcii.cogtool.model.TaskGroup) DefaultModelGeneratorState(edu.cmu.cs.hcii.cogtool.model.DefaultModelGeneratorState) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 2 with TaskGroup

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

the class ProjectUI method commitRenameTask.

// initiateTaskRename
/**
     * Reports a task renaming to the controller.
     * @param item
     */
protected boolean commitRenameTask(boolean activeCommit) {
    boolean success = true;
    if (editor.getEditor() != null) {
        Text text = (Text) editor.getEditor();
        String newName = text.getText();
        TreeItem item = editor.getItem();
        // Get task & parent taskgroup from item, don't use this.selection!
        AUndertaking taskToRename = (AUndertaking) item.getData();
        TreeItem parentItem = item.getParentItem();
        TaskGroup parentGroup = (TaskGroup) ((parentItem != null) ? parentItem.getData() : null);
        cleanupTaskEditor();
        success = performAction((CogToolPref.HCIPA.getBoolean()) ? ProjectLID.HCIPARenameTask : ProjectLID.RenameTask, new ProjectUI.TaskRenameEvent(taskToRename, newName, parentGroup), false);
        if (activeCommit) {
            renameTaskItem = null;
        }
    }
    return success;
}
Also used : TreeItem(org.eclipse.swt.widgets.TreeItem) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) Text(org.eclipse.swt.widgets.Text) ManagedText(edu.cmu.cs.hcii.cogtool.util.ManagedText) TaskGroup(edu.cmu.cs.hcii.cogtool.model.TaskGroup)

Example 3 with TaskGroup

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

the class ProjectMouseState method dealWithMouseDoubleClick.

@Override
protected void dealWithMouseDoubleClick(MouseEvent me) {
    super.dealWithMouseDoubleClick(me);
    TreeItem item = ui.tree.getItem(new Point(me.x, me.y));
    TreeColumn column = ui.findColumn(me.x);
    // check to see if the group visibility should toggle
    if ((item != null) && (column == null)) {
        // Toggle tree expand when a TaskGroup is double-clicked,
        // but not if double-clicking on the first column to edit the name
        AUndertaking u = (AUndertaking) item.getData();
        if (u.isTaskGroup()) {
            item.setExpanded(!item.getExpanded());
        }
    }
    // If on a valid cell, either edit script or open the script viewer
    if ((item != null) && (column != null) && (column.getData() != null)) {
        AUndertaking u = (AUndertaking) item.getData();
        // At the intersection of a task and design
        ProjectContextSelectionState seln = new ProjectContextSelectionState(ui.getProject());
        seln.setSelectedDesign((Design) column.getData());
        seln.addSelectedTask(u);
        if (u.isTaskGroup()) {
            TaskGroup group = (TaskGroup) u;
            if (GroupNature.SUM.equals(group.getNature())) {
                item.setExpanded(true);
                ui.cleanupTaskEditor();
                //TODO: won't work since repaint won't occur until after we're all done.
                ui.performAction(ProjectLID.ViewGroupScript, seln);
            }
        } else {
            ui.cleanupTaskEditor();
            //TODO: won't work since repaint won't occur until after we're all done.
            ui.performAction(ProjectLID.EditScript, seln);
        }
    } else if ((item != null) && (column != null) && (column.getData() == null)) {
        // In a valid row, first column
        if (ui.treeOperationOccurred == 0) {
            ui.initiateTaskRename(item, true);
        }
    }
}
Also used : TreeItem(org.eclipse.swt.widgets.TreeItem) TreeColumn(org.eclipse.swt.widgets.TreeColumn) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) Point(org.eclipse.swt.graphics.Point) TaskGroup(edu.cmu.cs.hcii.cogtool.model.TaskGroup)

Example 4 with TaskGroup

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

the class ProjectSelectionState method getSelectedTaskParents.

/**
     * Retrieves the parents of all selected tasks/groups.
     *
     * @return an array of task groups, using null to signify root tasks/groups
     */
public TaskGroup[] getSelectedTaskParents() {
    int selectedItemCount = getSelectedTaskCount();
    TaskGroup[] parents = new TaskGroup[selectedItemCount];
    Iterator<AUndertaking> selectedTasks = getSelectedTaskIterator();
    int i = 0;
    while (selectedTasks.hasNext()) {
        AUndertaking task = selectedTasks.next();
        parents[i++] = task.getTaskGroup();
    }
    return parents;
}
Also used : AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) TaskGroup(edu.cmu.cs.hcii.cogtool.model.TaskGroup)

Example 5 with TaskGroup

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

the class ProjectSelectionState method getSelectedTaskParent.

/**
     * Retrieves the parent task group that contains the selected undertaking.
     *
     * @return the parent task group if a all selected undertakings have the
     *         same parent; <code>null</code> is returned if there are no
     *         selected undertakings or if there are multiple selected
     *         undertakings with different parents or if all selected
     *         undertakings are top-level.
     */
public TaskGroup getSelectedTaskParent() {
    boolean first = true;
    TaskGroup allParent = null;
    // Examine the parent task group for each selected undertaking
    Iterator<AUndertaking> taskIt = getSelectedTaskIterator();
    while (taskIt.hasNext()) {
        AUndertaking item = taskIt.next();
        TaskGroup parentOfItem = item.getTaskGroup();
        // then null is the only possible response.
        if (parentOfItem == null) {
            return null;
        }
        // Remember first parent to compare against the remaining ones
        if (first) {
            first = false;
            allParent = parentOfItem;
        } else if (parentOfItem != allParent) {
            // return null
            return null;
        }
    }
    // If there is no selected undertaking, return null
    if (allParent == null) {
        return null;
    }
    // Otherwise, return the shared parent task group
    return allParent;
}
Also used : AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) 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