Search in sources :

Example 1 with DateChooser

use of de.jaret.util.ui.datechooser.DateChooser 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)

Aggregations

DateChooser (de.jaret.util.ui.datechooser.DateChooser)1 IFieldIdentifier (de.jaret.util.ui.datechooser.IFieldIdentifier)1 SimpleFieldIdentifier (de.jaret.util.ui.datechooser.SimpleFieldIdentifier)1 KeyEvent (org.eclipse.swt.events.KeyEvent)1 KeyListener (org.eclipse.swt.events.KeyListener)1 TraverseEvent (org.eclipse.swt.events.TraverseEvent)1 TraverseListener (org.eclipse.swt.events.TraverseListener)1