001: /*
002: * soapUI, copyright (C) 2004-2007 eviware.com
003: *
004: * soapUI is free software; you can redistribute it and/or modify it under the
005: * terms of version 2.1 of the GNU Lesser General Public License as published by
006: * the Free Software Foundation.
007: *
008: * soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
009: * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
010: * See the GNU Lesser General Public License for more details at gnu.org.
011: */
012:
013: package com.eviware.soapui.impl.wsdl.panels.teststeps.support;
014:
015: import java.beans.PropertyChangeEvent;
016: import java.beans.PropertyChangeListener;
017:
018: import javax.swing.AbstractListModel;
019: import javax.swing.ComboBoxModel;
020:
021: import com.eviware.soapui.impl.wsdl.teststeps.WsdlGotoTestStep.GotoCondition;
022: import com.eviware.soapui.model.support.TestSuiteListenerAdapter;
023: import com.eviware.soapui.model.testsuite.TestCase;
024: import com.eviware.soapui.model.testsuite.TestStep;
025:
026: /**
027: * ComboBox-model used by combo in the WsdlGotoTestStep desktop panel for selecting a conditions
028: * target teststep
029: *
030: * @author Ole.Matzura
031: */
032:
033: public class GotoTestStepsComboBoxModel extends AbstractListModel
034: implements ComboBoxModel {
035: private final TestCase testCase;
036: private GotoCondition condition;
037: private InternalTestSuiteListener testSuiteListener = new InternalTestSuiteListener();;
038: private InternalPropertyChangeListener propertyChangeListener = new InternalPropertyChangeListener();
039:
040: public GotoTestStepsComboBoxModel(TestCase testCase,
041: GotoCondition condition) {
042: super ();
043: this .testCase = testCase;
044: this .condition = condition;
045:
046: testCase.getTestSuite().addTestSuiteListener(testSuiteListener);
047:
048: if (condition != null)
049: condition.addPropertyChangeListener(
050: GotoCondition.TARGET_STEP_PROPERTY,
051: propertyChangeListener);
052:
053: for (int c = 0; c < testCase.getTestStepCount(); c++) {
054: testCase.getTestStepAt(c).addPropertyChangeListener(
055: TestStep.NAME_PROPERTY, propertyChangeListener);
056: }
057: }
058:
059: public GotoCondition getCondition() {
060: return condition;
061: }
062:
063: public void setCondition(GotoCondition condition) {
064: if (this .condition != null)
065: this .condition.removePropertyChangeListener(
066: GotoCondition.TARGET_STEP_PROPERTY,
067: propertyChangeListener);
068:
069: this .condition = condition;
070:
071: if (condition != null)
072: condition.addPropertyChangeListener(
073: GotoCondition.TARGET_STEP_PROPERTY,
074: propertyChangeListener);
075:
076: fireContentsChanged(this , 0, getSize());
077: }
078:
079: public void setSelectedItem(Object anItem) {
080: if (condition != null)
081: condition.setTargetStep(anItem == null ? null : anItem
082: .toString());
083: }
084:
085: public Object getSelectedItem() {
086: return condition == null ? null : condition.getTargetStep();
087: }
088:
089: public int getSize() {
090: return testCase.getTestStepCount();
091: }
092:
093: public Object getElementAt(int index) {
094: return testCase.getTestStepAt(index).getName();
095: }
096:
097: private class InternalTestSuiteListener extends
098: TestSuiteListenerAdapter {
099: public void testStepAdded(TestStep testStep, int index) {
100: if (testStep.getTestCase() == testCase) {
101: fireContentsChanged(GotoTestStepsComboBoxModel.this , 0,
102: getSize());
103: }
104: }
105:
106: public void testStepRemoved(TestStep testStep, int index) {
107: if (testStep.getTestCase() == testCase) {
108: fireContentsChanged(GotoTestStepsComboBoxModel.this , 0,
109: getSize());
110: }
111: }
112: }
113:
114: private class InternalPropertyChangeListener implements
115: PropertyChangeListener {
116: public void propertyChange(PropertyChangeEvent evt) {
117: fireContentsChanged(GotoTestStepsComboBoxModel.this , 0,
118: getSize());
119: }
120: }
121: }
|