View Javadoc

    1   /*
    2    *  soapUI, copyright (C) 2004-2007 eviware.com
    3    *
    4    *  soapUI is free software; you can redistribute it and/or modify it under the
    5    *  terms of version 2.1 of the GNU Lesser General Public License as published by
    6    *  the Free Software Foundation.
    7    *
    8    *  soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
    9    *  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.Interface;
    19  import com.eviware.soapui.model.iface.InterfaceListener;
    20  import com.eviware.soapui.model.iface.Operation;
    21  import com.eviware.soapui.model.iface.Request;
    22  import com.eviware.soapui.model.tree.AbstractModelItemTreeNode;
    23  import com.eviware.soapui.model.tree.SoapUITreeModel;
    24  import com.eviware.soapui.model.tree.SoapUITreeNode;
    25
    26  /***
    27   * SoapUITreeNode for Interface implementations
    28   *
    29   * @author Ole.Matzura
    30   */
    31
    32  public class InterfaceTreeNode extends AbstractModelItemTreeNode<Interface>
    33  {
    34  	private InternalInterfaceListener interfaceListener;
    35  	private List<OperationTreeNode> operationNodes = new ArrayList<OperationTreeNode>();
    36
    37     public InterfaceTreeNode( Interface iface, SoapUITreeModel treeModel )
    38     {
    39        super( iface, iface.getProject(), treeModel );
    40
    41        interfaceListener = new InternalInterfaceListener();
    42  		iface.addInterfaceListener( interfaceListener);
    43
    44  		for( int c = 0; c < iface.getOperationCount(); c++ )
    45  		{
    46  			operationNodes.add( new OperationTreeNode( iface.getOperationAt( c ), getTreeModel() ));
    47  		}
    48
    49  		treeModel.mapModelItems( operationNodes );
    50     }
    51
    52     public void release()
    53     {
    54     	super.release();
    55
    56     	getInterface().removeInterfaceListener( interfaceListener );
    57
    58     	for( OperationTreeNode treeNode : operationNodes )
    59     		treeNode.release();
    60     }
    61
    62     public Interface getInterface()
    63  	{
    64  		return (Interface) getModelItem();
    65  	}
    66
    67  	public int getChildCount()
    68     {
    69        return operationNodes.size();
    70     }
    71
    72     public int getIndexOfChild(Object child)
    73     {
    74     	return operationNodes.indexOf( child );
    75     }
    76
    77     public SoapUITreeNode getChildNode(int index)
    78     {
    79        return operationNodes.get( index );
    80     }
    81
    82     private class InternalInterfaceListener implements InterfaceListener
    83     {
    84        public void requestAdded(Request request)
    85        {
    86           OperationTreeNode operationTreeNode = (OperationTreeNode) getTreeModel().getTreeNode( request.getOperation() );
    87           if( operationTreeNode != null )
    88           	operationTreeNode.requestAdded( request );
    89        }
    90
    91        public void requestRemoved(Request request)
    92        {
    93           OperationTreeNode operationTreeNode = (OperationTreeNode) getTreeModel().getTreeNode( request.getOperation() );
    94           if( operationTreeNode != null )
    95           	operationTreeNode.requestRemoved( request );
    96        }
    97
    98        public void operationAdded(Operation operation)
    99        {
    100       	OperationTreeNode operationTreeNode = new OperationTreeNode( operation, getTreeModel() );
    101       	operationNodes.add( operationTreeNode );
    102          getTreeModel().notifyNodeInserted( operationTreeNode );
    103       }
    104
    105       public void operationRemoved(Operation operation)
    106       {
    107       	SoapUITreeNode treeNode = getTreeModel().getTreeNode( operation );
    108 			if( operationNodes.contains( treeNode))
    109       	{
    110       		getTreeModel().notifyNodeRemoved( treeNode );
    111       		operationNodes.remove( treeNode );
    112       	}
    113 			else throw new RuntimeException( "Removing unkown operation" );
    114       }
    115
    116 		public void operationUpdated( Operation operation )
    117 		{
    118 		}
    119    }
    120 }