I'm new to Vaadin and I want to implement this: when a button is clicked a window containing a calendar is opened, and the user should choose a date in the calendar. The user should be blocked until he chooses the date, so I wrote this:
public class KopivaadincomponentsUI extends UI {
@Override
protected void init(VaadinRequest request) {
final VerticalLayout layout = new VerticalLayout();
layout.setMargin(true);
setContent(layout);
Button button = new Button("Click Me");
button.addClickListener(new Button.ClickListener() {
public void buttonClick(ClickEvent event) {
DateChooser dateChooser = new DateChooser(new com.kopiright.xkopi.lib.type.Date(2013, 12, 9));
UI.getCurrent().addWindow(dateChooser);
synchronized (Lock.getInstance()) {
while (dateChooser.isVisible()) {
try {
Lock.getInstance().wait();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
});
layout.addComponent(button);
}
Here's the DateChooser—the window containing the calendar:
public class DateChooser extends Window implements ValueChangeListener{
public DateChooser(Date date){
this.setModal(true);
final FormLayout content = new FormLayout();
calPane = new CalendarPane();
content.addComponent(calPane);
this.setContent(content);
lock =new Lock();
}
/*package*/ class CalendarPane extends InlineDateField {
public CalendarPane() {
setImmediate(true);
setResolution(RESOLUTION_DAY);
setShowISOWeekNumbers(true);
}
private static final long serialVersionUID = -3958329773743250969L;
}
private CalendarPane calPane;
private static final long serialVersionUID = 1L;
@Override
public void valueChange(ValueChangeEvent event) {
synchronized(Lock.getInstance()) {
String date = String.valueOf(event.getProperty().getValue());
Calendar cal = Calendar.getInstance(Locale.FRANCE);
cal.setTime((java.util.Date) event.getProperty().getValue());
setSelectedDate(new NotNullDate(cal));
this.close();
Lock.getInstance().notify();
}
}
}
The problem is that when I click the button it waits infinitely. Any ideas will be appreciated.