View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2010 eviware.com 
3    *
4    *  soapUI is free software; you can redistribute it and/or modify it under the 
5    *  terms of version 2.1 of the GNU Lesser General Public License as published by 
6    *  the Free Software Foundation.
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.support.action.support;
14  
15  import java.beans.PropertyChangeListener;
16  import java.beans.PropertyChangeSupport;
17  
18  import com.eviware.soapui.model.ModelItem;
19  import com.eviware.soapui.support.action.SoapUIAction;
20  
21  /***
22   * Abstract SoapUIAction for extension
23   * 
24   * @author ole.matzura
25   */
26  
27  public abstract class AbstractSoapUIAction<T extends ModelItem> implements SoapUIAction<T>
28  {
29  	private PropertyChangeSupport propertySupport;
30  	private String name;
31  	private String description;
32  	private boolean enabled = true;
33  	private String id;
34  
35  	public AbstractSoapUIAction( String id )
36  	{
37  		this.id = id;
38  		propertySupport = new PropertyChangeSupport( this );
39  	}
40  
41  	public AbstractSoapUIAction( String name, String description )
42  	{
43  		this( null, name, description );
44  		id = getClass().getSimpleName();
45  	}
46  
47  	public AbstractSoapUIAction( String id, String name, String description )
48  	{
49  		this.id = id;
50  		this.name = name;
51  		this.description = description;
52  
53  		propertySupport = new PropertyChangeSupport( this );
54  	}
55  
56  	public String getId()
57  	{
58  		return id;
59  	}
60  
61  	public String getDescription()
62  	{
63  		return description;
64  	}
65  
66  	public void setEnabled( boolean enabled )
67  	{
68  		if( enabled == this.enabled )
69  			return;
70  
71  		boolean oldEnabled = this.enabled;
72  		this.enabled = enabled;
73  
74  		propertySupport.firePropertyChange( ENABLED_PROPERTY, oldEnabled, enabled );
75  	}
76  
77  	public boolean applies( T target )
78  	{
79  		return true;
80  	}
81  
82  	public boolean isDefault()
83  	{
84  		return false;
85  	}
86  
87  	public String getName()
88  	{
89  		return name;
90  	}
91  
92  	public boolean isEnabled()
93  	{
94  		return enabled;
95  	}
96  
97  	public void addPropertyChangeListener( String propertyName, PropertyChangeListener listener )
98  	{
99  		propertySupport.addPropertyChangeListener( propertyName, listener );
100 	}
101 
102 	public void addPropertyChangeListener( PropertyChangeListener listener )
103 	{
104 		propertySupport.addPropertyChangeListener( listener );
105 	}
106 
107 	public void removePropertyChangeListener( PropertyChangeListener listener )
108 	{
109 		propertySupport.removePropertyChangeListener( listener );
110 	}
111 
112 	public void removePropertyChangeListener( String propertyName, PropertyChangeListener listener )
113 	{
114 		propertySupport.removePropertyChangeListener( propertyName, listener );
115 	}
116 }