1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.model.tree;
14
15 import java.awt.Component;
16 import java.beans.PropertyChangeEvent;
17 import java.beans.PropertyChangeListener;
18
19 import javax.swing.Action;
20 import javax.swing.JPopupMenu;
21
22 import com.eviware.soapui.SoapUI;
23 import com.eviware.soapui.model.DesktopPanel;
24 import com.eviware.soapui.model.ModelItem;
25 import com.eviware.soapui.model.PanelBuilder;
26 import com.eviware.soapui.model.testsuite.TestCase;
27
28 /***
29 * Abstract base class for SoapUITreeNode implementations
30 *
31 * @author Ole.Matzura
32 */
33
34 public abstract class AbstractTreeNode implements SoapUITreeNode, PropertyChangeListener
35 {
36 private final ModelItem modelItem;
37 private JPopupMenu popup;
38 private PanelBuilder panelBuilder;
39 private SoapUITreeNode parent;
40
41 protected AbstractTreeNode( ModelItem modelItem, ModelItem parentItem )
42 {
43 this.modelItem = modelItem;
44 if( parentItem != null )
45 this.parent = parentItem.getTreeNode();
46
47 initPopup();
48
49 panelBuilder = modelItem.getPanelBuilder();
50
51 modelItem.addPropertyChangeListener( TestCase.NAME_PROPERTY, this );
52 modelItem.addPropertyChangeListener( TestCase.ICON_PROPERTY, this );
53 }
54
55 public SoapUITreeModel getTreeModel()
56 {
57 return SoapUI.getInstance().getTreeModel();
58 }
59
60 public boolean hasContentPanel()
61 {
62 return panelBuilder.canBuildDesktopPanel();
63 }
64
65 public Component getOverviewPanel()
66 {
67 return panelBuilder.buildOverviewPanel();
68 }
69
70 public DesktopPanel getDesktopPanel()
71 {
72 return panelBuilder.buildDesktopPanel();
73 }
74
75 public ModelItem getModelItem()
76 {
77 return modelItem;
78 }
79
80 public boolean valueChanged(Object newValue)
81 {
82 return false;
83 }
84
85 public boolean isLeaf()
86 {
87 return getChildCount() == 0;
88 }
89
90 public int getChildCount()
91 {
92 return 0;
93 }
94
95 public SoapUITreeNode getChildNode(int index)
96 {
97 return null;
98 }
99
100 public int getIndexOfChild(Object child)
101 {
102 return -1;
103 }
104
105 public String toString()
106 {
107 return modelItem.getName();
108 }
109
110 public JPopupMenu getPopup()
111 {
112 return popup;
113 }
114
115 public SoapUITreeNode getParent()
116 {
117 return parent;
118 }
119
120 protected void initPopup()
121 {
122 Action[] actions = modelItem.getActions();
123 if( actions == null || actions.length == 0 ) return;
124
125 popup = new JPopupMenu();
126
127 for (int i = 0; i < actions.length; i++)
128 {
129 popup.add( actions[i] );
130 }
131 }
132
133 public void setParentNode(SoapUITreeNode parent)
134 {
135 this.parent = parent;
136 }
137
138 public void propertyChange(PropertyChangeEvent evt)
139 {
140 getTreeModel().notifyNodeChanged( this );
141 }
142
143 public void release()
144 {
145 modelItem.removePropertyChangeListener( this );
146 }
147 }