Search in sources :

Example 1 with DefaultModelGeneratorState

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

the class SEDemoUI method showSelectionContextMenu.

/**
     * Mouse event occurred on the table, use the selected item to
     * display an appropriate menu.
     */
public void showSelectionContextMenu(int x, int y) {
    contextSelection.deselectAll();
    Table historyTable = view.getHistoryTable();
    org.eclipse.swt.graphics.Point atPoint = historyTable.toControl(x, y);
    TableItem ti = historyTable.getItem(atPoint);
    if ((ti != null) && (ti.getData() instanceof DefaultModelGeneratorState)) {
        contextSelection.setSelectedState((DefaultModelGeneratorState) ti.getData());
    } else {
        // this is the result Step, so no selection
        historyTable.select(historyTable.getItemCount() - 1);
    }
    showContextMenu(contextSelection, true);
}
Also used : Table(org.eclipse.swt.widgets.Table) TableItem(org.eclipse.swt.widgets.TableItem) DefaultModelGeneratorState(edu.cmu.cs.hcii.cogtool.model.DefaultModelGeneratorState)

Example 2 with DefaultModelGeneratorState

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

the class SEDemoUI 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 {
                    // should be instanceof DefaultModelGeneratorState!!!
                    AScriptStep step = ((DefaultModelGeneratorState) data).getScriptStep();
                    if (step instanceof HearScriptStep) {
                        if (interaction.askEditFrame()) {
                            Frame f = step.getCurrentFrame();
                            performAction(DesignEditorLID.EditFrame, f);
                        }
                        TableItem previousSelectedRow = swtList.getRowItem(selection.getPreviousSelection());
                        selection.setSelectedState(previousSelectedRow);
                    } else {
                        selection.setSelectedState(selectedItem);
                    }
                }
            }
            centerSelectedRegion();
            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) {
                    DefaultModelGeneratorState stepState = (DefaultModelGeneratorState) data;
                    AScriptStep step = stepState.getScriptStep();
                    // In case we need this; not a context selection
                    // in truth, but we can re-use the structure.
                    contextSelection.setSelectedState(stepState);
                    if (editable) {
                        if (step instanceof DelayScriptStep) {
                            performAction(SEDemoLID.ChangeWaitProperties, contextSelection);
                        } else if (step instanceof ThinkScriptStep) {
                            performAction(SEDemoLID.ChangeThinkProperties, contextSelection);
                        } else if (isEditable(step)) {
                            performAction(SEDemoLID.Edit, contextSelection);
                        }
                    }
                }
            }
        }
    };
    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;
                    uiModel.setCurrentOverride(script, script.getPreviousState(stepState));
                    Frame resultFrame = null;
                    if (stepState != null) {
                        resultFrame = stepState.getScriptStep().getCurrentFrame();
                    } else {
                        resultFrame = script.getDemonstration().getResultFrame();
                    }
                    try {
                        setCurrentFrame(resultFrame);
                    } catch (GraphicsUtil.ImageException ex) {
                        throw new RcvrImageException("Changing current demonstration frame", ex);
                    }
                } else {
                    // deselect item.
                    uiModel.setCurrentOverride(script, script.getLastState());
                }
            }
        }
    };
    selection.addHandler(this, SEDemoSelectionState.StepStateSelectionChange.class, selectionChangeHandler);
}
Also used : DelayScriptStep(edu.cmu.cs.hcii.cogtool.model.DelayScriptStep) Frame(edu.cmu.cs.hcii.cogtool.model.Frame) TableItem(org.eclipse.swt.widgets.TableItem) AScriptStep(edu.cmu.cs.hcii.cogtool.model.AScriptStep) EventObject(java.util.EventObject) ThinkScriptStep(edu.cmu.cs.hcii.cogtool.model.ThinkScriptStep) SWTList(edu.cmu.cs.hcii.cogtool.view.SWTList) RcvrImageException(edu.cmu.cs.hcii.cogtool.util.RcvrImageException) SelectionEvent(org.eclipse.swt.events.SelectionEvent) HearScriptStep(edu.cmu.cs.hcii.cogtool.model.HearScriptStep) EventObject(java.util.EventObject) AlertHandler(edu.cmu.cs.hcii.cogtool.util.AlertHandler) GraphicsUtil(edu.cmu.cs.hcii.cogtool.util.GraphicsUtil) DefaultModelGeneratorState(edu.cmu.cs.hcii.cogtool.model.DefaultModelGeneratorState) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 3 with DefaultModelGeneratorState

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

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

