View Javadoc

1   /*
2    *  soapUI, copyright (C) 2006 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;
14  
15  import java.awt.Component;
16  import java.beans.PropertyChangeListener;
17  import java.beans.PropertyChangeSupport;
18  
19  import javax.swing.Action;
20  import javax.swing.ImageIcon;
21  import javax.swing.JPopupMenu;
22  
23  import com.eviware.soapui.model.ModelItem;
24  import com.eviware.soapui.model.PanelBuilder;
25  import com.eviware.soapui.model.settings.Settings;
26  import com.eviware.soapui.support.action.ActionList;
27  import com.eviware.soapui.support.action.ActionSupport;
28  import com.eviware.soapui.support.action.DefaultActionList;
29  import com.eviware.soapui.ui.desktop.DesktopPanel;
30  
31  /***
32   * Base implementation of SoapUITreeNode interface
33   * 
34   * @author Ole.Matzura
35   */
36  
37  public abstract class AbstractTreeNode implements SoapUITreeNode
38  {
39  	private DummyModelItem modelItem;
40  	private JPopupMenu popup;
41  	private ActionList actions;
42  
43  	public AbstractTreeNode(String name, ImageIcon icon)
44  	{
45  		modelItem = new DummyModelItem( name, icon );
46  	}
47  	
48  	public boolean valueChanged(Object newValue)
49  	{
50  		return false;
51  	}
52  
53  	public boolean isLeaf()
54  	{
55  		return getChildCount() == 0;
56  	}
57  
58  	public JPopupMenu getPopup()
59  	{
60  		if( popup == null && actions != null )
61  			popup = ActionSupport.buildPopup( actions );
62  		
63  		return popup;
64  	}
65  	
66  	public void setLabel( String label )
67  	{
68  		modelItem.setLabel( label );
69  	}
70  	
71  	public ActionList getActions()
72  	{
73  		return actions;
74  	}
75  	
76  	public void addAction( Action action, boolean isDefault )
77  	{
78  		if( actions == null )
79  			actions = new DefaultActionList( modelItem.getName() );
80  		
81  		actions.addAction( action );
82  		if( isDefault && actions instanceof DefaultActionList )
83  			((DefaultActionList)actions).setDefaultAction( action );
84  	}
85  
86  	public void setActions(ActionList actions)
87  	{
88  		this.actions = actions;
89  	}
90  
91  	public Component getOverviewPanel()
92  	{
93  		return null;
94  	}
95  
96  	public DesktopPanel getDesktopPanel()
97  	{
98  		return null;
99  	}
100 
101 	public ModelItem getModelItem()
102 	{
103 		return modelItem;
104 	}
105 
106 	public boolean hasContentPanel()
107 	{
108 		return false;
109 	}
110 	
111 	public class DummyModelItem implements ModelItem
112 	{
113 		private String name;
114 		private ImageIcon icon;
115 		private PropertyChangeSupport propertyChangeSupport;
116 		
117 		public DummyModelItem(String name, ImageIcon icon)
118 		{
119 			this.name = name;
120 			this.icon = icon;
121 		}
122 
123 		public void setLabel( String label )
124 		{
125 			String oldName = this.name;
126 			this.name = label;
127 			
128 			if( propertyChangeSupport != null )
129 			{
130 				propertyChangeSupport.firePropertyChange( ModelItem.NAME_PROPERTY, oldName, label );
131 			}
132 		}
133 
134 		public String getName()
135 		{
136 			return name;
137 		}
138 
139 		public ImageIcon getIcon()
140 		{
141 			return icon;
142 		}
143 
144 		public ActionList getActions()
145 		{
146 			return actions;
147 		}
148 
149 		public PanelBuilder getPanelBuilder()
150 		{
151 			return null;
152 		}
153 
154 		public String getDescription()
155 		{
156 			return name;
157 		}
158 
159 		public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener)
160 		{
161 			if( propertyChangeSupport == null )
162 				propertyChangeSupport = new PropertyChangeSupport( this );
163 			
164 			propertyChangeSupport.addPropertyChangeListener( propertyName, listener );
165 		}
166 
167 		public void addPropertyChangeListener(PropertyChangeListener listener)
168 		{
169 			if( propertyChangeSupport == null )
170 				propertyChangeSupport = new PropertyChangeSupport( this );
171 			
172 			propertyChangeSupport.addPropertyChangeListener( listener );
173 		}
174 
175 		public void removePropertyChangeListener(PropertyChangeListener listener)
176 		{
177 			if( propertyChangeSupport != null )
178 				propertyChangeSupport.removePropertyChangeListener( listener );
179 		}
180 
181 		public SoapUITreeNode getTreeNode()
182 		{
183 			return AbstractTreeNode.this;
184 		}
185 
186 		public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener)
187 		{
188 			if( propertyChangeSupport != null )
189 				propertyChangeSupport.removePropertyChangeListener( propertyName, listener );
190 		}
191 
192 		public Settings getSettings()
193 		{
194 			return null;
195 		}
196 
197 		public void release()
198 		{
199 		}}
200 
201 
202 	public String toString()
203 	{
204 		return modelItem.getName();
205 	}
206 	
207 	public void reorder( boolean notify )
208 	{
209 	}
210 }