Vaadin CountdownClock Add On. How to freeze CountdownClock component and/or the appearance of count down tex

443 views Asked by At

I would like to freeze Vaadin CountdownClock component and/or count down text before Count Down is ended on click button. Can you help me to understand, which listeners or events can I establish/fire? After stop count down I would like to know if Count down is 0 or it was stopped.

There is code for button and reset Count Down.

    // button for stop count down table
stopCountDown.addClickListener(new ClickListener() {
    private static final long serialVersionUID = 1L;
    @Override
    public void buttonClick(ClickEvent event) {

      try {
        countDownClock.setImmediate(true);
        // hide count down clock, better would to freeze the text
        countDownClock.setVisible(false);
        // force stop count down
        countDownClockEndEvent.countDownEnded(countDownClock);
        LOGGER.info("Inside click listener of stopCountDown button." + countDownClock.getState().);
        // TODO manage confirmation - get the actual course and realize conversion
      }
      catch (Exception ex) {
          LOGGER.error("Exception inside refresh table listener", ex);
        showNotification("Error:" + ex.getLocalizedMessage(), Type.ERROR_MESSAGE);
      }
    }
  });

Count Down establish:

private void resetTimer() {
    countDownClock = new CountdownClock();
    ratesVerticalRight.addComponent(countDownClock);

    countDownClock.setEnabled(false);

    countDownClockEndEvent = new EndEventListener() {
        //@Override
        public void countDownEnded(CountdownClock clock) {
            LOGGER.info("Inside countDownEnded.");
            showNotification(
                            "Time is out or confirmed <br />"
                            + "next try... <br />", Type.HUMANIZED_MESSAGE);
        }
    };

    countDownClock.addEndEventListener(countDownClockEndEvent);

    System.out.println("State of clock: " +  countDownClock.getState().enabled);

    countDownClock.setEnabled(true);

    //event.getButton().setEnabled(false);
    Calendar c = Calendar.getInstance();
    c.add(Calendar.SECOND, 3);
    countDownClock.setDate(c.getTime());
    countDownClock.setFormat("<span style='font: bold 20px Arial; margin: 10px'>"
                    + "Countdown in %s.%ts seconds.</span>");

}
0

There are 0 answers