Search in sources :

Example 16 with TraverseListener

use of org.eclipse.swt.events.TraverseListener in project eclipse.platform.text by eclipse.

the class CompletionProposalPopup method addCommandSupport.

/**
 * Adds command support to the given control.
 *
 * @param control the control to watch for focus
 * @since 3.2
 */
private void addCommandSupport(final Control control) {
    final KeySequence commandSequence = fContentAssistant.getRepeatedInvocationKeySequence();
    if (commandSequence != null && !commandSequence.isEmpty() && fContentAssistant.isRepeatedInvocationMode()) {
        control.addFocusListener(new FocusListener() {

            private CommandKeyListener fCommandKeyListener;

            @Override
            public void focusGained(FocusEvent e) {
                if (Helper.okToUse(control)) {
                    if (fCommandKeyListener == null) {
                        fCommandKeyListener = new CommandKeyListener(commandSequence);
                        fProposalTable.addKeyListener(fCommandKeyListener);
                    }
                }
            }

            @Override
            public void focusLost(FocusEvent e) {
                if (fCommandKeyListener != null) {
                    control.removeKeyListener(fCommandKeyListener);
                    fCommandKeyListener = null;
                }
            }
        });
    }
    if (fAdditionalInfoController != null) {
        control.addFocusListener(new FocusListener() {

            private TraverseListener fTraverseListener;

            @Override
            public void focusGained(FocusEvent e) {
                if (Helper.okToUse(control)) {
                    if (fTraverseListener == null) {
                        fTraverseListener = new TraverseListener() {

                            @Override
                            public void keyTraversed(TraverseEvent event) {
                                if (event.detail == SWT.TRAVERSE_TAB_NEXT) {
                                    IInformationControl iControl = fAdditionalInfoController.getCurrentInformationControl2();
                                    if (fAdditionalInfoController.getInternalAccessor().canReplace(iControl)) {
                                        fAdditionalInfoController.getInternalAccessor().replaceInformationControl(true);
                                        event.doit = false;
                                    }
                                }
                            }
                        };
                        fProposalTable.addTraverseListener(fTraverseListener);
                    }
                }
            }

            @Override
            public void focusLost(FocusEvent e) {
                if (fTraverseListener != null) {
                    control.removeTraverseListener(fTraverseListener);
                    fTraverseListener = null;
                }
            }
        });
    }
}
Also used : TraverseEvent(org.eclipse.swt.events.TraverseEvent) IInformationControl(org.eclipse.jface.text.IInformationControl) TraverseListener(org.eclipse.swt.events.TraverseListener) KeySequence(org.eclipse.jface.bindings.keys.KeySequence) FocusListener(org.eclipse.swt.events.FocusListener) FocusEvent(org.eclipse.swt.events.FocusEvent)

Example 17 with TraverseListener

use of org.eclipse.swt.events.TraverseListener in project eclipse.platform.swt by eclipse.

the class GridLayoutTab method createChildWidgets.

/**
 * Creates the widgets in the "child" group.
 */
