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.wsdl.actions.iface;
14  
15  import java.util.ArrayList;
16  import java.util.Arrays;
17  import java.util.List;
18  
19  import com.eviware.soapui.impl.WorkspaceImpl;
20  import com.eviware.soapui.impl.wsdl.WsdlInterface;
21  import com.eviware.soapui.impl.wsdl.WsdlProject;
22  import com.eviware.soapui.model.support.ModelSupport;
23  import com.eviware.soapui.support.SoapUIException;
24  import com.eviware.soapui.support.UISupport;
25  import com.eviware.soapui.support.action.support.AbstractSoapUIAction;
26  
27  /***
28   * Clones an Interface to another project
29   * 
30   * @author Ole.Matzura
31   */
32  
33  public class CloneInterfaceAction extends AbstractSoapUIAction<WsdlInterface>
34  {
35  	public CloneInterfaceAction()
36  	{
37  		super( "Clone Interface", "Clones this Interface to another project" );
38  	}
39  
40  	public void perform( WsdlInterface iface, Object param )
41  	{
42  		WorkspaceImpl workspace = iface.getProject().getWorkspace();
43  		String[] names = ModelSupport.getNames( workspace.getOpenProjectList(), new String[] { "<Create New>" } );
44  
45  		List<String> asList = new ArrayList<String>( Arrays.asList( names ) );
46  		asList.remove( iface.getProject().getName() );
47  
48  		String targetProjectName = UISupport.prompt( "Select target Project for cloned Interface", "Clone Interface",
49  				asList );
50  		if( targetProjectName == null )
51  			return;
52  
53  		WsdlProject targetProject = ( WsdlProject )workspace.getProjectByName( targetProjectName );
54  		if( targetProject == null )
55  		{
56  			targetProjectName = UISupport.prompt( "Enter name for new Project", "Clone TestSuite", "" );
57  			if( targetProjectName == null )
58  				return;
59  
60  			try
61  			{
62  				targetProject = workspace.createProject( targetProjectName, null );
63  			}
64  			catch( SoapUIException e )
65  			{
66  				UISupport.showErrorMessage( e );
67  			}
68  
69  			if( targetProject == null )
70  				return;
71  		}
72  
73  		WsdlInterface targetIface = ( WsdlInterface )targetProject.getInterfaceByTechnicalId( iface.getTechnicalId() );
74  		if( targetIface != null )
75  		{
76  			UISupport.showErrorMessage( "Target Project already contains Interface for binding" );
77  		}
78  		else
79  		{
80  			boolean importEndpoints = UISupport.confirm( "Import endpoint defaults also?", getName() );
81  			UISupport.select( targetProject.importInterface( iface, importEndpoints, true ) );
82  		}
83  	}
84  }