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.model.tree.nodes;
14:
15: import java.util.ArrayList;
16: import java.util.List;
17:
18: import com.eviware.soapui.model.iface.Operation;
19: import com.eviware.soapui.model.iface.Request;
20: import com.eviware.soapui.model.tree.AbstractModelItemTreeNode;
21: import com.eviware.soapui.model.tree.SoapUITreeModel;
22: import com.eviware.soapui.model.tree.SoapUITreeNode;
23: import com.eviware.soapui.settings.UISettings;
24:
25: /**
26: * SoapUITreeNode for Operation implementations
27: *
28: * @author Ole.Matzura
29: */
30:
31: public class OperationTreeNode extends
32: AbstractModelItemTreeNode<Operation> {
33: private List<RequestTreeNode> requestNodes = new ArrayList<RequestTreeNode>();
34: private ReorderPropertyChangeListener propertyChangeListener = new ReorderPropertyChangeListener();
35:
36: public OperationTreeNode(Operation operation,
37: SoapUITreeModel treeModel) {
38: super (operation, operation.getInterface(), treeModel);
39:
40: for (int c = 0; c < operation.getRequestCount(); c++) {
41: Request request = operation.getRequestAt(c);
42: request.addPropertyChangeListener(Request.NAME_PROPERTY,
43: propertyChangeListener);
44: requestNodes.add(new RequestTreeNode(request,
45: getTreeModel()));
46: }
47:
48: initOrdering(requestNodes, UISettings.ORDER_REQUESTS);
49: treeModel.mapModelItems(requestNodes);
50: }
51:
52: public void release() {
53: super .release();
54:
55: for (RequestTreeNode treeNode : requestNodes) {
56: treeNode.getModelItem().removePropertyChangeListener(
57: propertyChangeListener);
58: treeNode.release();
59: }
60: }
61:
62: public Operation getOperation() {
63: return (Operation) getModelItem();
64: }
65:
66: public void requestAdded(Request request) {
67: RequestTreeNode requestTreeNode = new RequestTreeNode(request,
68: getTreeModel());
69: requestNodes.add(requestTreeNode);
70: reorder(false);
71: request.addPropertyChangeListener(Request.NAME_PROPERTY,
72: propertyChangeListener);
73: getTreeModel().notifyNodeInserted(requestTreeNode);
74: }
75:
76: public void requestRemoved(Request request) {
77: SoapUITreeNode requestTreeNode = getTreeModel().getTreeNode(
78: request);
79: if (requestNodes.contains(requestTreeNode)) {
80: getTreeModel().notifyNodeRemoved(requestTreeNode);
81: requestNodes.remove(requestTreeNode);
82: request
83: .removePropertyChangeListener(propertyChangeListener);
84: } else
85: throw new RuntimeException("Removing unkown request");
86: }
87: }
|