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.impl.actions;
14  
15  import java.io.File;
16  
17  import com.eviware.soapui.SoapUIExtensionClassLoader;
18  import com.eviware.soapui.SoapUIExtensionClassLoader.SoapUIClassLoaderState;
19  import com.eviware.soapui.impl.WorkspaceImpl;
20  import com.eviware.soapui.impl.wsdl.WsdlProject;
21  import com.eviware.soapui.support.MessageSupport;
22  import com.eviware.soapui.support.UISupport;
23  import com.eviware.soapui.support.action.support.AbstractSoapUIAction;
24  
25  /***
26   * Actions for importing an existing soapUI project file into the current
27   * workspace
28   * 
29   * @author Ole.Matzura
30   */
31  
32  public class ImportWsdlProjectAction extends AbstractSoapUIAction<WorkspaceImpl>
33  {
34  	public static final String SOAPUI_ACTION_ID = "ImportWsdlProjectAction";
35  	public static final MessageSupport messages = MessageSupport.getMessages( ImportWsdlProjectAction.class );
36  
37  	public ImportWsdlProjectAction()
38  	{
39  		super( messages.get( "title" ), messages.get( "description" ) );
40  	}
41  
42  	public void perform( WorkspaceImpl workspace, Object param )
43  	{
44  		File file = null;
45  
46  		if( param == null )
47  		{
48  			file = UISupport.getFileDialogs().openXML( this, messages.get( "prompt.title" ) );
49  		}
50  		else
51  		{
52  			file = new File( param.toString() );
53  		}
54  
55  		if( file == null )
56  			return;
57  
58  		String fileName = file.getAbsolutePath();
59  		if( fileName == null )
60  			return;
61  
62  		SoapUIClassLoaderState state = SoapUIExtensionClassLoader.ensure();
63  		try
64  		{
65  			WsdlProject project = ( WsdlProject )workspace.importProject( fileName );
66  			if( project != null )
67  				UISupport.select( project );
68  		}
69  		catch( Exception ex )
70  		{
71  			UISupport.showErrorMessage( ex );
72  		}
73  		finally
74  		{
75  			state.restore();
76  		}
77  	}
78  }