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.support.AbstractInterface;
16  import com.eviware.soapui.impl.wsdl.WsdlProject;
17  import com.eviware.soapui.impl.wsdl.actions.iface.RemoveInterfaceAction;
18  import com.eviware.soapui.support.UISupport;
19  
20  public class InterfaceToProjectDropHandler extends AbstractAfterModelItemDropHandler<AbstractInterface<?>, WsdlProject>
21  {
22  	@SuppressWarnings( "unchecked" )
23  	public InterfaceToProjectDropHandler()
24  	{
25  		super( ( Class<AbstractInterface<?>> )( Class )AbstractInterface.class, WsdlProject.class );
26  	}
27  
28  	@Override
29  	boolean canCopyAfter( AbstractInterface<?> source, WsdlProject target )
30  	{
31  		return source.getProject() != target && target.isOpen();
32  	}
33  
34  	@Override
35  	boolean canMoveAfter( AbstractInterface<?> source, WsdlProject target )
36  	{
37  		return source.getProject() != target && target.isOpen();
38  	}
39  
40  	@Override
41  	boolean copyAfter( AbstractInterface<?> source, WsdlProject target )
42  	{
43  		AbstractInterface<?> targetInterface = target.getInterfaceByTechnicalId( source.getTechnicalId() );
44  		if( targetInterface != null )
45  		{
46  			UISupport.showErrorMessage( "Target project already contains this Interface" );
47  			return false;
48  		}
49  		else if( !UISupport.confirm( "Copy Interface [" + source.getName() + "] to Project [" + target.getName() + "]",
50  				"Copy Interface" ) )
51  		{
52  			return false;
53  		}
54  
55  		boolean importEndpoints = UISupport.confirm( "Import endpoint defaults also?", "Copy Interface" );
56  		UISupport.select( target.importInterface( source, importEndpoints, true ) );
57  
58  		return true;
59  	}
60  
61  	@Override
62  	boolean moveAfter( AbstractInterface<?> source, WsdlProject target )
63  	{
64  		AbstractInterface<?> targetInterface = target.getInterfaceByTechnicalId( source.getTechnicalId() );
65  		if( targetInterface != null )
66  		{
67  			UISupport.showErrorMessage( "Target project already contains this Interface" );
68  			return false;
69  		}
70  
71  		if( RemoveInterfaceAction.hasRunningDependingTests( source ) )
72  		{
73  			UISupport.showErrorMessage( "Cannot remove Interface due to running depending tests" );
74  			return false;
75  		}
76  
77  		if( RemoveInterfaceAction.hasDependingTests( source ) )
78  		{
79  			Boolean retval = UISupport.confirmOrCancel(
80  					"Interface has depending Test Steps which will be removed. Copy Instead?"
81  							+ "\r\n(moving will remove dependant Test Steps from source project)", "Move Interface" );
82  
83  			if( retval == null )
84  				return false;
85  
86  			if( retval == true )
87  			{
88  				boolean importEndpoints = UISupport.confirm( "Move endpoint defaults also?", "Move Interface" );
89  				UISupport.select( target.importInterface( source, importEndpoints, true ) );
90  				return true;
91  			}
92  		}
93  		else if( !UISupport.confirm( "Move Interface [" + source.getName() + "] to Project [" + target.getName() + "]",
94  				"Move Interface" ) )
95  		{
96  			return false;
97  		}
98  
99  		boolean importEndpoints = UISupport.confirm( "Move endpoint defaults also?", "Move Interface" );
100 		UISupport.select( target.importInterface( source, importEndpoints, false ) );
101 		source.getProject().removeInterface( source );
102 		return true;
103 	}
104 
105 	@Override
106 	String getCopyAfterInfo( AbstractInterface<?> source, WsdlProject target )
107 	{
108 		return "Copy Interface [" + source.getName() + "] to Project [" + target.getName() + "]";
109 	}
110 
111 	@Override
112 	String getMoveAfterInfo( AbstractInterface<?> source, WsdlProject target )
113 	{
114 		return "Move Interface [" + source.getName() + "] to Project [" + target.getName() + "]";
115 	}
116 
117 }