01: /*
02: * soapUI, copyright (C) 2004-2007 eviware.com
03: *
04: * soapUI is free software; you can redistribute it and/or modify it under the
05: * terms of version 2.1 of the GNU Lesser General Public License as published by
06: * the Free Software Foundation.
07: *
08: * soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
09: * 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.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.TestRunner;
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: private final List<JComponent> components = new ArrayList<JComponent>();
34: private final List<Boolean> states = new ArrayList<Boolean>();
35: private final TestCase testCase;
36:
37: public TestRunComponentEnabler(TestCase testCase) {
38: this .testCase = testCase;
39:
40: SoapUI.getTestMonitor().addTestMonitorListener(this );
41: }
42:
43: public void release() {
44: SoapUI.getTestMonitor().removeTestMonitorListener(this );
45: }
46:
47: public void loadTestStarted(LoadTestRunner runner) {
48: disable();
49: }
50:
51: private void disable() {
52: if (states.isEmpty()) {
53: for (JComponent component : components) {
54: states.add(component.isEnabled());
55: component.setEnabled(false);
56: }
57: }
58: }
59:
60: private void enable() {
61: if (!states.isEmpty()) {
62: for (int c = 0; c < components.size(); c++) {
63: JComponent component = components.get(c);
64: component.setEnabled(states.get(c));
65: }
66:
67: states.clear();
68: }
69: }
70:
71: public void loadTestFinished(LoadTestRunner runner) {
72: if (!SoapUI.getTestMonitor().hasRunningTest(testCase))
73: enable();
74: }
75:
76: public void testCaseStarted(TestRunner runner) {
77: disable();
78: }
79:
80: public void testCaseFinished(TestRunner runner) {
81: if (!SoapUI.getTestMonitor().hasRunningTest(testCase))
82: enable();
83: }
84:
85: public void add(JComponent component) {
86: components.add(component);
87:
88: if (SoapUI.getTestMonitor().hasRunningTest(testCase)) {
89: states.add(component.isEnabled());
90: component.setEnabled(false);
91: }
92: }
93: }
|