Search in sources :

Example 1 with NatCombo

use of net.sourceforge.nattable.widget.NatCombo in project translationstudio8 by heartsome.

the class ComboBoxCellEditor method activateCell.

@Override
protected Control activateCell(Composite parent, Object originalCanonicalValue, Character initialEditValue) {
    this.originalCanonicalValue = originalCanonicalValue;
    combo = new NatCombo(parent, getCellStyle(), maxVisibleItems);
    combo.setItems(getDisplayValues());
    if (originalCanonicalValue != null) {
        combo.setSelection(new String[] { getDisplayValue() });
    }
    combo.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent event) {
            if ((event.keyCode == SWT.CR && event.stateMask == 0) || (event.keyCode == SWT.KEYPAD_CR && event.stateMask == 0)) {
                commit(MoveDirectionEnum.NONE);
            } else if (event.keyCode == SWT.ESC && event.stateMask == 0) {
                close();
            }
        }
    });
    combo.addTraverseListener(new TraverseListener() {

        public void keyTraversed(TraverseEvent event) {
            if (event.keyCode == SWT.TAB && event.stateMask == SWT.SHIFT) {
                commit(MoveDirectionEnum.LEFT);
            } else if (event.keyCode == SWT.TAB && event.stateMask == 0) {
                commit(MoveDirectionEnum.RIGHT);
            }
        }
    });
    combo.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDown(MouseEvent e) {
            commit(MoveDirectionEnum.NONE);
        }
    });
    return combo;
}
Also used : KeyEvent(org.eclipse.swt.events.KeyEvent) NatCombo(net.sourceforge.nattable.widget.NatCombo) TraverseEvent(org.eclipse.swt.events.TraverseEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) TraverseListener(org.eclipse.swt.events.TraverseListener) KeyAdapter(org.eclipse.swt.events.KeyAdapter) MouseAdapter(org.eclipse.swt.events.MouseAdapter)

Aggregations

NatCombo (net.sourceforge.nattable.widget.NatCombo)1 KeyAdapter (org.eclipse.swt.events.KeyAdapter)1 KeyEvent (org.eclipse.swt.events.KeyEvent)1 MouseAdapter (org.eclipse.swt.events.MouseAdapter)1 MouseEvent (org.eclipse.swt.events.MouseEvent)1 TraverseEvent (org.eclipse.swt.events.TraverseEvent)1 TraverseListener (org.eclipse.swt.events.TraverseListener)1