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.WsdlProject;
17  import com.eviware.soapui.impl.wsdl.actions.mockservice.CloneMockServiceAction;
18  import com.eviware.soapui.impl.wsdl.mock.WsdlMockService;
19  import com.eviware.soapui.support.UISupport;
20  import com.eviware.soapui.support.action.SoapUIAction;
21  
22  public class MockServiceToProjectDropHandler extends AbstractAfterModelItemDropHandler<WsdlMockService, WsdlProject>
23  {
24  	public MockServiceToProjectDropHandler()
25  	{
26  		super( WsdlMockService.class, WsdlProject.class );
27  	}
28  
29  	@Override
30  	boolean canCopyAfter( WsdlMockService source, WsdlProject target )
31  	{
32  		return true;
33  	}
34  
35  	@Override
36  	boolean canMoveAfter( WsdlMockService source, WsdlProject target )
37  	{
38  		return source.getProject() != target;
39  	}
40  
41  	@Override
42  	boolean copyAfter( WsdlMockService source, WsdlProject target )
43  	{
44  		SoapUIAction<WsdlMockService> action = SoapUI.getActionRegistry().getAction(
45  				CloneMockServiceAction.SOAPUI_ACTION_ID );
46  		CloneMockServiceAction a = ( CloneMockServiceAction )action;
47  
48  		String name = UISupport.prompt( "Specify name for copied MockService", "Copy MockService", "Copy of "
49  				+ source.getName() );
50  		if( name == null )
51  			return false;
52  
53  		if( source.getProject() == target )
54  		{
55  			a.cloneMockServiceWithinProject( source, name, target, source.getDescription() );
56  		}
57  		else
58  		{
59  			a.cloneToAnotherProject( source, target.getName(), name, source.getDescription() );
60  		}
61  
62  		return true;
63  	}
64  
65  	@Override
66  	boolean moveAfter( WsdlMockService source, WsdlProject target )
67  	{
68  		SoapUIAction<WsdlMockService> action = SoapUI.getActionRegistry().getAction(
69  				CloneMockServiceAction.SOAPUI_ACTION_ID );
70  		CloneMockServiceAction a = ( CloneMockServiceAction )action;
71  
72  		String name = UISupport.prompt( "Specify name for moved MockService", "Move MockService", source.getName() );
73  		if( name == null )
74  			return false;
75  
76  		if( a.cloneToAnotherProject( source, target.getName(), name, source.getDescription() ) == null )
77  			return false;
78  
79  		source.getProject().removeMockService( source );
80  		return true;
81  	}
82  
83  	@Override
84  	String getCopyAfterInfo( WsdlMockService source, WsdlProject target )
85  	{
86  		return "Copy MockService [" + source.getName() + "] to Project [" + target.getName() + "]";
87  	}
88  
89  	@Override
90  	String getMoveAfterInfo( WsdlMockService source, WsdlProject target )
91  	{
92  		return "Move MockService [" + source.getName() + "] to Project [" + target.getName() + "]";
93  	}
94  
95  }