Package honeycrm.client.field

Source Code of honeycrm.client.field.FieldDate

package honeycrm.client.field;

import honeycrm.client.dto.Dto;
import honeycrm.client.misc.Callback;
import honeycrm.client.misc.View;

import java.io.Serializable;
import java.util.Date;

import com.google.gwt.cell.client.DateCell;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.i18n.client.DateTimeFormat.PredefinedFormat;
import com.google.gwt.user.cellview.client.Column;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.user.datepicker.client.DateBox;

public class FieldDate extends AbstractField<Date, Void> {
  private static final long serialVersionUID = 734488177370075237L;

  public FieldDate() {
  }

  public FieldDate(final String index, final String label) {
    super(index, label);
  }

  @Override
  protected Serializable internalGetData(Widget w) {
    return ((DateBox) w).getValue();
  }

  @Override
  protected Widget editField() {
    final DateBox box = new DateBox();
    box.setFormat(new DateBox.DefaultFormat(DateTimeFormat.getFormat(PredefinedFormat.DATE_LONG)));
    return box;
  }

  @Override
  protected void internalSetData(DateBox widget, Object value, View view) {
    if (value instanceof Date) {
      widget.setValue((Date) value);
    } else {
      // nothing to do
    }
  }

  @Override
  protected void internalSetData(Label widget, Object value, View view) {
    widget.setText(internalFormattedValue(value));
  }
 
  @Override
  public String internalFormattedValue(Object value) {
    return null == value ? "" : DateTimeFormat.getFormat(PredefinedFormat.DATE_LONG).format((Date) value);
  }

  @Override
  public Column<Dto, Date> getColumn(String fieldName, final View viewMode, final Callback<Void> fieldUpdatedCallback) {
    return new Column<Dto, Date>(new DateCell()) {
      @Override
      public Date getValue(Dto object) {
        return null;
      }
    };
  }
}
TOP

Related Classes of honeycrm.client.field.FieldDate

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.