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.dnd.handlers;
14  
15  import com.eviware.soapui.impl.wsdl.WsdlProject;
16  import com.eviware.soapui.impl.wsdl.WsdlTestSuite;
17  import com.eviware.soapui.impl.wsdl.actions.testsuite.CloneTestSuiteAction;
18  import com.eviware.soapui.support.UISupport;
19  
20  public class TestSuiteToProjectDropHandler extends AbstractAfterModelItemDropHandler<WsdlTestSuite, WsdlProject>
21  {
22  	public TestSuiteToProjectDropHandler()
23  	{
24  		super( WsdlTestSuite.class, WsdlProject.class );
25  	}
26  
27  	@Override
28  	boolean canCopyAfter( WsdlTestSuite source, WsdlProject target )
29  	{
30  		return true;
31  	}
32  
33  	@Override
34  	boolean canMoveAfter( WsdlTestSuite source, WsdlProject target )
35  	{
36  		return source.getProject() != target;
37  	}
38  
39  	@Override
40  	boolean copyAfter( WsdlTestSuite source, WsdlProject target )
41  	{
42  		String name = UISupport.prompt( "Specify name for copied TestSuite", "Copy TestSuite", "Copy of "
43  				+ source.getName() );
44  		if( name == null )
45  			return false;
46  
47  		if( source.getProject() == target )
48  		{
49  			return CloneTestSuiteAction.cloneTestSuiteWithinProject( source, name, target, source.getDescription() );
50  		}
51  		else
52  		{
53  			return CloneTestSuiteAction.cloneToAnotherProject( source, target.getName(), name, false, source
54  					.getDescription() ) != null;
55  		}
56  	}
57  
58  	@Override
59  	boolean moveAfter( WsdlTestSuite source, WsdlProject target )
60  	{
61  		String name = UISupport.prompt( "Specify name for moved TestSuite", "Move TestSuite", source.getName() );
62  		if( name == null )
63  			return false;
64  
65  		WsdlTestSuite testSuite = CloneTestSuiteAction.cloneToAnotherProject( source, target.getName(), name, true,
66  				source.getDescription() );
67  		if( testSuite != null )
68  		{
69  			source.getProject().removeTestSuite( source );
70  			return true;
71  		}
72  
73  		return false;
74  	}
75  
76  	@Override
77  	String getCopyAfterInfo( WsdlTestSuite source, WsdlProject target )
78  	{
79  		return source.getProject() == target ? "Copy TestSuite [" + source.getName() + "] within Project ["
80  				+ target.getName() + "]" : "Copy TestSuite [" + source.getName() + "] to Project [" + target.getName()
81  				+ "]";
82  	}
83  
84  	@Override
85  	String getMoveAfterInfo( WsdlTestSuite source, WsdlProject target )
86  	{
87  		return "Move TestSuite [" + source.getName() + "] to Project [" + target.getName() + "]";
88  	}
89  
90  }