@Override
void createChildWidgets() {
    /* Create the TraverseListener */
    final TraverseListener traverseListener = e -> {
        if (e.detail == SWT.TRAVERSE_RETURN || e.detail == SWT.TRAVERSE_TAB_NEXT)
            resetEditors();
        if (e.detail == SWT.TRAVERSE_ESCAPE)
            disposeEditors();
    };
    /* Add common controls */
    super.createChildWidgets();
    /* Add hovers to the column headers whose field names have been shortened to save space */
    table.getColumn(HALIGN_COL).setToolTipText("horizontalAlignment");
    table.getColumn(VALIGN_COL).setToolTipText("verticalAlignment");
    table.getColumn(HGRAB_COL).setToolTipText("grabExcessHorizontalSpace");
    table.getColumn(VGRAB_COL).setToolTipText("grabExcessVerticalSpace");
    table.getColumn(HSPAN_COL).setToolTipText("horizontalSpan");
    table.getColumn(VSPAN_COL).setToolTipText("verticalSpan");
    table.getColumn(HINDENT_COL).setToolTipText("horizontalIndent");
    table.getColumn(VINDENT_COL).setToolTipText("verticalIndent");
    table.getColumn(MINWIDTH_COL).setToolTipText("minimumWidth");
    table.getColumn(MINHEIGHT_COL).setToolTipText("minimumHeight");
    /* Add TableEditors */
    nameEditor = new TableEditor(table);
    comboEditor = new TableEditor(table);
    widthEditor = new TableEditor(table);
    heightEditor = new TableEditor(table);
    vAlignEditor = new TableEditor(table);
    hAlignEditor = new TableEditor(table);
    hGrabEditor = new TableEditor(table);
    vGrabEditor = new TableEditor(table);
    hSpanEditor = new TableEditor(table);
    vSpanEditor = new TableEditor(table);
    hIndentEditor = new TableEditor(table);
    vIndentEditor = new TableEditor(table);
    minWidthEditor = new TableEditor(table);
    minHeightEditor = new TableEditor(table);
    excludeEditor = new TableEditor(table);
    table.addMouseListener(MouseListener.mouseDownAdapter(e -> {
        resetEditors();
        index = table.getSelectionIndex();
        Point pt = new Point(e.x, e.y);
        newItem = table.getItem(pt);
        if (newItem == null)
            return;
        TableItem oldItem = comboEditor.getItem();
        if (newItem == oldItem || newItem != lastSelected) {
            lastSelected = newItem;
            return;
        }
        table.showSelection();
        nameText = new Text(table, SWT.SINGLE);
        nameText.setText(data.get(index)[NAME_COL]);
        createTextEditor(nameText, nameEditor, NAME_COL);
        combo = new CCombo(table, SWT.READ_ONLY);
        createComboEditor(combo, comboEditor);
        widthText = new Text(table, SWT.SINGLE);
        widthText.setText(data.get(index)[WIDTH_COL]);
        createTextEditor(widthText, widthEditor, WIDTH_COL);
        heightText = new Text(table, SWT.SINGLE);
        heightText.setText(data.get(index)[HEIGHT_COL]);
        createTextEditor(heightText, heightEditor, HEIGHT_COL);
        String[] alignValues = new String[] { "BEGINNING", "CENTER", "END", "FILL" };
        hAlign = new CCombo(table, SWT.NONE);
        hAlign.setItems(alignValues);
        hAlign.setText(newItem.getText(HALIGN_COL));
        hAlignEditor.horizontalAlignment = SWT.LEFT;
        hAlignEditor.grabHorizontal = true;
        hAlignEditor.minimumWidth = 50;
        hAlignEditor.setEditor(hAlign, newItem, HALIGN_COL);
        hAlign.addTraverseListener(traverseListener);
        vAlign = new CCombo(table, SWT.NONE);
        vAlign.setItems(alignValues);
        vAlign.setText(newItem.getText(VALIGN_COL));
        vAlignEditor.horizontalAlignment = SWT.LEFT;
        vAlignEditor.grabHorizontal = true;
        vAlignEditor.minimumWidth = 50;
        vAlignEditor.setEditor(vAlign, newItem, VALIGN_COL);
        vAlign.addTraverseListener(traverseListener);
        String[] boolValues = new String[] { "false", "true" };
        hGrab = new CCombo(table, SWT.NONE);
        hGrab.setItems(boolValues);
        hGrab.setText(newItem.getText(HGRAB_COL));
        hGrabEditor.horizontalAlignment = SWT.LEFT;
        hGrabEditor.grabHorizontal = true;
        hGrabEditor.minimumWidth = 50;
        hGrabEditor.setEditor(hGrab, newItem, HGRAB_COL);
        hGrab.addTraverseListener(traverseListener);
        vGrab = new CCombo(table, SWT.NONE);
        vGrab.setItems(boolValues);
        vGrab.setText(newItem.getText(VGRAB_COL));
        vGrabEditor.horizontalAlignment = SWT.LEFT;
        vGrabEditor.grabHorizontal = true;
        vGrabEditor.minimumWidth = 50;
        vGrabEditor.setEditor(vGrab, newItem, VGRAB_COL);
        vGrab.addTraverseListener(traverseListener);
        hSpan = new Text(table, SWT.SINGLE);
        hSpan.setText(data.get(index)[HSPAN_COL]);
        createTextEditor(hSpan, hSpanEditor, HSPAN_COL);
        vSpan = new Text(table, SWT.SINGLE);
        vSpan.setText(data.get(index)[VSPAN_COL]);
        createTextEditor(vSpan, vSpanEditor, VSPAN_COL);
        hIndent = new Text(table, SWT.SINGLE);
        hIndent.setText(data.get(index)[HINDENT_COL]);
        createTextEditor(hIndent, hIndentEditor, HINDENT_COL);
        vIndent = new Text(table, SWT.SINGLE);
        vIndent.setText(data.get(index)[VINDENT_COL]);
        createTextEditor(vIndent, vIndentEditor, VINDENT_COL);
        minWidthText = new Text(table, SWT.SINGLE);
        minWidthText.setText(data.get(index)[MINWIDTH_COL]);
        createTextEditor(minWidthText, minWidthEditor, MINWIDTH_COL);
        minHeightText = new Text(table, SWT.SINGLE);
        minHeightText.setText(data.get(index)[MINHEIGHT_COL]);
        createTextEditor(minHeightText, minHeightEditor, MINHEIGHT_COL);
        exclude = new CCombo(table, SWT.NONE);
        exclude.setItems(boolValues);
        exclude.setText(newItem.getText(EXCLUDE_COL));
        excludeEditor.horizontalAlignment = SWT.LEFT;
        excludeEditor.grabHorizontal = true;
        excludeEditor.minimumWidth = 50;
        excludeEditor.setEditor(exclude, newItem, EXCLUDE_COL);
        exclude.addTraverseListener(traverseListener);
        for (int i = 0; i < table.getColumnCount(); i++) {
            Rectangle rect = newItem.getBounds(i);
            if (rect.contains(pt)) {
                switch(i) {
                    case NAME_COL:
                        nameText.setFocus();
                        break;
                    case COMBO_COL:
                        combo.setFocus();
                        break;
                    case WIDTH_COL:
                        widthText.setFocus();
                        break;
                    case HEIGHT_COL:
                        heightText.setFocus();
                        break;
                    case HALIGN_COL:
                        hAlign.setFocus();
                        break;
                    case VALIGN_COL:
                        vAlign.setFocus();
                        break;
                    case HGRAB_COL:
                        hGrab.setFocus();
                        break;
                    case VGRAB_COL:
                        vGrab.setFocus();
                        break;
                    case HSPAN_COL:
                        hSpan.setFocus();
                        break;
                    case VSPAN_COL:
                        vSpan.setFocus();
                        break;
                    case HINDENT_COL:
                        hIndent.setFocus();
                        break;
                    case VINDENT_COL:
                        vIndent.setFocus();
                        break;
                    case MINWIDTH_COL:
                        minWidthText.setFocus();
                        break;
                    case MINHEIGHT_COL:
                        minHeightText.setFocus();
                        break;
                    case EXCLUDE_COL:
                        exclude.setFocus();
                        break;
                    default:
                        resetEditors();
                        break;
                }
            }
        }
    }));
}
Also used : TableEditor(org.eclipse.swt.custom.TableEditor) TableItem(org.eclipse.swt.widgets.TableItem) Text(org.eclipse.swt.widgets.Text) Button(org.eclipse.swt.widgets.Button) Rectangle(org.eclipse.swt.graphics.Rectangle) Spinner(org.eclipse.swt.widgets.Spinner) TraverseListener(org.eclipse.swt.events.TraverseListener) Point(org.eclipse.swt.graphics.Point) Group(org.eclipse.swt.widgets.Group) MouseListener(org.eclipse.swt.events.MouseListener) SWT(org.eclipse.swt.SWT) GridData(org.eclipse.swt.layout.GridData) Label(org.eclipse.swt.widgets.Label) CCombo(org.eclipse.swt.custom.CCombo) Control(org.eclipse.swt.widgets.Control) GridLayout(org.eclipse.swt.layout.GridLayout) CCombo(org.eclipse.swt.custom.CCombo) TraverseListener(org.eclipse.swt.events.TraverseListener) TableItem(org.eclipse.swt.widgets.TableItem) Rectangle(org.eclipse.swt.graphics.Rectangle) Text(org.eclipse.swt.widgets.Text) Point(org.eclipse.swt.graphics.Point) TableEditor(org.eclipse.swt.custom.TableEditor)

