1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.model.tree;
14
15 import java.util.Enumeration;
16 import java.util.Vector;
17
18 import javax.swing.JPopupMenu;
19 import javax.swing.tree.TreeNode;
20
21 import com.eviware.soapui.model.ModelItem;
22 import com.eviware.soapui.support.action.swing.ActionList;
23 import com.eviware.soapui.support.action.swing.ActionListBuilder;
24 import com.eviware.soapui.support.action.swing.ActionSupport;
25
26 /***
27 * Base implementation of SoapUITreeNode interface
28 *
29 * @author Ole.Matzura
30 */
31
32 public abstract class AbstractTreeNode<T extends ModelItem> implements SoapUITreeNode
33 {
34 private T modelItem;
35
36 public AbstractTreeNode( T modelItem )
37 {
38 this.modelItem = modelItem;
39 }
40
41 public boolean valueChanged( Object newValue )
42 {
43 return false;
44 }
45
46 public boolean isLeaf()
47 {
48 return getChildCount() == 0;
49 }
50
51 public JPopupMenu getPopup()
52 {
53 return ActionSupport.buildPopup( getActions() );
54 }
55
56 public ActionList getActions()
57 {
58 return ActionListBuilder.buildActions( modelItem );
59 }
60
61 public T getModelItem()
62 {
63 return modelItem;
64 }
65
66 public String toString()
67 {
68 return modelItem.getName();
69 }
70
71 public void reorder( boolean notify )
72 {
73 }
74
75 public Enumeration children()
76 {
77 Vector<TreeNode> children = new Vector<TreeNode>();
78 for( int c = 0; c < getChildCount(); c++ )
79 children.add( getChildAt( c ) );
80
81 return children.elements();
82 }
83
84 public boolean getAllowsChildren()
85 {
86 return !isLeaf();
87 }
88
89 public TreeNode getChildAt( int childIndex )
90 {
91 return getChildNode( childIndex );
92 }
93
94 public int getIndex( TreeNode node )
95 {
96 return getIndexOfChild( node );
97 }
98
99 public TreeNode getParent()
100 {
101 return getParentTreeNode();
102 }
103
104 }