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.impl.wsdl.actions.project;
14  
15  import java.io.IOException;
16  
17  import com.eviware.soapui.SoapUI;
18  import com.eviware.soapui.impl.wsdl.WsdlProject;
19  import com.eviware.soapui.model.mock.MockService;
20  import com.eviware.soapui.model.testsuite.TestSuite;
21  import com.eviware.soapui.support.UISupport;
22  import com.eviware.soapui.support.action.support.AbstractSoapUIAction;
23  
24  /***
25   * Removes a WsdlProject from the workspace
26   * 
27   * @author Ole.Matzura
28   */
29  
30  public class RemoveProjectAction extends AbstractSoapUIAction<WsdlProject>
31  {
32  	public static final String SOAPUI_ACTION_ID = "RemoveProjectAction";
33  
34  	public RemoveProjectAction()
35  	{
36  		super( "Remove", "Removes this project from the workspace" );
37  	}
38  
39  	public void perform( WsdlProject project, Object param )
40  	{
41  		if( hasRunningTests( project ) )
42  		{
43  			UISupport.showErrorMessage( "Cannot remove Interface due to running tests" );
44  			return;
45  		}
46  
47  		Boolean retval = Boolean.FALSE;
48  
49  		if( project.isOpen() )
50  		{
51  			retval = UISupport.confirmOrCancel( "Save project [" + project.getName() + "] before removing?",
52  					"Remove Project" );
53  			if( retval == null )
54  				return;
55  		}
56  		else
57  		{
58  			if( !UISupport.confirm( "Remove project [" + project.getName() + "] from workspace", "Remove Project" ) )
59  				return;
60  		}
61  
62  		if( retval.booleanValue() )
63  		{
64  			try
65  			{
66  				project.save();
67  			}
68  			catch( IOException e1 )
69  			{
70  				UISupport.showErrorMessage( e1 );
71  			}
72  		}
73  
74  		project.getWorkspace().removeProject( project );
75  	}
76  
77  	private boolean hasRunningTests( WsdlProject project )
78  	{
79  		for( int c = 0; c < project.getTestSuiteCount(); c++ )
80  		{
81  			TestSuite testSuite = project.getTestSuiteAt( c );
82  			for( int i = 0; i < testSuite.getTestCaseCount(); i++ )
83  			{
84  				if( SoapUI.getTestMonitor().hasRunningTest( testSuite.getTestCaseAt( i ) ) )
85  				{
86  					return true;
87  				}
88  			}
89  		}
90  
91  		for( MockService mockService : project.getMockServiceList() )
92  		{
93  			if( SoapUI.getTestMonitor().hasRunningMock( mockService ) )
94  			{
95  				return true;
96  			}
97  		}
98  
99  		return false;
100 	}
101 }