Example usage for com.google.gwt.gen2.datepicker.client DateBox setDateFormat

List of usage examples for com.google.gwt.gen2.datepicker.client DateBox setDateFormat

Introduction

In this page you can find the example usage for com.google.gwt.gen2.datepicker.client DateBox setDateFormat.

Prototype

public void setDateFormat(DateTimeFormat format) 

Source Link

Document

Sets the date format to the given format.

Usage

From source file:com.google.gwt.gen2.demo.datepicker.client.DatePickerDemo.java

License:Apache License

private Widget dateRange() {
    VerticalPanel v = new VerticalPanel();
    HorizontalPanel p = new HorizontalPanel();
    v.add(p);//  ww w  .j  a  v  a 2s.c  o m
    start = new DateBox();
    start.setAnimationEnabled(true);
    final DateBox end = new DateBox();
    end.setAnimationEnabled(true);

    start.addKeyDownHandler(new KeyDownHandler() {
        public void onKeyDown(KeyDownEvent e) {
            if (e.isRightKeyCode() && start.getCursorPos() == start.getText().length()) {
                start.hideDatePicker();
                end.setFocus(true);
            }
        }
    });

    end.addKeyDownHandler(new KeyDownHandler() {
        public void onKeyDown(KeyDownEvent e) {
            if ((e.isLeftKeyCode()) && end.getCursorPos() == 0) {
                start.setFocus(true);
                end.hideDatePicker();
            }
        }
    });

    end.getDatePicker().addSelectionHandler(new SelectionHandler<Date>() {
        public void onSelection(SelectionEvent<Date> event) {
            start.removeStyleName("user-modified");
        }
    });

    start.showDate(new Date());

    p.add(start);
    Label l = new Label(" - ");
    l.setStyleName("filler");
    p.add(l);
    p.add(end);
    HorizontalPanel h2 = new HorizontalPanel();
    v.add(h2);
    h2.add(new Button("Short format", new ClickListener() {

        public void onClick(Widget sender) {
            start.setDateFormat(DateTimeFormat.getShortDateFormat());
            end.setDateFormat(DateTimeFormat.getShortDateFormat());
        }
    }));
    h2.add(new Button("Long format", new ClickListener() {

        public void onClick(Widget sender) {
            start.setDateFormat(DateTimeFormat.getLongDateFormat());
            end.setDateFormat(DateTimeFormat.getLongDateFormat());
        }
    }));

    h2.add(new Button("clear", new ClickListener() {
        public void onClick(Widget sender) {
            start.clear();
            end.clear();
        }
    }));
    return v;
}