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.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 AbstractModelItemTreeNode<Operation>
    32  {
    33  	private List<RequestTreeNode> requestNodes = new ArrayList<RequestTreeNode>();
    34  	private ReorderPropertyChangeListener propertyChangeListener = new ReorderPropertyChangeListener();
    35
    36  	public OperationTreeNode(Operation operation, SoapUITreeModel treeModel )
    37     {
    38        super( operation, operation.getInterface(), treeModel );
    39
    40        for( int c = 0; c < operation.getRequestCount(); c++ )
    41        {
    42        	Request request = operation.getRequestAt( c );
    43        	request.addPropertyChangeListener( Request.NAME_PROPERTY, propertyChangeListener );
    44  			requestNodes.add( new RequestTreeNode( request, getTreeModel() ));
    45        }
    46
    47        initOrdering( requestNodes, UISettings.ORDER_REQUESTS );
    48        treeModel.mapModelItems( requestNodes );
    49     }
    50
    51     public void release()
    52  	{
    53  		super.release();
    54
    55  		for( RequestTreeNode treeNode : requestNodes )
    56  		{
    57  			treeNode.getModelItem().removePropertyChangeListener( propertyChangeListener );
    58  			treeNode.release();
    59  		}
    60  	}
    61
    62  	public Operation getOperation()
    63     {
    64     	return (Operation) getModelItem();
    65     }
    66
    67  	public void requestAdded(Request request)
    68  	{
    69  		RequestTreeNode requestTreeNode = new RequestTreeNode( request, getTreeModel() );
    70  		requestNodes.add( requestTreeNode );
    71  		reorder(false);
    72  		request.addPropertyChangeListener( Request.NAME_PROPERTY, propertyChangeListener );
    73  		getTreeModel().notifyNodeInserted( requestTreeNode );
    74  	}
    75
    76  	public void requestRemoved(Request request)
    77  	{
    78  		SoapUITreeNode requestTreeNode = getTreeModel().getTreeNode( request );
    79  		if( requestNodes.contains( requestTreeNode ))
    80  		{
    81  		   getTreeModel().notifyNodeRemoved( requestTreeNode );
    82  		   requestNodes.remove( requestTreeNode );
    83  		   request.removePropertyChangeListener( propertyChangeListener );
    84  		}
    85  		else throw new RuntimeException( "Removing unkown request" );
    86  	}
    87  }