com.bearsoft.gwt.ui.widgets.grid.cells.DateEditorCell.java Source code

Java tutorial

Introduction

Here is the source code for com.bearsoft.gwt.ui.widgets.grid.cells.DateEditorCell.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bearsoft.gwt.ui.widgets.grid.cells;

import java.util.Date;

import com.bearsoft.gwt.ui.widgets.DecoratedDateBox;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.safehtml.shared.SafeHtmlUtils;
import com.google.gwt.user.client.ui.Widget;

/**
 * 
 * @author mg
 */
public class DateEditorCell extends RenderedEditorCell<Date> {

    protected DateTimeFormat format = DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.DATE_TIME_MEDIUM);

    public DateEditorCell() {
        super(new DecoratedDateBox());
    }

    public DateEditorCell(Widget aEditor) {
        super(aEditor);
    }

    public DateEditorCell(Widget aEditor, DateTimeFormat aFormat) {
        super(aEditor);
        format = aFormat;
    }

    public DateTimeFormat getFormat() {
        return format;
    }

    public void setFormat(DateTimeFormat aValue) {
        format = aValue;
    }

    @Override
    protected void renderCell(Context context, Date value, SafeHtmlBuilder sb) {
        sb.append(SafeHtmlUtils.fromTrustedString(value != null ? format.format(value) : ""));
    }
}