Search in sources :

Example 51 with KeyEvent

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

the class EnumComboEditor method getEditorControl.

/**
     * {@inheritDoc}
     */
public Control getEditorControl(JaretTable table, IRow row, IColumn column, char typedKey) {
    super.getEditorControl(table, row, column, typedKey);
    _items = new Object[] {};
    if (_combo == null) {
        _combo = new Combo(table, SWT.BORDER | SWT.READ_ONLY);
        _combo.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) {
            }
        });
        _combo.addFocusListener(this);
    }
    Class<?> clazz = column.getContentClass(row);
    if (clazz != null && Enum.class.isAssignableFrom(clazz)) {
        _items = clazz.getEnumConstants();
    } else {
        _items = new Object[] {};
    }
    Object value = column.getValue(row);
    _oldVal = value;
    int selIdx = -1;
    String[] stringItems = new String[_items.length];
    for (int i = 0; i < _items.length; i++) {
        stringItems[i] = _items[i].toString();
        if (value != null && value.equals(_items[i])) {
            selIdx = i;
        }
    }
    _combo.setItems(stringItems);
    if (selIdx != -1) {
        _combo.select(selIdx);
    }
    return _combo;
}
Also used : KeyEvent(org.eclipse.swt.events.KeyEvent) Combo(org.eclipse.swt.widgets.Combo) KeyListener(org.eclipse.swt.events.KeyListener) Point(org.eclipse.swt.graphics.Point)

Example 52 with KeyEvent

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

the class ObjectComboEditor method getEditorControl.

/**
     * {@inheritDoc}
     */
public Control getEditorControl(JaretTable table, IRow row, IColumn column, char typedKey) {
    super.getEditorControl(table, row, column, typedKey);
    if (_combo == null) {
        _combo = new Combo(table, SWT.BORDER | SWT.READ_ONLY);
        _combo.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) {
            }
        });
        _combo.addFocusListener(this);
        _combo.setItems(_stringItems);
    }
    Object value = column.getValue(row);
    _oldVal = value;
    int selIdx = -1;
    if (_allowNull && value == null) {
        selIdx = 0;
    } else {
        selIdx = _itemList.indexOf(value);
        selIdx = _allowNull ? selIdx + 1 : selIdx;
    }
    if (selIdx != -1) {
        _combo.select(selIdx);
    }
    return _combo;
}
Also used : KeyEvent(org.eclipse.swt.events.KeyEvent) Combo(org.eclipse.swt.widgets.Combo) KeyListener(org.eclipse.swt.events.KeyListener) Point(org.eclipse.swt.graphics.Point)

Example 53 with KeyEvent

use of org.eclipse.swt.events.KeyEvent 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)

Example 54 with KeyEvent

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

the class ColumnCategoriesDialog method addListenersToListViewer.

private void addListenersToListViewer() {
    listViewer.getControl().addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDoubleClick(MouseEvent e) {
            removeSelected();
        }
    });
    listViewer.getControl().addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            boolean controlMask = (e.stateMask & SWT.CONTROL) == SWT.CONTROL;
            if (controlMask && e.keyCode == SWT.ARROW_UP) {
                moveSelectedUp();
                e.doit = false;
            } else if (controlMask && e.keyCode == SWT.ARROW_DOWN) {
                moveSelectedDown();
                e.doit = false;
            }
        }

        @Override
        public void keyReleased(KeyEvent e) {
            if (e.character == ' ')
                removeSelected();
        }
    });
}
Also used : KeyEvent(org.eclipse.swt.events.KeyEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) KeyAdapter(org.eclipse.swt.events.KeyAdapter) MouseAdapter(org.eclipse.swt.events.MouseAdapter)

Example 55 with KeyEvent

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

the class ColumnChooserDialog method populateDialogArea.

