Ejemplo n.º 1
0
  @SuppressWarnings("serial")
  private Component buildDateFilter() {

    HorizontalLayout dateLayout = new HorizontalLayout();

    final PopupDateField startDate = new PopupDateField();
    startDate.addStyleName(ValoTheme.DATEFIELD_TINY);
    startDate.setWidth("150px");
    startDate.setDateFormat("yyyy-MM-dd");
    startDate.setInputPrompt("Start");

    startDate.setValue(today);

    dateLayout.addComponent(startDate);

    dateLayout.setComponentAlignment(startDate, Alignment.MIDDLE_CENTER);

    Label separator = new Label();
    separator.setCaptionAsHtml(true);
    separator.setCaption(" - ");
    dateLayout.addComponent(separator);

    final PopupDateField endDate = new PopupDateField();
    endDate.addStyleName(ValoTheme.DATEFIELD_TINY);
    endDate.setDateFormat("yyyy-MM-dd");
    endDate.setWidth("150px");
    endDate.setInputPrompt("End");
    endDate.setValue(tmrw);

    startDate.addValueChangeListener(
        new Property.ValueChangeListener() {

          public void valueChange(ValueChangeEvent event) {

            // endDateVal = (String) event.getProperty().getValue();
            // Notification.show("Start Date:"+startDate.getValue()+"End Date: " +
            // endDate.getValue());

            // fire event
            if (endDate.getValue() != null) {
              queryAndRefresh(
                  dateFormat.format(startDate.getValue()), dateFormat.format(endDate.getValue()));
            }
          }
        });

    endDate.addValueChangeListener(
        new Property.ValueChangeListener() {

          @SuppressWarnings("deprecation")
          public void valueChange(ValueChangeEvent event) {

            // endDateVal = (String) event.getProperty().getValue();
            // Notification.show("Start Date:"+startDate.getValue()+"End Date: " +
            // endDate.getValue());

            // fire event
            if (startDate.getValue() != null) {
              queryAndRefresh(
                  dateFormat.format(startDate.getValue()), dateFormat.format(endDate.getValue()));
            } else {
              Notification.show("Please enter Start Date", Notification.TYPE_WARNING_MESSAGE);
            }
          }
        });

    dateLayout.addComponent(endDate);

    return dateLayout;
  }