1 /**
2 * The contents of this file are subject to the Mozilla Public License Version 1.1
3 * (the "License"); you may not use this file except in compliance with the License.
4 * You may obtain a copy of the License at http://www.mozilla.org/MPL/
5 * Software distributed under the License is distributed on an "AS IS" basis,
6 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the
7 * specific language governing rights and limitations under the License.
8 *
9 * The Original Code is "" Description:
10 * ""
11 *
12 * The Initial Developer of the Original Code is University Health Network. Copyright (C)
13 * 2001. All Rights Reserved.
14 *
15 * Contributor(s): ______________________________________.
16 *
17 * Alternatively, the contents of this file may be used under the terms of the
18 * GNU General Public License (the "GPL"), in which case the provisions of the GPL are
19 * applicable instead of those above. If you wish to allow use of your version of this
20 * file only under the terms of the GPL and not to allow others to use your version
21 * of this file under the MPL, indicate your decision by deleting the provisions above
22 * and replace them with the notice and other provisions required by the GPL License.
23 * If you do not delete the provisions above, a recipient may use your version of
24 * this file under either the MPL or the GPL.
25 */
26 /*
27 * To change this template, choose Tools | Templates
28 * and open the template in the editor.
29 */
30 package ca.uhn.hl7v2.testpanel.model;
31
32 import java.beans.PropertyChangeListener;
33 import java.beans.PropertyChangeSupport;
34 import java.beans.PropertyVetoException;
35 import java.beans.VetoableChangeListener;
36 import java.beans.VetoableChangeSupport;
37
38 /**
39 * Base class for a model class
40 */
41 public abstract class AbstractModelClass {
42 // ~ Instance fields
43 // ------------------------------------------------------------------------------------------------
44
45 private transient PropertyChangeSupport myPropertyChangeSupport = new PropertyChangeSupport(this);
46 private transient VetoableChangeSupport myVetoableChangeSupport = new VetoableChangeSupport(this);
47
48 // ~ Methods
49 // --------------------------------------------------------------------------------------------------------
50
51 /**
52 * Add a PropertyChangeListener for a specific property. The listener will
53 * be invoked only when a call on firePropertyChange names that specific
54 * property. The same listener object may be added more than once. For each
55 * property, the listener will be invoked the number of times it was added
56 * for that property. If <code>propertyName</code> or <code>listener</code>
57 * is null, no exception is thrown and no action is taken.
58 *
59 * @param propertyName
60 * The name of the property to listen on.
61 * @param listener
62 * The PropertyChangeListener to be added
63 */
64 public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) {
65 myPropertyChangeSupport.addPropertyChangeListener(propertyName, listener);
66 }
67
68 /**
69 * Add a PropertyChangeListener for a specific property. The listener will
70 * be invoked only when a call on firePropertyChange names that specific
71 * property. The same listener object may be added more than once. For each
72 * property, the listener will be invoked the number of times it was added
73 * for that property. If <code>propertyName</code> or <code>listener</code>
74 * is null, no exception is thrown and no action is taken.
75 *
76 * @param propertyName
77 * The name of the property to listen on.
78 * @param listener
79 * The PropertyChangeListener to be added
80 */
81 public void addVetoableyChangeListener(String propertyName, VetoableChangeListener listener) {
82 myVetoableChangeSupport.addVetoableChangeListener(propertyName, listener);
83 }
84
85 public abstract Object exportConfigToXml();
86
87 /**
88 * Report a bound property update to any registered listeners. No event is
89 * fired if old and new are equal and non-null.
90 *
91 * <p>
92 * This is merely a convenience wrapper around the more general
93 * firePropertyChange method that takes {@code PropertyChangeEvent} value.
94 *
95 * @param propertyName
96 * The programmatic name of the property that was changed.
97 * @param oldValue
98 * The old value of the property.
99 * @param newValue
100 * The new value of the property.
101 */
102 public void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
103 myPropertyChangeSupport.firePropertyChange(propertyName, oldValue, newValue);
104 }
105
106 /**
107 * Report a bound property update to any registered listeners. No event is
108 * fired if old and new are equal and non-null.
109 *
110 * <p>
111 * This is merely a convenience wrapper around the more general
112 * firePropertyChange method that takes {@code PropertyChangeEvent} value.
113 *
114 * @param propertyName
115 * The programmatic name of the property that was changed.
116 * @param oldValue
117 * The old value of the property.
118 * @param newValue
119 * The new value of the property.
120 */
121 public void fireVetoableChange(String propertyName, Object oldValue, Object newValue) throws PropertyVetoException {
122 myVetoableChangeSupport.fireVetoableChange(propertyName, oldValue, newValue);
123 }
124
125 /**
126 * Remove a PropertyChangeListener for a specific property. If
127 * <code>listener</code> was added more than once to the same event source
128 * for the specified property, it will be notified one less time after being
129 * removed. If <code>propertyName</code> is null, no exception is thrown and
130 * no action is taken. If <code>listener</code> is null, or was never added
131 * for the specified property, no exception is thrown and no action is
132 * taken.
133 *
134 * @param propertyName
135 * The name of the property that was listened on.
136 * @param listener
137 * The PropertyChangeListener to be removed
138 */
139 public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) {
140 myPropertyChangeSupport.removePropertyChangeListener(propertyName, listener);
141 }
142
143 public void removePropertyChangeListener(String propertyName, Class<? extends PropertyChangeListener> listenerClass) {
144 boolean found = false;
145 do {
146 for (PropertyChangeListener next : myPropertyChangeSupport.getPropertyChangeListeners(propertyName)) {
147 if (next.getClass().isInstance(listenerClass)) {
148 myPropertyChangeSupport.removePropertyChangeListener(propertyName, next);
149 found = true;
150 break;
151 }
152 }
153 } while (found);
154 }
155
156 /**
157 * Remove a PropertyChangeListener for a specific property. If
158 * <code>listener</code> was added more than once to the same event source
159 * for the specified property, it will be notified one less time after being
160 * removed. If <code>propertyName</code> is null, no exception is thrown and
161 * no action is taken. If <code>listener</code> is null, or was never added
162 * for the specified property, no exception is thrown and no action is
163 * taken.
164 *
165 * @param propertyName
166 * The name of the property that was listened on.
167 * @param listener
168 * The PropertyChangeListener to be removed
169 */
170 public void removeVetoableChangeListener(String propertyName, VetoableChangeListener listener) {
171 myVetoableChangeSupport.removeVetoableChangeListener(propertyName, listener);
172 }
173 }