View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2008 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  
14  package com.eviware.soapui.support.dnd.handlers;
15  
16  import com.eviware.soapui.impl.support.AbstractInterface;
17  import com.eviware.soapui.impl.wsdl.WsdlProject;
18  import com.eviware.soapui.impl.wsdl.actions.iface.RemoveInterfaceAction;
19  import com.eviware.soapui.support.UISupport;
20  
21  public class InterfaceToProjectDropHandler extends AbstractAfterModelItemDropHandler<AbstractInterface<?>, WsdlProject>
22  {
23  	@SuppressWarnings("unchecked")
24  	public InterfaceToProjectDropHandler()
25  	{
26  		super( (Class<AbstractInterface<?>>)(Class) AbstractInterface.class, WsdlProject.class );
27  	}
28  	
29  	@Override
30  	boolean canCopyAfter( AbstractInterface<?> source, WsdlProject target )
31  	{
32  		return source.getProject() != target && target.isOpen();
33  	}
34  
35  	@Override
36  	boolean canMoveAfter( AbstractInterface<?> source, WsdlProject target )
37  	{
38  		return source.getProject() != target && target.isOpen();
39  	}
40  
41  	@Override
42  	boolean copyAfter( AbstractInterface<?> source, WsdlProject target )
43  	{
44  		AbstractInterface<?> targetInterface = target.getInterfaceByTechnicalId( source.getTechnicalId() );
45  		if( targetInterface != null )
46  		{
47  			UISupport.showErrorMessage( "Target project already contains this Interface" );
48  			return false;
49  		}
50  		else if( !UISupport.confirm( "Copy Interface [" + source.getName() + "] to Project [" + 
51  					target.getName() + "]", "Copy Interface" ))
52  		{
53  			return false;
54  		}
55  		
56  		boolean importEndpoints = UISupport.confirm( "Import endpoint defaults also?", "Copy Interface" );
57  		UISupport.select( target.importInterface( source, importEndpoints, true ));
58  		
59  		return true;
60  	}
61  
62  	@Override
63  	boolean moveAfter( AbstractInterface<?> source, WsdlProject target )
64  	{
65  		AbstractInterface<?> targetInterface = target.getInterfaceByTechnicalId( source.getTechnicalId() );
66  		if( targetInterface != null )
67  		{
68  			UISupport.showErrorMessage( "Target project already contains this Interface" );
69  			return false;
70  		}
71  
72  		if( RemoveInterfaceAction.hasRunningDependingTests( source ) )
73     	{
74     		UISupport.showErrorMessage( "Cannot remove Interface due to running depending tests" );
75     		return false;
76     	}
77     	
78  		if( RemoveInterfaceAction.hasDependingTests( source ) )
79     	{
80     		Boolean retval = UISupport.confirmOrCancel( "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 [" + 
94  						target.getName() + "]", "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 	
118 }