1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.impl.wsdl.panels.teststeps.support;
14
15 import java.beans.PropertyChangeEvent;
16 import java.beans.PropertyChangeListener;
17
18 import javax.swing.AbstractListModel;
19 import javax.swing.ComboBoxModel;
20
21 import com.eviware.soapui.impl.wsdl.teststeps.WsdlGotoTestStep.GotoCondition;
22 import com.eviware.soapui.model.support.TestSuiteListenerAdapter;
23 import com.eviware.soapui.model.testsuite.TestCase;
24 import com.eviware.soapui.model.testsuite.TestStep;
25
26 /***
27 * ComboBox-model used by combo in the WsdlGotoTestStep desktop panel for selecting a conditions
28 * target teststep
29 *
30 * @author Ole.Matzura
31 */
32
33 public class GotoTestStepsComboBoxModel extends AbstractListModel implements
34 ComboBoxModel
35 {
36 private final TestCase testCase;
37 private GotoCondition condition;
38 private InternalTestSuiteListener testSuiteListener = new InternalTestSuiteListener();;
39 private InternalPropertyChangeListener propertyChangeListener = new InternalPropertyChangeListener();
40
41 public GotoTestStepsComboBoxModel( TestCase testCase, GotoCondition condition )
42 {
43 super();
44 this.testCase = testCase;
45 this.condition = condition;
46
47 testCase.getTestSuite().addTestSuiteListener( testSuiteListener );
48
49 if( condition != null )
50 condition.addPropertyChangeListener( GotoCondition.TARGET_STEP_PROPERTY, propertyChangeListener );
51
52 for( int c = 0; c < testCase.getTestStepCount(); c++ )
53 {
54 testCase.getTestStepAt( c ).addPropertyChangeListener( TestStep.NAME_PROPERTY, propertyChangeListener );
55 }
56 }
57
58 public GotoCondition getCondition()
59 {
60 return condition;
61 }
62
63 public void setCondition(GotoCondition condition)
64 {
65 if( this.condition != null )
66 this.condition.removePropertyChangeListener( GotoCondition.TARGET_STEP_PROPERTY, propertyChangeListener );
67
68 this.condition = condition;
69
70 if( condition != null )
71 condition.addPropertyChangeListener( GotoCondition.TARGET_STEP_PROPERTY, propertyChangeListener );
72
73 fireContentsChanged( this, 0, getSize() );
74 }
75
76 public void setSelectedItem(Object anItem)
77 {
78 if( condition != null )
79 condition.setTargetStep( anItem == null ? null : anItem.toString() );
80 }
81
82 public Object getSelectedItem()
83 {
84 return condition == null ? null : condition.getTargetStep();
85 }
86
87 public int getSize()
88 {
89 return testCase.getTestStepCount();
90 }
91
92 public Object getElementAt(int index)
93 {
94 return testCase.getTestStepAt( index ).getName();
95 }
96
97 private class InternalTestSuiteListener extends TestSuiteListenerAdapter
98 {
99 public void testStepAdded(TestStep testStep, int index)
100 {
101 if( testStep.getTestCase() == testCase )
102 {
103 fireContentsChanged( GotoTestStepsComboBoxModel.this, 0, getSize() );
104 }
105 }
106
107 public void testStepRemoved(TestStep testStep, int index)
108 {
109 if( testStep.getTestCase() == testCase )
110 {
111 fireContentsChanged( GotoTestStepsComboBoxModel.this, 0, getSize() );
112 }
113 }
114 }
115
116 private class InternalPropertyChangeListener implements PropertyChangeListener
117 {
118 public void propertyChange(PropertyChangeEvent evt)
119 {
120 fireContentsChanged( GotoTestStepsComboBoxModel.this, 0, getSize() );
121 }
122 }
123
124 public void release()
125 {
126 testCase.getTestSuite().removeTestSuiteListener( testSuiteListener );
127
128 if( condition != null )
129 condition.removePropertyChangeListener( GotoCondition.TARGET_STEP_PROPERTY, propertyChangeListener );
130
131 for( int c = 0; c < testCase.getTestStepCount(); c++ )
132 {
133 testCase.getTestStepAt( c ).removePropertyChangeListener( TestStep.NAME_PROPERTY, propertyChangeListener );
134 }
135 }
136 }