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.model.tree.nodes;
014:
015: import java.util.ArrayList;
016: import java.util.List;
017:
018: import com.eviware.soapui.model.testsuite.LoadTest;
019: import com.eviware.soapui.model.testsuite.TestCase;
020: import com.eviware.soapui.model.testsuite.TestStep;
021: import com.eviware.soapui.model.testsuite.TestSuite;
022: import com.eviware.soapui.model.testsuite.TestSuiteListener;
023: import com.eviware.soapui.model.tree.AbstractModelItemTreeNode;
024: import com.eviware.soapui.model.tree.SoapUITreeModel;
025: import com.eviware.soapui.model.tree.SoapUITreeNode;
026:
027: /**
028: * SoapUITreeNode for TestSuite implementations
029: *
030: * @author Ole.Matzura
031: */
032:
033: public class TestSuiteTreeNode extends
034: AbstractModelItemTreeNode<TestSuite> {
035: private InternalTestSuiteListener internalTestSuiteListener = new InternalTestSuiteListener();;
036: private ReorderPropertyChangeListener propertyChangeListener = new ReorderPropertyChangeListener();
037: private List<TestCaseTreeNode> testCaseNodes = new ArrayList<TestCaseTreeNode>();
038:
039: public TestSuiteTreeNode(TestSuite testSuite,
040: SoapUITreeModel treeModel) {
041: super (testSuite, testSuite.getProject(), treeModel);
042:
043: testSuite.addTestSuiteListener(internalTestSuiteListener);
044:
045: for (int c = 0; c < testSuite.getTestCaseCount(); c++) {
046: TestCase testCase = testSuite.getTestCaseAt(c);
047: testCase.addPropertyChangeListener(TestCase.NAME_PROPERTY,
048: propertyChangeListener);
049: testCaseNodes.add(new TestCaseTreeNode(testCase,
050: getTreeModel()));
051: }
052:
053: getTreeModel().mapModelItems(testCaseNodes);
054: }
055:
056: public void release() {
057: super .release();
058:
059: getTestSuite().removeTestSuiteListener(
060: internalTestSuiteListener);
061:
062: for (TestCaseTreeNode treeNode : testCaseNodes) {
063: treeNode.getModelItem().removePropertyChangeListener(
064: propertyChangeListener);
065: treeNode.release();
066: }
067: }
068:
069: @Override
070: public int getChildCount() {
071: return testCaseNodes.size();
072: }
073:
074: @Override
075: public SoapUITreeNode getChildNode(int index) {
076: return testCaseNodes.get(index);
077: }
078:
079: @Override
080: public int getIndexOfChild(Object child) {
081: return testCaseNodes.indexOf(child);
082: }
083:
084: public TestSuite getTestSuite() {
085: return (TestSuite) getModelItem();
086: }
087:
088: private class InternalTestSuiteListener implements
089: TestSuiteListener {
090: public void testCaseAdded(TestCase testCase) {
091: TestCaseTreeNode testCaseTreeNode = new TestCaseTreeNode(
092: testCase, getTreeModel());
093: testCaseNodes.add(testCase.getTestSuite()
094: .getIndexOfTestCase(testCase), testCaseTreeNode);
095:
096: testCase.addPropertyChangeListener(TestCase.NAME_PROPERTY,
097: propertyChangeListener);
098: getTreeModel().notifyNodeInserted(testCaseTreeNode);
099: }
100:
101: public void testCaseRemoved(TestCase testCase) {
102: SoapUITreeNode treeNode = getTreeModel().getTreeNode(
103: testCase);
104: if (testCaseNodes.contains(treeNode)) {
105: getTreeModel().notifyNodeRemoved(treeNode);
106: testCaseNodes.remove(treeNode);
107: testCase
108: .removePropertyChangeListener(propertyChangeListener);
109: } else
110: throw new RuntimeException("Removing unknown TestCase");
111: }
112:
113: public void testStepAdded(TestStep testStep, int index) {
114: TestCaseTreeNode testCaseTreeNode = (TestCaseTreeNode) getTreeModel()
115: .getTreeNode(testStep.getTestCase());
116: testCaseTreeNode.testStepInserted(testStep, index);
117: }
118:
119: public void testStepRemoved(TestStep testStep, int index) {
120: TestCaseTreeNode testCaseTreeNode = (TestCaseTreeNode) getTreeModel()
121: .getTreeNode(testStep.getTestCase());
122: testCaseTreeNode.testStepRemoved(testStep, index);
123: }
124:
125: public void loadTestAdded(LoadTest loadTest) {
126: TestCaseTreeNode testCaseTreeNode = (TestCaseTreeNode) getTreeModel()
127: .getTreeNode(loadTest.getTestCase());
128: testCaseTreeNode.loadTestInserted(loadTest);
129: }
130:
131: public void loadTestRemoved(LoadTest loadTest) {
132: TestCaseTreeNode testCaseTreeNode = (TestCaseTreeNode) getTreeModel()
133: .getTreeNode(loadTest.getTestCase());
134: testCaseTreeNode.loadTestRemoved(loadTest);
135: }
136:
137: public void testStepMoved(TestStep testStep, int fromIndex,
138: int offset) {
139: TestCaseTreeNode testCaseTreeNode = (TestCaseTreeNode) getTreeModel()
140: .getTreeNode(testStep.getTestCase());
141: testCaseTreeNode.testStepMoved(testStep, fromIndex, offset);
142: }
143:
144: public void testCaseMoved(TestCase testCase, int index,
145: int offset) {
146: testCaseRemoved(testCase);
147: testCaseAdded(testCase);
148: }
149: }
150: }
|