eu.future.earth.gwt.client.DateButtonWithPicker Maven / Gradle / Ivy
The newest version!
package eu.future.earth.gwt.client;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.logical.shared.HasValueChangeHandlers;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Widget;
import eu.future.earth.client.date.DateNoTimeZone;
import eu.future.earth.gwt.client.date.FtrGwtResources;
import eu.future.earth.gwt.client.date.picker.DatePickerDialog;
import eu.future.earth.gwt.client.date.picker.DateSelectEvent;
import eu.future.earth.gwt.client.date.picker.DateSelectListener;
import eu.future.earth.gwt.client.date.picker.NoneContraintAndEntryRenderer;
import eu.future.earth.gwt.client.ui.button.TouchButton;
import eu.future.earth.gwt.client.ui.button.UiType;
public class DateButtonWithPicker extends Composite implements ClickHandler, DateSelectListener, HasValueChangeHandlers {
private TouchButton dateButton = new TouchButton(new Image(FtrGwtResources.IMAGES.cal()), UiType.Regular);
private DatePickerDialog datePicker = null;
private NoneContraintAndEntryRenderer renderer = new NoneContraintAndEntryRenderer();
private List toAdd = new ArrayList();
public void addWidgetToPicker(Widget newWidget) {
toAdd.add(newWidget);
};
public DateButtonWithPicker() {
super();
initWidget(dateButton);
dateButton.addClickHandler(this);
}
private boolean state = true;
public void setEditable(boolean newState) {
state = newState;
if (state) {
dateButton.setVisible(true);
} else {
dateButton.setVisible(false);
}
}
public void setButtonEnabled(boolean newState) {
dateButton.setEnabled(newState);
}
private Date theDate = null;
public void setDate(Date newValue) {
theDate = newValue;
}
public void setDateNoTimeZone(DateNoTimeZone newValue) {
theDate = DateNoTimeZone.convert(newValue);
}
public Date getValue() {
return theDate;
}
@Override
public void onClick(ClickEvent widget) {
if (datePicker == null) {
datePicker = new DatePickerDialog(renderer, UiType.Regular);
datePicker.addDateSelectEventHandler(this);
for (Widget add : toAdd) {
datePicker.addWidgetToPicker(add);
}
}
if (theDate == null) {
theDate = new Date();
}
datePicker.setSelectedDate(theDate);
datePicker.show(this);
}
@Override
public HandlerRegistration addValueChangeHandler(ValueChangeHandler handler) {
return addHandler(handler, ValueChangeEvent.getType());
}
@Override
public void handleDateSelectEvent(DateSelectEvent newEvent) {
if (newEvent.getSource() == datePicker) {
} else {
// set
}
theDate = newEvent.getDate();
ValueChangeEvent.fire(this, newEvent.getDate());
}
}