Search in sources :

Example 1 with SelectionEvent

use of org.eclipse.swt.events.SelectionEvent 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 2 with SelectionEvent

use of org.eclipse.swt.events.SelectionEvent 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 3 with SelectionEvent

use of org.eclipse.swt.events.SelectionEvent in project cogtool by cogtool.

the class StoppableProgressBar method addBelowBar.

@Override
protected void addBelowBar() {
    super.addBelowBar();
    // box, tying it to the given pausable "process" object.
    if (stopListener != null) {
        stopButton = new Button(shell, SWT.PUSH);
        stopButton.setText(STOP_LABEL);
        stopButton.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent evt) {
                stopListener.stop();
                stopButton.setEnabled(false);
            }
        });
        FormData data = new FormData();
        // Replace positioning for cancelButton if present
        if (cancelButton != null) {
            data.left = new FormAttachment(50, 3);
            data.top = new FormAttachment(bar, 5, SWT.BOTTOM);
            cancelButton.setLayoutData(data);
            data = new FormData();
            data.right = new FormAttachment(50, -3);
            data.top = new FormAttachment(bar, 5, SWT.BOTTOM);
        } else {
            data.left = new FormAttachment(bar, 0, SWT.CENTER);
            data.top = new FormAttachment(bar, 5, SWT.BOTTOM);
        }
        stopButton.setLayoutData(data);
    }
}
Also used : FormData(org.eclipse.swt.layout.FormData) Button(org.eclipse.swt.widgets.Button) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) FormAttachment(org.eclipse.swt.layout.FormAttachment)

Example 4 with SelectionEvent

use of org.eclipse.swt.events.SelectionEvent in project cogtool by cogtool.

the class ThreadProgressBar method addBelowBar.

@Override
protected void addBelowBar() {
    FormData data = new FormData();
    // at the top of the dialog box otherwise
    if (statusLabel != null) {
        data.top = new FormAttachment(statusLabel, 10, SWT.BOTTOM);
        data.bottom = new FormAttachment(statusLabel, 25, SWT.BOTTOM);
    } else {
        data.top = new FormAttachment(0, 10);
        data.bottom = new FormAttachment(0, 25);
    }
    data.left = new FormAttachment(0, 20);
    data.right = new FormAttachment(100, -20);
    bar.setLayoutData(data);
    // box, tying it to the given cancelable "process" object.
    if (cancelListener != null) {
        cancelButton = new Button(shell, SWT.PUSH);
        cancelButton.setText(L10N.get("B.Cancel", "Cancel"));
        cancelButton.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent evt) {
                // Called from the main UI thread
                cancelListener.cancel();
                cancelButton.setEnabled(false);
            }
        });
        data = new FormData();
        data.left = new FormAttachment(bar, 0, SWT.CENTER);
        data.top = new FormAttachment(bar, 5, SWT.BOTTOM);
        cancelButton.setLayoutData(data);
    }
}
Also used : FormData(org.eclipse.swt.layout.FormData) Button(org.eclipse.swt.widgets.Button) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) FormAttachment(org.eclipse.swt.layout.FormAttachment)

Example 5 with SelectionEvent

use of org.eclipse.swt.events.SelectionEvent in project cogtool by cogtool.

the class ActionPropertySet method createEmptyComposite.

