View Javadoc

    1   /*
    2    *  soapUI, copyright (C) 2004-2007 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.getProjectList(), 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", asList );
    49  		if( targetProjectName == null )
    50  			return;
    51
    52  		WsdlProject targetProject = ( WsdlProject ) workspace.getProjectByName( targetProjectName );
    53  		if( targetProject == null )
    54  		{
    55  			targetProjectName = UISupport.prompt( "Enter name for new Project", "Clone TestSuite", "" );
    56  			if( targetProjectName == null )
    57  				return;
    58
    59  			try
    60  			{
    61  				targetProject = workspace.createProject( targetProjectName );
    62  			}
    63  			catch( SoapUIException e )
    64  			{
    65  				UISupport.showErrorMessage( e );
    66  			}
    67
    68  			if( targetProject == null )
    69  				return;
    70  		}
    71
    72  		WsdlInterface targetIface = targetProject.getInterfaceByBindingName( iface.getBindingName() );
    73  		if( targetIface != null )
    74  		{
    75  			UISupport.showErrorMessage( "Target Project already contains Interface for binding" );
    76  		}
    77  		else
    78  		{
    79  			UISupport.select( targetProject.importInterface( iface ) );
    80  		}
    81     }
    82  }