1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.impl.wsdl.panels.support;
14
15 import java.util.ArrayList;
16 import java.util.List;
17
18 import javax.swing.JComponent;
19
20 import com.eviware.soapui.SoapUI;
21 import com.eviware.soapui.model.testsuite.LoadTestRunner;
22 import com.eviware.soapui.model.testsuite.TestCase;
23 import com.eviware.soapui.model.testsuite.TestCaseRunner;
24 import com.eviware.soapui.monitor.support.TestMonitorListenerAdapter;
25
26 /***
27 * ComponentEnabler for disabling components during TestCase runs
28 *
29 * @author Ole.Matzura
30 */
31
32 public class TestRunComponentEnabler extends TestMonitorListenerAdapter
33 {
34 private final List<JComponent> components = new ArrayList<JComponent>();
35 private final List<Boolean> states = new ArrayList<Boolean>();
36 private final TestCase testCase;
37
38 public TestRunComponentEnabler( TestCase testCase )
39 {
40 this.testCase = testCase;
41
42 SoapUI.getTestMonitor().addTestMonitorListener( this );
43 }
44
45 public void release()
46 {
47 SoapUI.getTestMonitor().removeTestMonitorListener( this );
48 }
49
50 public void loadTestStarted( LoadTestRunner runner )
51 {
52 disable();
53 }
54
55 private void disable()
56 {
57 if( states.isEmpty() )
58 {
59 for( JComponent component : components )
60 {
61 states.add( component.isEnabled() );
62 component.setEnabled( false );
63 }
64 }
65 }
66
67 private void enable()
68 {
69 if( !states.isEmpty() )
70 {
71 for( int c = 0; c < components.size(); c++ )
72 {
73 JComponent component = components.get( c );
74 component.setEnabled( states.get( c ) );
75 }
76
77 states.clear();
78 }
79 }
80
81 public void loadTestFinished( LoadTestRunner runner )
82 {
83 if( !SoapUI.getTestMonitor().hasRunningTest( testCase ) )
84 enable();
85 }
86
87 public void testCaseStarted( TestCaseRunner runner )
88 {
89 disable();
90 }
91
92 public void testCaseFinished( TestCaseRunner runner )
93 {
94 if( !SoapUI.getTestMonitor().hasRunningTest( testCase ) )
95 enable();
96 }
97
98 public void add( JComponent component )
99 {
100 components.add( component );
101
102 if( SoapUI.getTestMonitor().hasRunningTest( testCase ) )
103 {
104 states.add( component.isEnabled() );
105 component.setEnabled( false );
106 }
107 }
108 }