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.ui;
14  
15  import java.awt.BorderLayout;
16  import java.lang.reflect.InvocationTargetException;
17  
18  import javax.swing.JPanel;
19  import javax.swing.SwingUtilities;
20  
21  import com.eviware.soapui.support.StringUtils;
22  import com.eviware.soapui.support.components.BrowserComponent;
23  import com.eviware.soapui.ui.support.DefaultDesktopPanel;
24  
25  public class URLDesktopPanel extends DefaultDesktopPanel
26  {
27  	private BrowserComponent browser;
28  	private boolean closed;
29  
30  	public URLDesktopPanel( String title, String description, String url ) throws InterruptedException, InvocationTargetException
31  	{
32  		super( title, description, new JPanel( new BorderLayout() ) );
33  
34  		JPanel panel = ( JPanel )getComponent();
35  
36  		browser = new BrowserComponent( true );
37  		panel.add( browser.getComponent(), BorderLayout.CENTER );
38  
39  		if( StringUtils.hasContent( url ) )
40  			navigate( url, null, true );
41  	}
42  
43  	public void navigate( String url, String errorUrl, boolean async ) 
44  	{
45  		//if (!browser.isBrowserInitialised()) {
46  		//	browser.initBrowser();
47  		//}
48  		if( async )
49  		{
50  			SwingUtilities.invokeLater( new Navigator( url, errorUrl ) );
51  		}
52  		else
53  		{
54  			browser.navigate( url, errorUrl );
55  		}
56  	}
57  
58  	public boolean onClose( boolean canCancel )
59  	{
60  		browser.release();
61  		closed = true;
62  		return super.onClose( canCancel );
63  	}
64  
65  	public boolean isClosed()
66  	{
67  		return closed;
68  	}
69  
70  	private class Navigator implements Runnable
71  	{
72  		private final String url;
73  		private final String errorUrl;
74  
75  		public Navigator( String url, String errorUrl )
76  		{
77  			this.url = url;
78  			this.errorUrl = errorUrl;
79  		}
80  
81  		public void run()
82  		{
83  			
84  				browser.navigate( url, errorUrl );
85  			
86  		}
87  	}
88  }