protected Composite createEmptyComposite() {
    Composite c = new Composite(actionSettings, SWT.NONE);
    c.setLayout(new FormLayout());
    ListenerIdentifierMap lidMap = view.getLIDMap();
    designNameLabel = new DisplayLabel(c, SWT.NONE);
    designNameLabel.setText(nameLabel);
    designName = new View.PerformActionText(c, SWT.SINGLE | SWT.BORDER) {

        @Override
        protected void onFocus() {
            super.onFocus();
            view.getTransmuter().setLIDEnabledState();
        }

        @Override
        protected boolean doChangeAction() {
            Design design = (Design) designName.getData();
            DesignEditorUI.DesignRenameParameters parms = new DesignEditorUI.DesignRenameParameters(design, designName.getText());
            boolean changed = view.performAction(ProjectLID.RenameDesign, parms, true);
            if (!changed) {
                designName.setText(design.getName());
            }
            return changed;
        }
    };
    inputDevicesLabel = new DisplayLabel(c, SWT.NONE);
    inputDevicesLabel.setText(L10N.get("APS.InputDevices", "Input Devices") + ":");
    outputDevicesLabel = new DisplayLabel(c, SWT.NONE);
    outputDevicesLabel.setText(L10N.get("APS.OutputDevices", "Output Devices") + ":");
    for (int i = 0; i < DeviceType.DISPLAY_ORDER.length; i++) {
        deviceButtons[i] = new Button(c, SWT.CHECK);
        deviceButtons[i].setText(DeviceType.DISPLAY_ORDER[i].getName());
        deviceButtons[i].setEnabled(false);
        deviceButtons[i].setSelection(false);
    }
    addDevices = new Button(c, SWT.PUSH);
    addDevices.setText(addDevicesLabel);
    addDevices.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent evt) {
            view.performAction(DesignEditorLID.AddDesignDevices);
        }
    });
    lidMap.addWidget(DesignEditorLID.AddDesignDevices, addDevices, ListenerIdentifierMap.NORMAL);
    skinLabel = new DisplayLabel(c, SWT.NONE);
    skinLabel.setText(DESIGN_SKIN);
    skinCombo = new ComboWithEnableFix(c, SWT.DROP_DOWN | SWT.READ_ONLY);
    for (int i = 1; i < SkinType.DISPLAY.length - 1; i++) {
        // Don't allow None or Palm
        skinCombo.add(SkinType.DISPLAY[i].getName());
    }
    skinCombo.select(0);
    skinCombo.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent evt) {
            switch(skinCombo.getSelectionIndex()) {
                case 0:
                default:
                    {
                        view.performAction(DesignEditorLID.SkinWireFrame);
                        break;
                    }
                case 1:
                    {
                        view.performAction(DesignEditorLID.SkinMacOSX);
                        break;
                    }
                case 2:
                    {
                        view.performAction(DesignEditorLID.SkinWinXP);
                        break;
                    }
            }
        }
    });
    frameTreeLabel = new DisplayLabel(c, SWT.NONE);
    frameTreeLabel.setText(FRAMES);
    frameTree = new Tree(c, SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER);
    frameTree.setLinesVisible(true);
    updater = new TreeItemUpdater.FrameItemUpdater(frameTree);
    return c;
}
Also used : FormLayout(org.eclipse.swt.layout.FormLayout) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Point(org.eclipse.swt.graphics.Point) DisplayLabel(edu.cmu.cs.hcii.cogtool.util.DisplayLabel) Design(edu.cmu.cs.hcii.cogtool.model.Design) DesignEditorUI(edu.cmu.cs.hcii.cogtool.ui.DesignEditorUI) Button(org.eclipse.swt.widgets.Button) ListenerIdentifierMap(edu.cmu.cs.hcii.cogtool.util.ListenerIdentifierMap) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Tree(org.eclipse.swt.widgets.Tree) ComboWithEnableFix(edu.cmu.cs.hcii.cogtool.util.ComboWithEnableFix)

Aggregations

SelectionEvent (org.eclipse.swt.events.SelectionEvent)971 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)831 GridData (org.eclipse.swt.layout.GridData)572 GridLayout (org.eclipse.swt.layout.GridLayout)481 Composite (org.eclipse.swt.widgets.Composite)479 Button (org.eclipse.swt.widgets.Button)468 Label (org.eclipse.swt.widgets.Label)314 Text (org.eclipse.swt.widgets.Text)221 SelectionListener (org.eclipse.swt.events.SelectionListener)185 Group (org.eclipse.swt.widgets.Group)168 ModifyEvent (org.eclipse.swt.events.ModifyEvent)143 ModifyListener (org.eclipse.swt.events.ModifyListener)143 Combo (org.eclipse.swt.widgets.Combo)118 MenuItem (org.eclipse.swt.widgets.MenuItem)89 ToolItem (org.eclipse.swt.widgets.ToolItem)89 Menu (org.eclipse.swt.widgets.Menu)88 TableViewer (org.eclipse.jface.viewers.TableViewer)84 Point (org.eclipse.swt.graphics.Point)82 ArrayList (java.util.ArrayList)79 ToolBar (org.eclipse.swt.widgets.ToolBar)76