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());
}
}
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();
}
}
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;
}
Aggregations