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.tree.AbstractModelItemTreeNode;
022: import com.eviware.soapui.model.tree.AbstractTreeNode;
023: import com.eviware.soapui.model.tree.SoapUITreeModel;
024: import com.eviware.soapui.model.tree.SoapUITreeNode;
025: import com.eviware.soapui.model.tree.nodes.support.WsdlLoadTestsModelItem;
026: import com.eviware.soapui.model.tree.nodes.support.WsdlTestStepsModelItem;
027: import com.eviware.soapui.support.action.swing.ActionList;
028: import com.eviware.soapui.support.action.swing.ActionListBuilder;
029:
030: /**
031: * SoapUITreeNode for TestCase implementations
032: *
033: * @author Ole.Matzura
034: */
035:
036: public class TestCaseTreeNode extends
037: AbstractModelItemTreeNode<TestCase> {
038: private TestStepsTreeNode testStepsNode;
039: private LoadTestsTreeNode loadTestsNode;
040:
041: public TestCaseTreeNode(TestCase testCase, SoapUITreeModel treeModel) {
042: super (testCase, testCase.getTestSuite(), treeModel);
043:
044: testStepsNode = new TestStepsTreeNode();
045: loadTestsNode = new LoadTestsTreeNode();
046:
047: getTreeModel().mapModelItem(testStepsNode);
048: getTreeModel().mapModelItem(loadTestsNode);
049: }
050:
051: public void release() {
052: super .release();
053:
054: getTreeModel().unmapModelItem(testStepsNode.getModelItem());
055: getTreeModel().unmapModelItem(loadTestsNode.getModelItem());
056:
057: testStepsNode.release();
058: loadTestsNode.release();
059: }
060:
061: public int getChildCount() {
062: return 2;
063: }
064:
065: public SoapUITreeNode getChildNode(int index) {
066: if (index == 0)
067: return testStepsNode;
068:
069: if (index == 1)
070: return loadTestsNode;
071:
072: return null;
073: }
074:
075: public int getIndexOfChild(Object child) {
076: if (child == testStepsNode)
077: return 0;
078: if (child == loadTestsNode)
079: return 1;
080:
081: return -1;
082: }
083:
084: public LoadTestsTreeNode getLoadTestsNode() {
085: return loadTestsNode;
086: }
087:
088: public TestStepsTreeNode getTestStepsNode() {
089: return testStepsNode;
090: }
091:
092: public TestCase getTestCase() {
093: return getModelItem();
094: }
095:
096: public class TestStepsTreeNode extends
097: AbstractTreeNode<WsdlTestStepsModelItem> {
098: private List<TestStepTreeNode> testStepNodes = new ArrayList<TestStepTreeNode>();
099:
100: protected TestStepsTreeNode() {
101: super (new WsdlTestStepsModelItem(getTestCase()));
102:
103: for (int c = 0; c < getTestCase().getTestStepCount(); c++) {
104: testStepNodes.add(new TestStepTreeNode(getTestCase()
105: .getTestStepAt(c), getModelItem(),
106: getTreeModel()));
107: }
108:
109: getTreeModel().mapModelItems(testStepNodes);
110: }
111:
112: public int getChildCount() {
113: return testStepNodes.size();
114: }
115:
116: public int getIndexOfChild(Object child) {
117: return testStepNodes.indexOf(child);
118: }
119:
120: public SoapUITreeNode getChildNode(int index) {
121: return testStepNodes.get(index);
122: }
123:
124: public SoapUITreeNode getParentTreeNode() {
125: return TestCaseTreeNode.this ;
126: }
127:
128: public void testStepInserted(TestStep testStep, int index) {
129: TestStepTreeNode testStepTreeNode = new TestStepTreeNode(
130: testStep, getModelItem(), getTreeModel());
131: testStepNodes.add(index, testStepTreeNode);
132: getTreeModel().notifyNodeInserted(testStepTreeNode);
133: getTreeModel().notifyNodeChanged(this );
134: }
135:
136: public void testStepRemoved(TestStep testStep, int index) {
137: SoapUITreeNode treeNode = getTreeModel().getTreeNode(
138: testStep);
139: if (testStepNodes.contains(treeNode)) {
140: getTreeModel().notifyNodeRemoved(treeNode);
141: testStepNodes.remove(treeNode);
142: } else
143: throw new RuntimeException("Removing unkown testStep");
144: }
145:
146: public void testStepMoved(TestStep testStep, int fromIndex,
147: int offset) {
148: testStepRemoved(testStep, fromIndex);
149: testStepInserted(testStep, fromIndex + offset);
150: }
151:
152: public ActionList getActions() {
153: return ActionListBuilder.buildActions(
154: "TestStepsTreeNodeActions", TestCaseTreeNode.this
155: .getModelItem());
156: }
157:
158: public void release() {
159: for (TestStepTreeNode testStepNode : testStepNodes)
160: testStepNode.release();
161:
162: getModelItem().release();
163: }
164: }
165:
166: public class LoadTestsTreeNode extends
167: AbstractTreeNode<WsdlLoadTestsModelItem> {
168: private List<LoadTestTreeNode> loadTestNodes = new ArrayList<LoadTestTreeNode>();
169:
170: protected LoadTestsTreeNode() {
171: super (new WsdlLoadTestsModelItem(getTestCase()));
172:
173: for (int c = 0; c < getTestCase().getLoadTestCount(); c++) {
174: loadTestNodes.add(new LoadTestTreeNode(getTestCase()
175: .getLoadTestAt(c), getModelItem(),
176: getTreeModel()));
177: }
178:
179: getTreeModel().mapModelItems(loadTestNodes);
180: }
181:
182: public int getChildCount() {
183: return loadTestNodes.size();
184: }
185:
186: public int getIndexOfChild(Object child) {
187: return loadTestNodes.indexOf(child);
188: }
189:
190: public SoapUITreeNode getChildNode(int index) {
191: return loadTestNodes.get(index);
192: }
193:
194: public SoapUITreeNode getParentTreeNode() {
195: return TestCaseTreeNode.this ;
196: }
197:
198: public void loadTestInserted(LoadTest loadTest) {
199: LoadTestTreeNode loadTestTreeNode = new LoadTestTreeNode(
200: loadTest, getModelItem(), getTreeModel());
201: loadTestNodes.add(loadTestTreeNode);
202: getTreeModel().notifyNodeInserted(loadTestTreeNode);
203: getTreeModel().notifyNodeChanged(this );
204: }
205:
206: public void loadTestRemoved(LoadTest loadTest) {
207: SoapUITreeNode treeNode = getTreeModel().getTreeNode(
208: loadTest);
209: if (loadTestNodes.contains(treeNode)) {
210: getTreeModel().notifyNodeRemoved(treeNode);
211: loadTestNodes.remove(treeNode);
212: } else
213: throw new RuntimeException("Removing unkown loadTest");
214: }
215:
216: public void release() {
217: for (LoadTestTreeNode loadTestNode : loadTestNodes)
218: loadTestNode.release();
219: }
220:
221: public ActionList getActions() {
222: return ActionListBuilder.buildActions(
223: "LoadTestsTreeNodeActions", TestCaseTreeNode.this
224: .getModelItem());
225: }
226: }
227:
228: public void testStepInserted(TestStep testStep, int index) {
229: testStepsNode.testStepInserted(testStep, index);
230: }
231:
232: public void testStepRemoved(TestStep testStep, int index) {
233: testStepsNode.testStepRemoved(testStep, index);
234: }
235:
236: public void loadTestInserted(LoadTest loadTest) {
237: loadTestsNode.loadTestInserted(loadTest);
238: }
239:
240: public void loadTestRemoved(LoadTest loadTest) {
241: loadTestsNode.loadTestRemoved(loadTest);
242: }
243:
244: public void testStepMoved(TestStep testStep, int fromIndex,
245: int offset) {
246: testStepsNode.testStepMoved(testStep, fromIndex, offset);
247: }
248: }
|