1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.impl.wsdl.actions.iface;
14
15 import java.awt.event.ActionEvent;
16
17 import javax.swing.AbstractAction;
18 import javax.swing.Action;
19
20 import com.eviware.soapui.SoapUI;
21 import com.eviware.soapui.impl.wsdl.WsdlInterface;
22 import com.eviware.soapui.impl.wsdl.WsdlProject;
23 import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestStep;
24 import com.eviware.soapui.model.testsuite.TestCase;
25 import com.eviware.soapui.model.testsuite.TestSuite;
26 import com.eviware.soapui.support.UISupport;
27
28 /***
29 * Removes a WsdlInterface from a WsdlProject
30 *
31 * @author Ole.Matzura
32 */
33
34 public class RemoveInterfaceAction extends AbstractAction
35 {
36 private final WsdlInterface iface;
37
38 public RemoveInterfaceAction( WsdlInterface iface )
39 {
40 super( "Remove" );
41 this.iface = iface;
42 putValue( Action.SHORT_DESCRIPTION, "Removes this interface from the project" );
43 putValue( Action.ACCELERATOR_KEY, UISupport.getKeyStroke( "DELETE" ));
44 }
45
46 public void actionPerformed(ActionEvent e)
47 {
48 if( hasDependingTests( iface ) )
49 {
50 UISupport.showErrorMessage( "Cannot remove Interface due to running depending tests" );
51 return;
52 }
53
54 if( UISupport.confirm( "Remove interface [" + iface.getName() + "] from project [" +
55 iface.getProject().getName() + "]?", "Remove Interface" ))
56 {
57 WsdlProject project = (WsdlProject) iface.getProject();
58 project.removeInterface( iface);
59 }
60 }
61
62 static boolean hasDependingTests( WsdlInterface iface )
63 {
64 if( SoapUI.getTestMonitor() == null )
65 return false;
66
67 for( int c = 0; c < iface.getProject().getTestSuiteCount(); c++ )
68 {
69 TestSuite testSuite = iface.getProject().getTestSuiteAt( c );
70 for( int i = 0; i < testSuite.getTestCaseCount(); i++ )
71 {
72 TestCase testCase = testSuite.getTestCaseAt( i );
73 if( !SoapUI.getTestMonitor().hasRunningTest( testCase ))
74 continue;
75
76 for( int j = 0; j < testCase.getTestStepCount(); j++ )
77 {
78 WsdlTestStep testStep = (WsdlTestStep) testCase.getTestStepAt( j );
79 if( testStep.dependsOn( iface ))
80 {
81 return true;
82 }
83 }
84 }
85 }
86
87 return false;
88 }
89 }