View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2010 eviware.com 
3    *
4    *  soapUI is free software; you can redistribute it and/or modify it under the 
5    *  terms of version 2.1 of the GNU Lesser General Public License as published by 
6    *  the Free Software Foundation.
7    *
8    *  soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 
9    *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
10   *  See the GNU Lesser General Public License for more details at gnu.org.
11   */
12  
13  package com.eviware.soapui.support.swing;
14  
15  import com.eviware.x.dialogs.Worker;
16  import com.eviware.x.dialogs.XProgressDialog;
17  import com.eviware.x.dialogs.XProgressMonitor;
18  
19  /***
20   * 
21   * @author Lars Høidahl
22   */
23  public class SwingWorkerDelegator extends SwingWorker
24  {
25  	private XProgressMonitor monitor;
26  	private Worker delegate;
27  	private XProgressDialog dialog;
28  
29  	/***
30  	 * Start a thread that will call <code>delegate.construct</code> and then
31  	 * exit.
32  	 */
33  	public SwingWorkerDelegator( XProgressMonitor monitor, XProgressDialog dialog, Worker delegate )
34  	{
35  		this.monitor = monitor;
36  		this.dialog = dialog;
37  		this.delegate = delegate;
38  	}
39  
40  	/***
41  	 * Compute the value to be returned by the <code>get</code> method.
42  	 */
43  
44  	public Object construct()
45  	{
46  		return delegate.construct( monitor );
47  	}
48  
49  	/***
50  	 * Called on the event dispatching thread (not on the worker thread) after
51  	 * the <code>construct</code> method has returned.
52  	 */
53  	public void finished()
54  	{
55  		delegate.finished();
56  		if( dialog != null )
57  			dialog.setVisible( false );
58  		delegate = null;
59  		monitor = null;
60  		dialog = null;
61  	}
62  }