Example 18 with TraverseListener

use of org.eclipse.swt.events.TraverseListener in project translationstudio8 by heartsome.

the class DateCellEditor method createControl.

/**
     * Create the chooser control.
     * 
     * @param table parent table.
     */
private void createControl(JaretTable table) {
    _table = table;
    if (_chooser == null) {
        _chooser = new DateChooser(table, SWT.NULL);
        // TODO locale dependent
        IFieldIdentifier fi = new SimpleFieldIdentifier(".", new int[] { Calendar.DAY_OF_MONTH, Calendar.MONTH, Calendar.YEAR });
        _chooser.setFieldIdentifier(fi);
        _chooser.setSelectAllOnFocusGained(false);
        _chooser.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
        _chooser.addFocusListener(this);
        _chooser.addDateChooserListener(this);
        _chooser.getTextField().addKeyListener(new KeyListener() {

            public void keyPressed(KeyEvent event) {
                if (event.keyCode == SWT.TAB) {
                    _chooser.validateInput();
                    stopEditing(true);
                    // do not further process
                    event.doit = false;
                    _table.forceFocus();
                    _table.focusRight();
                } else if (event.keyCode == SWT.CR) {
                    _chooser.validateInput();
                    stopEditing(true);
                    // do not further process
                    event.doit = false;
                    _table.forceFocus();
                    _table.focusDown();
                } else if (event.keyCode == SWT.ESC) {
                    stopEditing(false);
                    restoreOldVal();
                    // do not further process
                    event.doit = false;
                    _table.forceFocus();
                }
            }

            public void keyReleased(KeyEvent e) {
            }
        });
        // add a traverse listener so the TAB-key won't traverse the focus out of the table
        _chooser.getTextField().addTraverseListener(new TraverseListener() {

            public void keyTraversed(TraverseEvent e) {
                e.doit = false;
            }
        });
    }
}
Also used : KeyEvent(org.eclipse.swt.events.KeyEvent) TraverseEvent(org.eclipse.swt.events.TraverseEvent) TraverseListener(org.eclipse.swt.events.TraverseListener) SimpleFieldIdentifier(de.jaret.util.ui.datechooser.SimpleFieldIdentifier) IFieldIdentifier(de.jaret.util.ui.datechooser.IFieldIdentifier) KeyListener(org.eclipse.swt.events.KeyListener) DateChooser(de.jaret.util.ui.datechooser.DateChooser)

