Search in sources :

Example 1 with CDateTime

use of org.eclipse.nebula.widgets.cdatetime.CDateTime in project portfolio by buchen.

the class DatePicker method setSelection.

public void setSelection(LocalDate date) {
    if (control instanceof CDateTime) {
        Date d = Date.from(date.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant());
        ((CDateTime) control).setSelection(d);
    } else {
        // DateTime widget has zero-based months
        ((DateTime) control).setDate(date.getYear(), date.getMonthValue() - 1, date.getDayOfMonth());
    }
}
Also used : CDateTime(org.eclipse.nebula.widgets.cdatetime.CDateTime) Date(java.util.Date) LocalDate(java.time.LocalDate) LocalDateTime(java.time.LocalDateTime) CDateTime(org.eclipse.nebula.widgets.cdatetime.CDateTime) DateTime(org.eclipse.swt.widgets.DateTime)

Example 2 with CDateTime

use of org.eclipse.nebula.widgets.cdatetime.CDateTime in project portfolio by buchen.

the class SimpleDateTimeDateSelectionProperty method doSetValue.

@Override
protected void doSetValue(Object source, Object value) {
    if (source instanceof DateTime) {
        LocalDate date = (LocalDate) value;
        DateTime dateTime = (DateTime) source;
        // DateTime widget has zero-based months
        dateTime.setDate(date.getYear(), date.getMonthValue() - 1, date.getDayOfMonth());
    } else if (source instanceof CDateTime) {
        LocalDate date = (LocalDate) value;
        CDateTime dateTime = (CDateTime) source;
        dateTime.setSelection(Date.from(date.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant()));
    } else {
        throw new UnsupportedOperationException();
    }
}
Also used : CDateTime(org.eclipse.nebula.widgets.cdatetime.CDateTime) LocalDate(java.time.LocalDate) CDateTime(org.eclipse.nebula.widgets.cdatetime.CDateTime) LocalDateTime(java.time.LocalDateTime) DateTime(org.eclipse.swt.widgets.DateTime)

Example 3 with CDateTime

use of org.eclipse.nebula.widgets.cdatetime.CDateTime in project nebula.widgets.nattable by eclipse.

the class CDateTimeCellEditor method createEditorControl.

@Override
public CDateTime createEditorControl(final Composite parent) {
    final CDateTime dateControl = new CDateTime(parent, this.style) {

        @Override
        protected Shell getContentShell() {
            Shell shell = super.getContentShell();
            shell.addShellListener(new ShellAdapter() {

                @Override
                public void shellActivated(ShellEvent e) {
                    if (CDateTimeCellEditor.this.focusListener instanceof InlineFocusListener) {
                        ((InlineFocusListener) CDateTimeCellEditor.this.focusListener).handleFocusChanges = false;
                    }
                }

                @Override
                public void shellClosed(ShellEvent e) {
                    if (CDateTimeCellEditor.this.focusListener instanceof InlineFocusListener) {
                        ((InlineFocusListener) CDateTimeCellEditor.this.focusListener).handleFocusChanges = true;
                    }
                }
            });
            return shell;
        }

        @Override
        protected void addTextListener() {
            super.addTextListener();
            this.text.getControl().addTraverseListener(new TraverseListener() {

                @Override
                public void keyTraversed(TraverseEvent event) {
                    boolean committed = false;
                    if (event.keyCode == SWT.TAB && event.stateMask == SWT.MOD2) {
                        committed = commit(MoveDirectionEnum.LEFT);
                    } else if (event.keyCode == SWT.TAB && event.stateMask == 0) {
                        committed = commit(MoveDirectionEnum.RIGHT);
                    } else if (event.detail == SWT.TRAVERSE_ESCAPE) {
                        close();
                    }
                    if (!committed) {
                        event.doit = false;
                    }
                }
            });
        }
    };
    // set style information configured in the associated cell style
    dateControl.setBackground(this.cellStyle.getAttributeValue(CellStyleAttributes.BACKGROUND_COLOR));
    dateControl.setForeground(this.cellStyle.getAttributeValue(CellStyleAttributes.FOREGROUND_COLOR));
    // StackOverflowError
    if ((this.style & CDT.SIMPLE) == 0) {
        dateControl.setFont(this.cellStyle.getAttributeValue(CellStyleAttributes.FONT));
    }
    dateControl.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetDefaultSelected(SelectionEvent event) {
            boolean commit = (event.stateMask == SWT.MOD3) ? false : true;
            MoveDirectionEnum move = MoveDirectionEnum.NONE;
            if (CDateTimeCellEditor.this.moveSelectionOnEnter && CDateTimeCellEditor.this.editMode == EditModeEnum.INLINE) {
                if (event.stateMask == 0) {
                    move = MoveDirectionEnum.DOWN;
                } else if (event.stateMask == SWT.MOD2) {
                    move = MoveDirectionEnum.UP;
                }
            }
            if (commit)
                commit(move);
            if (CDateTimeCellEditor.this.editMode == EditModeEnum.DIALOG) {
                parent.forceFocus();
            }
        }
    });
    return dateControl;
}
Also used : CDateTime(org.eclipse.nebula.widgets.cdatetime.CDateTime) Shell(org.eclipse.swt.widgets.Shell) ShellAdapter(org.eclipse.swt.events.ShellAdapter) TraverseEvent(org.eclipse.swt.events.TraverseEvent) MoveDirectionEnum(org.eclipse.nebula.widgets.nattable.selection.SelectionLayer.MoveDirectionEnum) TraverseListener(org.eclipse.swt.events.TraverseListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ShellEvent(org.eclipse.swt.events.ShellEvent)

Aggregations

CDateTime (org.eclipse.nebula.widgets.cdatetime.CDateTime)3 LocalDate (java.time.LocalDate)2 LocalDateTime (java.time.LocalDateTime)2 DateTime (org.eclipse.swt.widgets.DateTime)2 Date (java.util.Date)1 MoveDirectionEnum (org.eclipse.nebula.widgets.nattable.selection.SelectionLayer.MoveDirectionEnum)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 ShellAdapter (org.eclipse.swt.events.ShellAdapter)1 ShellEvent (org.eclipse.swt.events.ShellEvent)1 TraverseEvent (org.eclipse.swt.events.TraverseEvent)1 TraverseListener (org.eclipse.swt.events.TraverseListener)1 Shell (org.eclipse.swt.widgets.Shell)1