the class ScriptViewerUI method showSelectionContextMenu.

/**
     * Mouse event occurred on the table, use the selected item to
     * display an appropriate menu.
     *
     */
public void showSelectionContextMenu(int x, int y) {
    contextSelection.deselectAll();
    Table historyTable = view.getHistoryTable();
    org.eclipse.swt.graphics.Point atPoint = historyTable.toControl(x, y);
    TableItem ti = historyTable.getItem(atPoint);
    if ((ti != null) && (ti.getData() instanceof DefaultModelGeneratorState)) {
        contextSelection.setSelectedState((DefaultModelGeneratorState) ti.getData());
    } else {
        // this is the result Step, so no selection
        historyTable.select(historyTable.getItemCount() - 1);
    }
    showContextMenu(contextSelection, true);
}
Also used : Table(org.eclipse.swt.widgets.Table) TableItem(org.eclipse.swt.widgets.TableItem) DefaultModelGeneratorState(edu.cmu.cs.hcii.cogtool.model.DefaultModelGeneratorState)

Example 5 with DefaultModelGeneratorState

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

the class SEDemoController method assignActions.

@Override
public void assignActions() {
    super.assignActions();
    ui.setAction(SEDemoLID.Undo, new UndoController.UndoAction(undoMgr, interaction));
    ui.setAction(SEDemoLID.Redo, new UndoController.RedoAction(undoMgr, interaction));
    ui.setAction(SEDemoLID.SetMouseHand, createSetMouseHandAction());
    ui.setAction(SEDemoLID.SetHandLocation, createSetHandLocationAction());
    ui.setAction(SEDemoLID.PerformTransition, createPerformTransitionAction());
    ui.setAction(SEDemoLID.InsertThink, new IListenerAction() {

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

        public boolean performAction(Object prms) {
            SEDemoSelectionState selection = (SEDemoSelectionState) prms;
            return performInsertThink(selection);
        }
    });
    ui.setAction(SEDemoLID.ChangeThinkProperties, new IListenerAction() {

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

        public boolean performAction(Object prms) {
            SEDemoSelectionState selection = (SEDemoSelectionState) prms;
            return performChangeThink(selection);
        }
    });
    ui.setAction(SEDemoLID.InsertDelay, new IListenerAction() {

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

        public boolean performAction(Object prms) {
            SEDemoSelectionState selection = (SEDemoSelectionState) prms;
            return performInsertDelay(selection);
        }
    });
    ui.setAction(SEDemoLID.ChangeWaitProperties, new IListenerAction() {

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

        public boolean performAction(Object prms) {
            SEDemoSelectionState selection = (SEDemoSelectionState) prms;
            return performChangeDelay(selection);
        }
    });
    ui.setAction(SEDemoLID.Edit, new IListenerAction() {

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

        public boolean performAction(Object prms) {
            SEDemoSelectionState selection = (SEDemoSelectionState) prms;
            DefaultModelGeneratorState selectedState = selection.getSelectedState();
            if (selectedState == null) {
                interaction.protestNoStep();
                return false;
            }
            AScriptStep step = selectedState.getScriptStep();
            if (step instanceof ThinkScriptStep) {
                return performChangeThink(selection);
            }
            if (step instanceof DelayScriptStep) {
                return performChangeDelay(selection);
            }
            if ((step instanceof ActionScriptStep) && step.isDemonstrated() && step.isInsertedByUser()) {
                return performEditSelfTransition((ActionScriptStep) step);
            }
            step = step.getOwner();
            if ((step instanceof ActionScriptStep) && step.isDemonstrated() && step.isInsertedByUser()) {
                return performEditSelfTransition((ActionScriptStep) step);
            }
            interaction.protestNotEditable();
            return false;
        }
    });
    ui.setAction(SEDemoLID.InsertDrive, new IListenerAction() {

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

        public boolean performAction(Object prms) {
            SEDemoSelectionState selection = (SEDemoSelectionState) prms;
            return performInsertDrive(selection);
        }
    });
    ui.setAction(SEDemoLID.InsertLookAt, new IListenerAction() {

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

        public boolean performAction(Object prms) {
            SEDemoUI.LookAtTransition lookAt = (SEDemoUI.LookAtTransition) prms;
            return performInsertLookAt(lookAt.selection, lookAt.target);
        }
    });
    ui.setAction(SEDemoLID.InsertSelfTransition, createInsertSelfTransitionAction());
    ui.setAction(SEDemoLID.Delete, new IListenerAction() {

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

        public boolean performAction(Object prms) {
            // If not the "most recent" step state, warn
            // the user that this will remove all
            // items after as well, unless it's a think,
            // look-at or other non-transitioning item.
            SEDemoSelectionState selection = (SEDemoSelectionState) prms;
            return deleteScriptStep(selection);
        }
    });
    ui.setAction(SEDemoLID.RegenerateScript, createRegenerateScriptAction());
    ui.setAction(SEDemoLID.RecomputeScript, createSaveScriptChangesAction());
    ui.setAction(SEDemoLID.ExportScriptToCSV, createExportScriptToCSVAction());
    ui.setAction(DesignEditorLID.EditFrame, createEditFrameAction());
    ui.setAction(SEDemoLID.ShowModelVisualization, createShowModelVisualizationAction());
}
Also used : DelayScriptStep(edu.cmu.cs.hcii.cogtool.model.DelayScriptStep) ActionScriptStep(edu.cmu.cs.hcii.cogtool.model.ActionScriptStep) AScriptStep(edu.cmu.cs.hcii.cogtool.model.AScriptStep) ThinkScriptStep(edu.cmu.cs.hcii.cogtool.model.ThinkScriptStep) SEDemoUI(edu.cmu.cs.hcii.cogtool.ui.SEDemoUI) IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) SEDemoSelectionState(edu.cmu.cs.hcii.cogtool.ui.SEDemoSelectionState) DefaultModelGeneratorState(edu.cmu.cs.hcii.cogtool.model.DefaultModelGeneratorState)