Example 19 with TraverseListener

use of org.eclipse.swt.events.TraverseListener in project cubrid-manager by CUBRID.

the class DataTypeCellEditor method createControl.

protected Control createControl(Composite parent) {
    comboBox = new DataTypeCombo(parent, getStyle());
    comboBox.setFont(parent.getFont());
    populateComboBoxItems();
    //		comboBox.addKeyListener(new KeyAdapter() {
    //			public void keyPressed(KeyEvent event) {
    //				if (event.character == '\r') {
    //					applyEditorValueAndDeactivate();
    //				}
    //				keyReleaseOccured(event);
    //			}
    //
    //			public void keyReleased(KeyEvent event) {
    //			}
    //		});
    comboBox.addModifyListener(getModifyListener());
    comboBox.addSelectionListener(new SelectionAdapter() {

        public void widgetDefaultSelected(SelectionEvent event) {
            applyEditorValueAndDeactivate();
        }

        public void widgetSelected(SelectionEvent event) {
            value = comboBox.getText();
        }
    });
    comboBox.addTraverseListener(new TraverseListener() {

        public void keyTraversed(TraverseEvent event) {
            if (event.detail == SWT.TRAVERSE_ESCAPE || event.detail == SWT.TRAVERSE_RETURN) {
                event.doit = false;
            }
        }
    });
    comboBox.addFocusListener(new FocusAdapter() {

        public void focusLost(FocusEvent event) {
            applyEditorValueAndDeactivate();
            DataTypeCellEditor.this.focusLost();
        }
    });
    return comboBox;
}
Also used : FocusAdapter(org.eclipse.swt.events.FocusAdapter) TraverseEvent(org.eclipse.swt.events.TraverseEvent) TraverseListener(org.eclipse.swt.events.TraverseListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) FocusEvent(org.eclipse.swt.events.FocusEvent)

