1
2
3
4
5
6
7
8
9
10
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 }