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.awt.event.ActionEvent;
16 import java.io.IOException;
17
18 import javax.swing.AbstractAction;
19 import javax.swing.Action;
20
21 import com.eviware.soapui.SoapUI;
22 import com.eviware.soapui.impl.wsdl.WsdlProject;
23 import com.eviware.soapui.model.testsuite.TestSuite;
24 import com.eviware.soapui.support.UISupport;
25
26 /***
27 * Removes a WsdlProject from the workspace
28 *
29 * @author Ole.Matzura
30 */
31
32 public class RemoveProjectAction extends AbstractAction
33 {
34 private final WsdlProject project;
35
36 public RemoveProjectAction( WsdlProject project)
37 {
38 super( "Remove" );
39 this.project = project;
40 putValue( Action.SHORT_DESCRIPTION, "Removes this project from the workspace" );
41 putValue( Action.ACCELERATOR_KEY, UISupport.getKeyStroke( "DELETE" ));
42 }
43
44 public void actionPerformed(ActionEvent e)
45 {
46 if( hasRunningTests())
47 {
48 UISupport.showErrorMessage( "Cannot remove Interface due to running tests" );
49 return;
50 }
51
52 Boolean retval = UISupport.confirmOrCancel( "Save project [" + project.getName() + "] before removing?", "Remove Project" );
53 if( retval == null )
54 return;
55
56 if( retval.booleanValue() )
57 {
58 try
59 {
60 project.save();
61 }
62 catch( IOException e1 )
63 {
64 UISupport.showErrorMessage( e1 );
65 }
66 }
67
68 project.getWorkspace().removeProject( project );
69 }
70
71 private boolean hasRunningTests()
72 {
73 for( int c = 0; c < project.getTestSuiteCount(); c++ )
74 {
75 TestSuite testSuite = project.getTestSuiteAt( c );
76 for( int i = 0; i < testSuite.getTestCaseCount(); i++ )
77 {
78 if( SoapUI.getTestMonitor().hasRunningTest( testSuite.getTestCaseAt( i )))
79 {
80 return true;
81 }
82 }
83 }
84
85 return false;
86 }
87 }