Example 20 with TraverseListener

use of org.eclipse.swt.events.TraverseListener in project translationstudio8 by heartsome.

the class IntegerCellEditor method createControl.

/**
     * Create the control.
     * 
     * @param table parent table
     */
private void createControl(JaretTable table) {
    if (_spinner == null) {
        _table = table;
        _spinner = new Spinner(table, SWT.BORDER);
        _spinner.setMaximum(_max);
        _spinner.setMinimum(_min);
        _spinner.addTraverseListener(new TraverseListener() {

            public void keyTraversed(TraverseEvent e) {
                e.doit = false;
            }
        });
        _spinner.addKeyListener(new KeyListener() {

            public void keyPressed(KeyEvent event) {
                if (event.keyCode == SWT.TAB) {
                    event.doit = false;
                    stopEditing(true);
                    _table.forceFocus();
                    _table.focusRight();
                } else if (event.keyCode == SWT.CR) {
                    event.doit = false;
                    stopEditing(true);
                    _table.forceFocus();
                    _table.focusDown();
                } else if (event.keyCode == SWT.ESC) {
                    event.doit = false;
                    stopEditing(false);
                    _column.setValue(_row, _oldVal);
                    _table.forceFocus();
                }
            }

            public void keyReleased(KeyEvent arg0) {
            }
        });
        _spinner.addFocusListener(this);
    }
}
Also used : KeyEvent(org.eclipse.swt.events.KeyEvent) TraverseEvent(org.eclipse.swt.events.TraverseEvent) TraverseListener(org.eclipse.swt.events.TraverseListener) Spinner(org.eclipse.swt.widgets.Spinner) KeyListener(org.eclipse.swt.events.KeyListener)

Aggregations

TraverseListener (org.eclipse.swt.events.TraverseListener)32 TraverseEvent (org.eclipse.swt.events.TraverseEvent)30 FocusEvent (org.eclipse.swt.events.FocusEvent)10 SelectionEvent (org.eclipse.swt.events.SelectionEvent)10 FocusAdapter (org.eclipse.swt.events.FocusAdapter)9 Point (org.eclipse.swt.graphics.Point)9 Button (org.eclipse.swt.widgets.Button)9 MouseEvent (org.eclipse.swt.events.MouseEvent)8 Text (org.eclipse.swt.widgets.Text)8 KeyEvent (org.eclipse.swt.events.KeyEvent)7 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)7 StyledText (org.eclipse.swt.custom.StyledText)6 ModifyEvent (org.eclipse.swt.events.ModifyEvent)6 ModifyListener (org.eclipse.swt.events.ModifyListener)6 Composite (org.eclipse.swt.widgets.Composite)6 Control (org.eclipse.swt.widgets.Control)6 Label (org.eclipse.swt.widgets.Label)6 MouseAdapter (org.eclipse.swt.events.MouseAdapter)5 MouseListener (org.eclipse.swt.events.MouseListener)5 GridData (org.eclipse.swt.layout.GridData)5