use of com.vaadin.ui.Window.CloseEvent in project VaadinUtils by rlsutton1.
the class DateTimePickerInline method getChangeYearClickListener.
private ClickListener getChangeYearClickListener() {
return new ClickListener() {
/**
*/
private static final long serialVersionUID = 1L;
@Override
public void buttonClick(ClickEvent event) {
final Window window = new Window();
GridLayout yearGrid = new GridLayout(5, 20);
int currentYear = DateTime.now().getYear();
int endYear = DateTime.now().getYear() + 10;
int startYear = (endYear - 135);
for (int year = endYear; year > startYear; year--) {
final int buttonYear = year;
Button yearButton = new Button("" + year);
yearButton.setStyleName(ValoTheme.BUTTON_TINY);
if (year == currentYear) {
yearButton.addStyleName(ValoTheme.BUTTON_FRIENDLY);
}
yearButton.addClickListener(new ClickListener() {
private static final long serialVersionUID = 1L;
@Override
public void buttonClick(ClickEvent event) {
setValue(new DateTime(getValue().getTime()).withYear(buttonYear).toDate());
window.close();
}
});
yearGrid.addComponent(yearButton);
}
Panel scrollPanel = new Panel();
VerticalLayout container = new VerticalLayout();
container.addComponent(new Label("Select a year"));
container.setMargin(true);
container.addComponent(scrollPanel);
scrollPanel.setContent(yearGrid);
scrollPanel.setHeight("200");
window.setResizable(false);
window.setContent(container);
// position window over year button
int x = event.getClientX();
int y = event.getClientY();
int wh = UI.getCurrent().getPage().getBrowserWindowHeight();
y = Math.max(0, y);
int heightOfDatePicker = 300;
y = Math.min(y, wh - heightOfDatePicker);
int ww = UI.getCurrent().getPage().getBrowserWindowWidth();
x = Math.max(0, x - 50);
int widthOfDatePicker = 290;
x = Math.min(x, ww - widthOfDatePicker);
// window.setModal(true);
window.setPosition(x, y);
window.setClosable(true);
UI.getCurrent().addWindow(window);
// add mouse click listener to close window when the user
// clicks outside of the window
final MouseEvents.ClickListener listener = new MouseEvents.ClickListener() {
private static final long serialVersionUID = 1L;
@Override
public void click(MouseEvents.ClickEvent event) {
window.close();
}
};
UI.getCurrent().addClickListener(listener);
// tidy up: remove mouse click listener
window.addCloseListener(new CloseListener() {
private static final long serialVersionUID = 1L;
@Override
public void windowClose(CloseEvent e) {
UI.getCurrent().removeClickListener(listener);
}
});
}
};
}
Aggregations