@Override
public void populateDialogArea(Composite parent) {
    GridDataFactory.fillDefaults().grab(true, true).applyTo(parent);
    parent.setLayout(new GridLayout(4, false));
    createLabels(parent, availableLabel, selectedLabel);
    availableTree = new Tree(parent, SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.Expand);
    GridData gridData = GridDataFactory.fillDefaults().grab(true, true).create();
    availableTree.setLayoutData(gridData);
    availableTree.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDoubleClick(MouseEvent e) {
            addSelected();
        }
    });
    availableTree.addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent e) {
            if (e.character == ' ')
                addSelected();
        }
    });
    Composite buttonComposite = new Composite(parent, SWT.NONE);
    buttonComposite.setLayout(new GridLayout(1, true));
    Button addButton = new Button(buttonComposite, SWT.PUSH);
    addButton.setImage(GUIHelper.getImage("arrow_right"));
    gridData = GridDataFactory.fillDefaults().grab(false, true).align(SWT.CENTER, SWT.CENTER).create();
    addButton.setLayoutData(gridData);
    addButton.addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }

        public void widgetSelected(SelectionEvent e) {
            addSelected();
        }
    });
    Button removeButton = new Button(buttonComposite, SWT.PUSH);
    removeButton.setImage(GUIHelper.getImage("arrow_left"));
    gridData = GridDataFactory.copyData(gridData);
    removeButton.setLayoutData(gridData);
    removeButton.addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }

        public void widgetSelected(SelectionEvent e) {
            removeSelected();
        }
    });
    selectedTree = new Tree(parent, SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.Expand);
    gridData = GridDataFactory.fillDefaults().grab(true, true).create();
    selectedTree.setLayoutData(gridData);
    selectedTree.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDoubleClick(MouseEvent e) {
            removeSelected();
        }
    });
    selectedTree.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            boolean controlMask = (e.stateMask & SWT.CONTROL) == SWT.CONTROL;
            if (controlMask && e.keyCode == SWT.ARROW_UP) {
                moveSelectedUp();
                e.doit = false;
            } else if (controlMask && e.keyCode == SWT.ARROW_DOWN) {
                moveSelectedDown();
                e.doit = false;
            }
        }

        @Override
        public void keyReleased(KeyEvent e) {
            if (e.character == ' ')
                removeSelected();
        }
    });
    selectedTree.addTreeListener(new TreeListener() {

        public void treeCollapsed(TreeEvent event) {
            selectedTreeCollapsed(event);
        }

        public void treeExpanded(TreeEvent event) {
            selectedTreeExpanded(event);
        }
    });
    selectedTree.addSelectionListener(new SelectionListener() {

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

        public void widgetSelected(SelectionEvent event) {
            toggleColumnGroupSelection((TreeItem) event.item);
        }
    });
    Composite upDownbuttonComposite = new Composite(parent, SWT.NONE);
    upDownbuttonComposite.setLayout(new GridLayout(1, true));
    Button upButton = new Button(upDownbuttonComposite, SWT.PUSH);
    upButton.setImage(GUIHelper.getImage("arrow_up"));
    gridData = GridDataFactory.fillDefaults().grab(false, true).align(SWT.CENTER, SWT.CENTER).create();
    upButton.setLayoutData(gridData);
    upButton.addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }

        public void widgetSelected(SelectionEvent e) {
            moveSelectedUp();
        }
    });
    Button downButton = new Button(upDownbuttonComposite, SWT.PUSH);
    downButton.setImage(GUIHelper.getImage("arrow_down"));
    gridData = GridDataFactory.copyData(gridData);
    downButton.setLayoutData(gridData);
    downButton.addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }

        public void widgetSelected(SelectionEvent e) {
            moveSelectedDown();
        }
    });
}
Also used : ISelectionTreeListener(net.sourceforge.nattable.columnChooser.ISelectionTreeListener) TreeListener(org.eclipse.swt.events.TreeListener) MouseEvent(org.eclipse.swt.events.MouseEvent) Composite(org.eclipse.swt.widgets.Composite) TreeItem(org.eclipse.swt.widgets.TreeItem) KeyAdapter(org.eclipse.swt.events.KeyAdapter) MouseAdapter(org.eclipse.swt.events.MouseAdapter) KeyEvent(org.eclipse.swt.events.KeyEvent) TreeEvent(org.eclipse.swt.events.TreeEvent) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Tree(org.eclipse.swt.widgets.Tree) SelectionListener(org.eclipse.swt.events.SelectionListener)

Aggregations

KeyEvent (org.eclipse.swt.events.KeyEvent)98 KeyAdapter (org.eclipse.swt.events.KeyAdapter)63 GridData (org.eclipse.swt.layout.GridData)54 GridLayout (org.eclipse.swt.layout.GridLayout)42 Composite (org.eclipse.swt.widgets.Composite)42 SelectionEvent (org.eclipse.swt.events.SelectionEvent)41 Text (org.eclipse.swt.widgets.Text)34 KeyListener (org.eclipse.swt.events.KeyListener)32 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)32 Label (org.eclipse.swt.widgets.Label)29 ModifyEvent (org.eclipse.swt.events.ModifyEvent)22 ModifyListener (org.eclipse.swt.events.ModifyListener)22 Point (org.eclipse.swt.graphics.Point)21 Button (org.eclipse.swt.widgets.Button)21 MouseEvent (org.eclipse.swt.events.MouseEvent)20 TableViewer (org.eclipse.jface.viewers.TableViewer)19 StyledText (org.eclipse.swt.custom.StyledText)13 FocusEvent (org.eclipse.swt.events.FocusEvent)13 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)12 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)12