How to prevent someone from rapid clicking on a FileDownloader button?

Using the same code form the manual we have:

Button downloadButton = new Button("Download image");
FileDownloader fileDownloader = new FileDownloader(createResource());
fileDownloader.extend(downloadButton);

The problem with this sample code is that someone could just start to rapid click on the downloadButton 50x in a row and the dynamically created file would be generated 50x. Is there a way to put a limiter, that is say after x times prevent the user from downloading? Also if you click on this rapidly you get an error, specifically a DefaultErrorHandler.

At the very least I would like a way to prevent someone from downloading the file more than x times. Additionally it would be nice to have something like downloadButton.disableOnClick() but I can’t seem to find a way to re-enable after the download has finished…

I would try the following. Add click listener to the button and disable the button in the click event. You can re-enable the button in
handleConnectorRequest
of the FileDownloader.

Can you please expand what you by then re-enable the button in handleConnectorRequest? Unfortauntely there isn’t much in the Javadocs to explain how you would do this…

I meant somenting like this, i.e. overdrive that method:

FileDownloader downloader = new FileDownloader(stream) {
    @Override
    public boolean handleConnectorRequest(VaadinRequest request, VaadinResponse response, String path) throws IOException {
         <re-enable your button here>
         return super .handleConnectorRequest(request, response, path);
    }
};