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.iface.Interface;
019: import com.eviware.soapui.model.iface.InterfaceListener;
020: import com.eviware.soapui.model.iface.Operation;
021: import com.eviware.soapui.model.iface.Request;
022: import com.eviware.soapui.model.tree.AbstractModelItemTreeNode;
023: import com.eviware.soapui.model.tree.SoapUITreeModel;
024: import com.eviware.soapui.model.tree.SoapUITreeNode;
025:
026: /**
027: * SoapUITreeNode for Interface implementations
028: *
029: * @author Ole.Matzura
030: */
031:
032: public class InterfaceTreeNode extends
033: AbstractModelItemTreeNode<Interface> {
034: private InternalInterfaceListener interfaceListener;
035: private List<OperationTreeNode> operationNodes = new ArrayList<OperationTreeNode>();
036:
037: public InterfaceTreeNode(Interface iface, SoapUITreeModel treeModel) {
038: super (iface, iface.getProject(), treeModel);
039:
040: interfaceListener = new InternalInterfaceListener();
041: iface.addInterfaceListener(interfaceListener);
042:
043: for (int c = 0; c < iface.getOperationCount(); c++) {
044: operationNodes.add(new OperationTreeNode(iface
045: .getOperationAt(c), getTreeModel()));
046: }
047:
048: treeModel.mapModelItems(operationNodes);
049: }
050:
051: public void release() {
052: super .release();
053:
054: getInterface().removeInterfaceListener(interfaceListener);
055:
056: for (OperationTreeNode treeNode : operationNodes)
057: treeNode.release();
058: }
059:
060: public Interface getInterface() {
061: return (Interface) getModelItem();
062: }
063:
064: public int getChildCount() {
065: return operationNodes.size();
066: }
067:
068: public int getIndexOfChild(Object child) {
069: return operationNodes.indexOf(child);
070: }
071:
072: public SoapUITreeNode getChildNode(int index) {
073: return operationNodes.get(index);
074: }
075:
076: private class InternalInterfaceListener implements
077: InterfaceListener {
078: public void requestAdded(Request request) {
079: OperationTreeNode operationTreeNode = (OperationTreeNode) getTreeModel()
080: .getTreeNode(request.getOperation());
081: if (operationTreeNode != null)
082: operationTreeNode.requestAdded(request);
083: }
084:
085: public void requestRemoved(Request request) {
086: OperationTreeNode operationTreeNode = (OperationTreeNode) getTreeModel()
087: .getTreeNode(request.getOperation());
088: if (operationTreeNode != null)
089: operationTreeNode.requestRemoved(request);
090: }
091:
092: public void operationAdded(Operation operation) {
093: OperationTreeNode operationTreeNode = new OperationTreeNode(
094: operation, getTreeModel());
095: operationNodes.add(operationTreeNode);
096: getTreeModel().notifyNodeInserted(operationTreeNode);
097: }
098:
099: public void operationRemoved(Operation operation) {
100: SoapUITreeNode treeNode = getTreeModel().getTreeNode(
101: operation);
102: if (operationNodes.contains(treeNode)) {
103: getTreeModel().notifyNodeRemoved(treeNode);
104: operationNodes.remove(treeNode);
105: } else
106: throw new RuntimeException("Removing unkown operation");
107: }
108:
109: public void operationUpdated(Operation operation) {
110: }
111: }
112: }
|