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.support;
14  
15  import java.beans.PropertyChangeListener;
16  import java.beans.PropertyChangeSupport;
17  import java.util.ArrayList;
18  import java.util.List;
19  
20  import javax.swing.Action;
21  
22  import com.eviware.soapui.SoapUI;
23  import com.eviware.soapui.impl.EmptyPanelBuilder;
24  import com.eviware.soapui.model.ModelItem;
25  import com.eviware.soapui.model.PanelBuilder;
26  import com.eviware.soapui.model.tree.AbstractTreeNode;
27  import com.eviware.soapui.model.tree.SoapUITreeModel;
28  import com.eviware.soapui.model.tree.SoapUITreeNode;
29  
30  /***
31   * Base-class for ModelItem implementations
32   * 
33   * @author Ole.Matzura
34   */
35  
36  public abstract class AbstractModelItem implements ModelItem
37  {
38     private List<Action> actions;
39     private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport( this );
40     private SoapUITreeNode treeNode;
41  
42     protected void addAction( Action action )
43     {
44     	if( actions == null )
45     		 actions = new ArrayList<Action>();
46     	
47        actions.add( action );
48     }
49     
50     public Action[] getActions()
51     {
52     	if( actions == null )
53     		return new Action[0];
54     	
55        return actions.toArray( new Action[actions.size()] );
56     }
57     
58     public PanelBuilder getPanelBuilder()
59     {
60        return new EmptyPanelBuilder();
61     }
62     
63     public String getDescription()
64     {
65        return getName();
66     }
67     
68     public SoapUITreeNode getTreeNode()
69     {
70        if( treeNode == null )
71        {
72           treeNode = createTreeNode();
73        }
74        
75        return treeNode;
76     }
77     
78     public SoapUITreeModel getTreeModel()
79     {
80        return SoapUI.getInstance().getTreeModel();
81     }
82     
83     protected abstract SoapUITreeNode createTreeNode();
84     
85  
86     public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener)
87     {
88        propertyChangeSupport.addPropertyChangeListener( propertyName, listener );
89     }
90  
91     public void addPropertyChangeListener(PropertyChangeListener listener)
92     {
93        propertyChangeSupport.addPropertyChangeListener( listener );
94     }
95  
96     public void removePropertyChangeListener(PropertyChangeListener listener)
97     {
98        propertyChangeSupport.removePropertyChangeListener( listener );
99     }
100    
101    protected void notifyPropertyChanged( String name, Object oldValue, Object newValue )
102    {
103       propertyChangeSupport.firePropertyChange( name, oldValue, newValue );
104    }
105 
106    protected void notifyPropertyChanged( String name, int oldValue, int newValue )
107    {
108       propertyChangeSupport.firePropertyChange( name, oldValue, newValue );
109    }
110 
111    protected void notifyPropertyChanged( String name, boolean oldValue, boolean newValue )
112    {
113       propertyChangeSupport.firePropertyChange( name, oldValue, newValue );
114    }
115 
116    public void release()
117    {
118    	if( treeNode != null && treeNode instanceof AbstractTreeNode )
119    		((AbstractTreeNode)treeNode).release();
120    }
121    
122 }