View Javadoc

1   /*
2    *  soapui, copyright (C) 2005 Ole Matzura / eviware.com 
3    *
4    *  SoapUI is free software; you can redistribute it and/or modify it under the 
5    *  terms of the GNU Lesser General Public License as published by the Free Software Foundation; 
6    *  either version 2.1 of the License, or (at your option) any later version.
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 com.eviware.soapui.model.iface.Interface;
16  import com.eviware.soapui.model.iface.InterfaceListener;
17  import com.eviware.soapui.model.iface.Operation;
18  import com.eviware.soapui.model.iface.Request;
19  import com.eviware.soapui.model.tree.AbstractTreeNode;
20  import com.eviware.soapui.model.tree.SoapUITreeNode;
21  
22  /***
23   * SoapUITreeNode for Interface implementations
24   * 
25   * @author Ole.Matzura
26   */
27  
28  public class InterfaceTreeNode extends AbstractTreeNode
29  {
30     private final Interface iface;
31  	private InternalInterfaceListener internalInterfaceListener;
32  
33     public InterfaceTreeNode( Interface iface )
34     {
35        super( iface, iface.getProject() );
36        this.iface = iface;
37        
38        internalInterfaceListener = new InternalInterfaceListener();
39  		iface.addInterfaceListener( internalInterfaceListener);
40     }
41    
42     public void release()
43     {
44     	super.release();
45     	
46     	iface.removeInterfaceListener( internalInterfaceListener );
47     }
48     
49     public int getChildCount()
50     {
51        return iface.getOperationCount();
52     }
53  
54     public int getIndexOfChild(Object child)
55     {
56        for( int c = 0; c < iface.getOperationCount(); c++ )
57        {
58           if( iface.getOperationAt( c ).getTreeNode() == child ) return c;
59        }
60        
61        return -1;
62     }
63  
64     public SoapUITreeNode getChildNode(int index)
65     {
66        return iface.getOperationAt(index).getTreeNode();
67     }
68     
69     private class InternalInterfaceListener extends InternalTreeNodeListener implements InterfaceListener
70     {
71     	public InternalInterfaceListener()
72     	{
73     		super( getTreeModel() );
74     	}
75  
76        public void requestAdded(Request request)
77        {
78           notifyNodeInserted( request );
79        }
80  
81        public void requestRemoved(Request request)
82        {
83           notifyNodeRemoved( request );
84        }
85  
86        public void operationAdded(Operation operation)
87        {
88           notifyNodeInserted( operation );
89        }
90           
91        public void operationRemoved(Operation operation)
92        {
93           notifyNodeRemoved( operation );
94        }
95     }
96  }