KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > project > uiapi > CategoryChangeSupport


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.project.uiapi;
21
22 import java.beans.PropertyChangeListener JavaDoc;
23 import java.beans.PropertyChangeSupport JavaDoc;
24
25 /**
26  * Support for listening on changes in a category's properties. Separated from
27  * API.
28  *
29  * @author Martin Krauskopf
30  */

31 public class CategoryChangeSupport {
32
33     public static final CategoryChangeSupport NULL_INSTANCE = new CategoryChangeSupport() {
34         public void firePropertyChange(String JavaDoc pn, Object JavaDoc o, Object JavaDoc n) {}
35         public void removePropertyChangeListener(PropertyChangeListener JavaDoc l) {}
36         void addPropertyChangeListener(PropertyChangeListener JavaDoc l) {}
37     };
38     
39     private PropertyChangeSupport JavaDoc changeSupport;
40     
41     /** Name for the <code>valid</code> property. */
42     public static final String JavaDoc VALID_PROPERTY = "isCategoryValid"; // NOI18N
43

44     /** Property for an error message of the category. */
45     public static final String JavaDoc ERROR_MESSAGE_PROPERTY = "categoryErrorMessage"; // NOI18N
46

47     synchronized void addPropertyChangeListener(
48             PropertyChangeListener JavaDoc listener) {
49         if (listener == null) {
50             return;
51         }
52         if (changeSupport == null) {
53             changeSupport = new PropertyChangeSupport JavaDoc(this);
54         }
55         changeSupport.addPropertyChangeListener(listener);
56     }
57     
58     public synchronized void removePropertyChangeListener(
59             PropertyChangeListener JavaDoc listener) {
60         if (listener == null || changeSupport == null) {
61             return;
62         }
63         changeSupport.removePropertyChangeListener(listener);
64     }
65     
66     
67     public void firePropertyChange(String JavaDoc propertyName,
68             Object JavaDoc oldValue, Object JavaDoc newValue) {
69         if (changeSupport == null ||
70                 (oldValue != null && newValue != null && oldValue.equals(newValue))) {
71             return;
72         }
73         changeSupport.firePropertyChange(propertyName, oldValue, newValue);
74     }
75     
76 }
77
Popular Tags