View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2009 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.SoapUI;
16  import com.eviware.soapui.impl.wsdl.WsdlRequest;
17  import com.eviware.soapui.impl.wsdl.actions.request.AddRequestToMockServiceAction;
18  import com.eviware.soapui.impl.wsdl.mock.WsdlMockOperation;
19  import com.eviware.soapui.support.UISupport;
20  import com.eviware.soapui.support.action.SoapUIAction;
21  
22  public class RequestToMockOperationDropHandler extends
23  		AbstractAfterModelItemDropHandler<WsdlRequest, WsdlMockOperation>
24  {
25  	public RequestToMockOperationDropHandler()
26  	{
27  		super( WsdlRequest.class, WsdlMockOperation.class );
28  	}
29  
30  	@Override
31  	boolean canCopyAfter( WsdlRequest source, WsdlMockOperation target )
32  	{
33  		return source.getOperation() == target.getOperation();
34  	}
35  
36  	@Override
37  	boolean canMoveAfter( WsdlRequest source, WsdlMockOperation target )
38  	{
39  		return source.getOperation() == target.getOperation();
40  	}
41  
42  	@Override
43  	boolean copyAfter( WsdlRequest source, WsdlMockOperation target )
44  	{
45  		return addRequestToMockOperation( source, target );
46  	}
47  
48  	private boolean addRequestToMockOperation( WsdlRequest request, WsdlMockOperation mockOperation )
49  	{
50  		if( !UISupport.confirm( "Add request to MockOperation [" + mockOperation.getName() + "]", "Add Request" ) )
51  			return false;
52  
53  		SoapUIAction<WsdlRequest> action = SoapUI.getActionRegistry().getAction(
54  				AddRequestToMockServiceAction.SOAPUI_ACTION_ID );
55  		( ( AddRequestToMockServiceAction )action ).perform( request, mockOperation );
56  		return true;
57  	}
58  
59  	@Override
60  	boolean moveAfter( WsdlRequest source, WsdlMockOperation target )
61  	{
62  		return addRequestToMockOperation( source, target );
63  	}
64  
65  	@Override
66  	String getCopyAfterInfo( WsdlRequest source, WsdlMockOperation target )
67  	{
68  		return "Add Request [" + source.getName() + "] to MockOperation [" + target.getName() + "]";
69  	}
70  
71  	@Override
72  	String getMoveAfterInfo( WsdlRequest source, WsdlMockOperation target )
73  	{
74  		return getCopyAfterInfo( source, target );
75  	}
76  }