Search in sources :

Example 26 with AUndertaking

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

the class ProjectController method createShowModelVisualizationAction.

// Action for ShowVisualization
protected IListenerAction createShowModelVisualizationAction() {
    return new IListenerAction() {

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

        public boolean performAction(Object prms) {
            ProjectSelectionState seln = (ProjectSelectionState) prms;
            // Must have selected tasks and design
            Design design = seln.getSelectedDesign();
            AUndertaking[] tasks = seln.getSelectedTasks(TaskSelectionState.PRUNE_SELECTION);
            if ((design == null) || (tasks == null) || (tasks.length == 0)) {
                return false;
            }
            boolean visCreated = false;
            for (AUndertaking task : tasks) {
                if (createVisualization(design, task, -1)) {
                    visCreated = true;
                    break;
                }
            }
            if (!visCreated) {
                interaction.reportProblem(visualizationNotCreated, noResultsToVisualize);
            }
            return visCreated;
        }
    };
}
Also used : 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) ProjectSelectionState(edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking)

Example 27 with AUndertaking

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

the class SWTTreeProjectSelectionState method setSelectedCell.

/**
     * Support for selecting a cell
     */
public void setSelectedCell(TreeItem item, TreeColumn column) {
    if ((item != null) && (column != null)) {
        AUndertaking t = (AUndertaking) item.getData();
        Design d = (Design) column.getData();
        if ((t != null) && (d != null)) {
            deselectAll();
            selectedColumns.add(column);
            selectedItems.put(t, item);
            raiseAlert(new ProjectSelectionChange(this, tree.indexOf(column), item, true));
        }
    }
}
Also used : Design(edu.cmu.cs.hcii.cogtool.model.Design) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking)

Example 28 with AUndertaking

use of edu.cmu.cs.hcii.cogtool.model.AUndertaking 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 29 with AUndertaking

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

the class ProjectUI method initiateTaskRename.

// initiateTaskRename
/**
     * Triggers the task-renaming functionality in the UI on the given
     * TreeItem's AUndertaking.
     */
public void initiateTaskRename(TreeItem taskToRenameItem, boolean selectAll) {
    // Can progress only if no other rename is already in progress
    if ((editor.getEditor() == null) && (taskToRenameItem != null)) {
        // Ensure the selection is set properly so it looks right when done
        selection.setSelectedItem(taskToRenameItem);
        final AUndertaking task = (AUndertaking) taskToRenameItem.getData();
        // The editor must have the same size as the cell.
        editor.horizontalAlignment = SWT.LEFT;
        editor.grabHorizontal = true;
        // The control that will be the editor must be a child of the Tree
        ManagedText newEditor = new ManagedText(tree, SWT.SINGLE | SWT.LEFT, Keypad.FULL_KEYPAD) {

            @Override
            public boolean confirm(int focusRule) {
                return commitRenameTask(true);
            }

            @Override
            public void cancel() {
                cleanupTaskEditor();
            }
        };
        newEditor.setFocus();
        String taskName = task.getName();
        int nameLength = taskName.length();
        newEditor.setText(taskName);
        if (selectAll) {
            newEditor.selectAll();
        } else {
            newEditor.setSelection(nameLength, nameLength);
        }
        editor.setEditor(newEditor, taskToRenameItem);
        setViewEnabledState(selection, ListenerIdentifierMap.NORMAL);
    }
}
Also used : AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) ManagedText(edu.cmu.cs.hcii.cogtool.util.ManagedText) Point(org.eclipse.swt.graphics.Point)

Example 30 with AUndertaking

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

the class ProjectUI method showContextMenu.

// Override to set the correct context menu on the frame
//    item  item-selected column design  where          selection to use
//(a)  ok        n/a        ok     ok    cell           temporary cell
//(b)  ok        yes        ok    null   task           normal selection
//(c)  ok        no         ok    null   task           temporary task
//(d)  ok        n/a       null    n/a   right of cells temporary task
//(e) null       n/a        ok     ok    design         temporary design
//(f) null       n/a        ok    null   bottom-left    no selection
//(g) null       n/a       null    n/a   bottom-right   no selection
// TODO: dfm -- make the code match the above!!!!!
@Override
public void showContextMenu(int x, int y) {
    // Clear any stale state
    contextSelection.deselectAll();
    // Check which region of the frame was hit
    TreeItem item = tree.getItem(new Point(x, y));
    TreeColumn column = findColumn(x);
    // See if the context invocation was made beyond all designs
    if (column == null) {
        if (item == null) {
            // see (g) above
            showContextMenu();
        } else {
            // see (d) above
            selectOverBox(item.getBounds());
            contextSelection.addSelectedTask((AUndertaking) item.getData());
            showContextMenu(contextSelection, View.CONTEXT);
        }
    } else // If not, the invocation occurred somewhere within the table
    {
        Design design = (Design) column.getData();
        // Detect a context invocation in the table header/footer
        if (item == null) {
            // Detect a context invocation under the "tasks" heading
            if (design == null) {
                // see (f) above
                showContextMenu();
            } else // Otherwise the invocation lies under a design heading
            {
                // see (e) above
                // TODO: Really?  What if something else was selected?
                selectOverBox(computeColumnArea(column));
                contextSelection.setSelectedDesign(design);
                showContextMenu(contextSelection, View.CONTEXT);
            }
        } else // Detect a context invocation inside the table body
        {
            AUndertaking undertaking = (AUndertaking) item.getData();
            // Check for context invocation under the "tasks" column
            if (design == null) {
                // Set up the contextual selection state as necessary
                if (selection.isTaskSelected(undertaking)) {
                    // see (b) above
                    showContextMenu();
                } else {
                    // see (c) above
                    selectOverBox(item.getBounds());
                    contextSelection.addSelectedTask(undertaking);
                    showContextMenu(contextSelection, View.CONTEXT);
                }
            } else // Otherwise at the intersection of a task and a design
            {
                // see (a) above
                selection.setSelectedCell(item, column);
                Rectangle bounds = item.getBounds(tree.indexOf(column));
                if (OSUtils.MACOSX) {
                    // XXX: DIRTY HACK TO fix SWT bug.
                    bounds.y -= 1;
                    bounds.height += 1;
                }
                selectOverBox(bounds);
                // TODO: instead of the following, pass undertaking and
                //       design in to showContextMenuForIntersection()
                Menu contextMenu = view.getContextMenuForIntersection(project, undertaking, design);
                // Set up the contextual selection state as necessary
                contextSelection.setSelectedDesign(design);
                contextSelection.addSelectedTask(undertaking);
                setViewEnabledState(contextSelection, ListenerIdentifierMap.CONTEXT);
                contextMenu.setVisible(true);
            }
        }
    }
}
Also used : Design(edu.cmu.cs.hcii.cogtool.model.Design) TreeItem(org.eclipse.swt.widgets.TreeItem) TreeColumn(org.eclipse.swt.widgets.TreeColumn) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) Menu(org.eclipse.swt.widgets.Menu)

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