Skip to content

Instantly share code, notes, and snippets.

@mgenov
Created July 20, 2011 11:54
Show Gist options
  • Save mgenov/1094828 to your computer and use it in GitHub Desktop.
Save mgenov/1094828 to your computer and use it in GitHub Desktop.
HacketDateInput.java
public class DateInput implements Validatable {
public interface Display {
HasValue<Date> getDate();
void showError(boolean error);
void clear();
void setEnabled(boolean enabled);
}
private Display display;
private boolean required;
@Inject
public DateInput() {
}
public void bindDisplay(Display display) {
this.display = display;
}
@SuppressWarnings("deprecation")
public Date getSelectedDate() {
if (display.getDate() == null) {
return null;
}
Date date = display.getDate().getValue();
/**
* This is a handy way which we are using to handle repeated billing periods
* when contract is edited manually by the user. This check need to be removed
* when new version of the application is made.
*/
if (date != null) {
date.setHours(12);
}
return date;
}
public void setRequired(boolean required) {
this.required = required;
}
public boolean isValid() {
if (display.getDate().getValue() == null && required == true) {
return false;
}
return true;
}
public void showError() {
display.showError(!isValid());
}
public void go(HasWidgets parent) {
parent.add((Widget) display);
}
/**
* Sets the specified date value. Please note that dates with null values aren't being set, which means
* that if you are having an existing date and you are trying to set null value the value will be the same
* as was before the invocation.
*
* @param date the date to be set
*/
public void setDate(Date date) {
display.getDate().setValue(date);
}
public void clear() {
display.clear();
display.showError(false);
}
public void setEnabled(boolean enabled) {
display.setEnabled(enabled);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment