How to clear the buffer of click events?

Hello!
I have an annoying problem with LayoutClickListener.
If the user clicks the mouse too often, it is not possible to clear the buffer of events.
And if each click is processed long enough (more than 100 milliseconds), the whole process begins to slow down.

You can also try it here by often clicking the mouse on the top panel:
http://demo.vaadin.com/sampler#ClickableLayoutBasic

Thanks for any help.

If this problem can not be solved in a general way, then perhaps someone can help me with a particular case.
At the click of the mouse, I hung Event calling a modal window.
If a user makes a few quick clicks, it opens a modal windows - one on another.
What better way to solve this problem?

Sounds quite a tricky problem. The client side can’t really know whether or not to send the event, so I guess the problem should be solved on the server.

What about buffering the click events yourself? Then purge the buffer whenever you feel it’s safe (e.g. once every 100ms), and clear all unwanted events.

I don’t quite get the use case. What is the user trying to do/achieve? Opening modal windows from consecutive mouse clicks sounds like a bad behavior, but since I know nothing about your case, I might be totally wrong.

Thanks for answer!
This gave me an understanding that there is no generally accepted solution. And this is more than enough.
I have all clicks are caught by a single handler.
So I think a fairly good solution would be to ignore events if since the last processed passed less NNN milliseconds.

Thanks for great framework!

Maybe it will be interesting for someone with the same problem.
Here is my solution:

Declare field and constant:


  private Long lastClickTime = null;
  private static final int MAX_TIME_BETWEEN_CLICKS = 1000;

Declare new method:


  private boolean checkOftenClicksOK() {
    boolean res = true;
    Long currentTime = System.currentTimeMillis();
    if (lastClickTime != null) {
      res = Math.abs(lastClickTime - currentTime) >= MAX_TIME_BETWEEN_CLICKS;
    }
    if (res) {
      lastClickTime = currentTime;    
    }
    return res;
  }

Usage example:


    menuLayout.addListener(new LayoutEvents.LayoutClickListener() {
      @Override
      public void layoutClick(LayoutEvents.LayoutClickEvent event) {
        Component child = event.getChildComponent();
        if (child instanceof AbstractComponent) {
          if (checkOftenClicksOK()) {
              onMenuActivated(child);
          }
        }
      }
    });