Aggregations

DefaultModelGeneratorState (edu.cmu.cs.hcii.cogtool.model.DefaultModelGeneratorState)21 Demonstration (edu.cmu.cs.hcii.cogtool.model.Demonstration)9 ThinkScriptStep (edu.cmu.cs.hcii.cogtool.model.ThinkScriptStep)7 AUndoableEdit (edu.cmu.cs.hcii.cogtool.util.AUndoableEdit)7 AScriptStep (edu.cmu.cs.hcii.cogtool.model.AScriptStep)6 TableItem (org.eclipse.swt.widgets.TableItem)6 ComputationUndoRedo (edu.cmu.cs.hcii.cogtool.controller.DemoScriptCmd.ComputationUndoRedo)5 TaskApplication (edu.cmu.cs.hcii.cogtool.model.TaskApplication)5 IUndoableEdit (edu.cmu.cs.hcii.cogtool.util.IUndoableEdit)5 DelayScriptStep (edu.cmu.cs.hcii.cogtool.model.DelayScriptStep)4 Frame (edu.cmu.cs.hcii.cogtool.model.Frame)4 HandLocation (edu.cmu.cs.hcii.cogtool.model.HandLocation)4 Script (edu.cmu.cs.hcii.cogtool.model.Script)4 EventObject (java.util.EventObject)4 Table (org.eclipse.swt.widgets.Table)3 AUndertaking (edu.cmu.cs.hcii.cogtool.model.AUndertaking)2 CognitiveModelGenerator (edu.cmu.cs.hcii.cogtool.model.CognitiveModelGenerator)2 Design (edu.cmu.cs.hcii.cogtool.model.Design)2 SEDemoInteraction (edu.cmu.cs.hcii.cogtool.ui.SEDemoInteraction)2 AlertHandler (edu.cmu.cs.hcii.cogtool.util.AlertHandler)2