Example usage for com.google.gwt.cell.client DatePickerCell DatePickerCell

List of usage examples for com.google.gwt.cell.client DatePickerCell DatePickerCell

Introduction

In this page you can find the example usage for com.google.gwt.cell.client DatePickerCell DatePickerCell.

Prototype

@SuppressWarnings("deprecation")
public DatePickerCell() 

Source Link

Document

Constructs a new DatePickerCell that uses the date/time format given by DateTimeFormat#getFullDateFormat .

Usage

From source file:com.google.gwt.examples.cellview.CellTableFieldUpdaterExampleComplex.java

License:Apache License

@Override
public void onModuleLoad() {
    // Create a CellTable with a key provider.
    final CellTable<Contact> table = new CellTable<Contact>(KEY_PROVIDER);
    table.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED);

    // Add a text input column to edit the name.
    final TextInputCell nameCell = new TextInputCell();
    Column<Contact, String> nameColumn = new Column<Contact, String>(nameCell) {
        @Override/*from  w ww  . j a v a  2s.  c o  m*/
        public String getValue(Contact object) {
            return object.name;
        }
    };
    table.addColumn(nameColumn, "Name");

    // Add a field updater to be notified when the user enters a new name.
    nameColumn.setFieldUpdater(new FieldUpdater<Contact, String>() {
        @Override
        public void update(int index, Contact object, String value) {
            // Validate the data.
            if (value.length() < 3) {
                Window.alert("Names must be at least three characters long.");

                /*
                 * Clear the view data. The view data contains the pending change and
                 * allows the table to render with the pending value until the data is
                 * committed. If the data is committed into the object, the view data
                 * is automatically cleared out. If the data is not committed because
                 * it is invalid, you must delete.
                 */
                nameCell.clearViewData(KEY_PROVIDER.getKey(object));

                // Redraw the table.
                table.redraw();
                return;
            }

            // Inform the user of the change.
            Window.alert("You changed the name of " + object.name + " to " + value);

            // Push the changes into the Contact. At this point, you could send an
            // asynchronous request to the server to update the database.
            object.name = value;

            // Redraw the table with the new data.
            table.redraw();
        }
    });

    // Add a date column to show the birthday.
    Column<Contact, Date> dateColumn = new Column<Contact, Date>(new DatePickerCell()) {
        @Override
        public Date getValue(Contact object) {
            return object.birthday;
        }
    };
    table.addColumn(dateColumn, "Birthday");

    // Add a field updater to be notified when the user enters a new birthday.
    dateColumn.setFieldUpdater(new FieldUpdater<Contact, Date>() {
        @Override
        public void update(int index, Contact object, Date value) {
            Window.alert("You changed the birthday of " + object.name + " to "
                    + DateTimeFormat.getFormat(PredefinedFormat.DATE_LONG).format(value));

            // Push the changes into the Contact.
            object.birthday = value;

            // Redraw the table with the new data.
            table.redraw();
        }
    });
    // Add a text column to show the address.
    TextColumn<Contact> addressColumn = new TextColumn<Contact>() {
        @Override
        public String getValue(Contact object) {
            return object.address;
        }
    };
    table.addColumn(addressColumn, "Address");

    // Set the total row count. This isn't strictly necessary, but it affects
    // paging calculations, so its good habit to keep the row count up to date.
    table.setRowCount(CONTACTS.size(), true);

    // Push the data into the widget.
    table.setRowData(0, CONTACTS);

    // Add it to the root panel.
    RootPanel.get().add(table);
}

From source file:io.pelle.mango.client.gwt.modules.dictionary.controls.time.DateControlFactory.java

License:Open Source License

@Override
public <VOType extends IBaseVO> Column<ITableRow<VOType>, ?> createColumn(final DateControl dateControl,
        boolean editable, ListDataProvider<ITableRow<VOType>> listDataProvider,
        IMangoCellTable<VOType> mangoCellTable) {
    if (editable) {
        final DatePickerCell datePickerCell = new DatePickerCell();

        Column<IBaseTable.ITableRow<VOType>, Date> column = new Column<IBaseTable.ITableRow<VOType>, Date>(
                datePickerCell) {/*  ww w.  ja  va 2  s. c  o m*/

            @Override
            public Date getValue(IBaseTable.ITableRow<VOType> tableRow) {
                Object date = tableRow.getElement(dateControl.getModel()).getValue();

                if (date == null) {
                    return new Date();
                } else {
                    return (Date) tableRow.getElement(dateControl.getModel()).getValue();
                }
            }
        };

        FieldUpdater<IBaseTable.ITableRow<VOType>, Date> fieldUpdater = new FieldUpdater<IBaseTable.ITableRow<VOType>, Date>() {
            @SuppressWarnings("unchecked")
            @Override
            public void update(int index, IBaseTable.ITableRow<VOType> tableRow, Date value) {
                tableRow.getElement(dateControl.getModel()).setValue(value);
            }
        };
        column.setFieldUpdater(fieldUpdater);

        return column;
    } else {
        return super.createColumn(dateControl, editable, listDataProvider, mangoCellTable);
    }
}

From source file:org.mklab.taskit.client.ui.admin.LectureEditorView.java

License:Apache License

private Column<LectureProxy, Date> createDateColumn() {
    final Column<LectureProxy, Date> dateColumn = new Column<LectureProxy, Date>(new DatePickerCell()) {

        @Override/* www.  j av a2 s .c o m*/
        public Date getValue(LectureProxy object) {
            return object.getDate();
        }

    };
    dateColumn.setFieldUpdater(new FieldUpdater<LectureProxy, Date>() {

        @Override
        public void update(@SuppressWarnings("unused") int index, LectureProxy object, Date value) {
            final LectureProxy lecture = getPresenter().edit(object);
            lecture.setDate(value);
            getPresenter().save(lecture);
        }
    });
    return dateColumn;
}