Example usage for org.eclipse.jface.databinding.swt.typed WidgetProperties dateTimeSelection

List of usage examples for org.eclipse.jface.databinding.swt.typed WidgetProperties dateTimeSelection

Introduction

In this page you can find the example usage for org.eclipse.jface.databinding.swt.typed WidgetProperties dateTimeSelection.

Prototype

public static IWidgetValueProperty<DateTime, Date> dateTimeSelection() 

Source Link

Document

Returns a value property for observing the selection state of a DateTime .

Usage

From source file:org.eclipse.jface.examples.databinding.snippets.Snippet030DateAndTimeObservableValue.java

License:Open Source License

private void bindUI() {
    DataBindingContext dbc = new DataBindingContext();

    IObservableValue<Date> model = WritableValue.withValueType(Date.class);
    model.setValue(new Date());

    dbc.bindValue(WidgetProperties.text().observe(modelText), model);

    final IObservableValue<Date> timeSelection = WidgetProperties.dateTimeSelection().observe(time);

    dbc.bindValue(//from  w w  w  . ja va  2 s. c  om
            new DateAndTimeObservableValue(WidgetProperties.dateTimeSelection().observe(date), timeSelection),
            model);
    dbc.bindValue(new DateAndTimeObservableValue(WidgetProperties.dateTimeSelection().observe(calendar),
            timeSelection), model);

    syncTime.addListener(SWT.Selection, new Listener() {
        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                if (syncTime.getSelection()) {
                    timeSelection.setValue(new Date());
                    Display.getCurrent().timerExec(100, this);
                }
            }
        };

        @Override
        public void handleEvent(Event event) {
            time.setEnabled(!syncTime.getSelection());
            if (syncTime.getSelection()) {
                runnable.run();
            }
        }
    });
}

From source file:org.eclipse.jface.examples.databinding.snippets.Snippet033CrossValidationControlDecoration.java

License:Open Source License

private void bindUI() {
    IObservableValue<Date> startDateObservable = WidgetProperties.dateTimeSelection().observe(startDate);
    IObservableValue<Date> endDateObservable = WidgetProperties.dateTimeSelection().observe(endDate);

    ControlDecorationSupport.create(new DateRangeValidator(startDateObservable, endDateObservable,
            "Start date must be on or before end date"), SWT.LEFT | SWT.CENTER);

    // Customize the decoration's description text and image
    ControlDecorationUpdater decorationUpdater = new ControlDecorationUpdater() {
        @Override//  w  w  w.  j  a v a2  s .co m
        protected String getDescriptionText(IStatus status) {
            return "ERROR: " + super.getDescriptionText(status);
        }

        @Override
        protected Image getImage(IStatus status) {
            return status.isOK() ? null : Display.getCurrent().getSystemImage(SWT.ICON_ERROR);
        }
    };
    ControlDecorationSupport.create(
            new DateRangeValidator(Observables.constantObservableValue(new Date()), startDateObservable,
                    "Choose a starting date later than today"),
            SWT.LEFT | SWT.TOP, (Composite) null, decorationUpdater);
}