Auto closing of modal window

Hello!
What is the best way to implement the auto closing of a modal window after some time (let us say 2 or 3 minutes)?

Background:I have a touch application where the user can open a modal window which advices him to put his member card into the card reader. However this is a kiosk application, meaning that nearly every day an user opens the window but does not progress. Therefor I want to implement an auto closing functionality if no further interaction occurs.

Has someone ever implemented such a functionality and can give me some adivces how to implements this? Should I try to use the auto reresher addon for that? Or has vaadin some kind of preimplemented methods for that? I am still using vaadin 6.

I am very grateful for any help,
Florian

Hello Florian.

Well basically you need a Thread that executes a Window.close() method after a specific time. You then also need a polling mechanism so that the client gets notified that the Window is closed. To do this you could either use a Refresher (use RefreshListener instead of a Thread) or in this case you could also use he built-in
Progress Indicator
. Using this you can make a Worker Thread which also updates the Indicator to give a visual representation of when the Time is over.

Hope it Helps,
Marius

Thank you for your help, it had worked like a charme. If someone may need this as well, this is my code for the WindowClosingThread:


public class AutoWindowCloser extends Thread {
	
	private Window window;
	private long closingTime;
	private boolean exit;
	private Refresher refresher;
	private static Log log = LogFactory.getLog(AutoWindowCloser.class);
	
	public AutoWindowCloser(Window window, long closingTime, Refresher refresher) {
		this.window = window;
		this.closingTime = closingTime;
		this.refresher = refresher;
		this.exit = false;
	}
	
	public void exitThread() {
		log.debug("Disabling auto window closer...");
		this.exit = true;
	}
	
	public void run() {
		
		// Sleep for the given time
		try {
			log.debug("Window will close in "+closingTime+" milliseconds...");
			Thread.sleep(closingTime);
			
			// Close the window if quit is false
			if(!exit) {
				log.debug("Window will close...");
				window.getApplication().getMainWindow().removeWindow(window);
				refresher.setEnabled(true);
			}
			else {
				log.debug("Automatic Window Closing disabled...");
			}
			
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}

You do not need the refresher, I just use it in my application, and that is the reason why I have added it to the thread.
Greetings,
Florian

With the coming 7.1 you can also use the built-in push or polling mechanisms, no need for the ProgressIndicator hack or other add-ons.