KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > tasklist > core > filter > FilterCondition


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.tasklist.core.filter;
21
22 import javax.swing.*;
23 import org.netbeans.spi.settings.DOMConvertor;
24
25 /**
26  * A condition (type and relation pair) in the filter.
27  * Don't forget to override sameType if you extend this class!
28  *
29  * @author Tor Norbye
30  */

31 public abstract class FilterCondition {
32     transient private String JavaDoc name = null;
33
34     /**
35      * Creates a condition with the given name.
36      *
37      * @param name user visible name of the filter condition
38      */

39     public FilterCondition() {
40       this.name = null;
41     }
42
43     /**
44      * Copy constructor. Use from subclassed clone.
45      */

46     protected FilterCondition(final FilterCondition rhs) {
47         this.name = rhs.name;
48     }
49
50     /**
51      * Deep clone, please implement in subclass.
52      */

53     public abstract Object JavaDoc clone() ;
54     
55     /**
56      * Returns the user visible name of this condition
57      *
58      * @return name of this condition
59      */

60     public String JavaDoc getName() {
61       if (this.name == null) this.name = getDisplayName();
62       return this.name;
63     }
64     
65     /**
66      * Compares two objects.
67      *
68      * @param obj value of the property
69      */

70     public abstract boolean isTrue(Object JavaDoc obj);
71
72     /**
73      * Creates a component that will represent a constant within the
74      * filter dialog. It should support {@link #PROP_VALUE_VALID}
75      * client property.
76      *
77      * @return created component or null if no component
78      */

79     public JComponent createConstantComponent() {
80         return null;
81     }
82
83     /**
84      * Gets constant from the specified component and save it.
85      * This method should be also implemented if createConstantComponent()
86      * is implemented.
87      *
88      * @param cmp with createConstantComponent() create component
89      */

90     public void getConstantFrom(JComponent cmp) {
91         assert cmp != null : "getConstantFrom() is not implemented!";
92     }
93
94     final boolean isValueValid(JComponent cmp) {
95         Boolean JavaDoc valid = (Boolean JavaDoc) cmp.getClientProperty(PROP_VALUE_VALID);
96         if (valid == null) {
97             return true;
98         } else {
99             return valid.booleanValue();
100         }
101     }
102
103     /**
104      * Checks whether fc is of the same type.
105      * This method will be used to replace a condition created with
106      * Filter.getConditionsFor(Node.Property) with one contained in a filter.
107      * This method should return true also if this and fc have different
108      * constants for comparing with property values.
109      *
110      * @param fc another condition
111      * @return true fc is of the same type as this
112      */

113      public boolean sameType(FilterCondition fc) {
114        return fc.getClass() == getClass();
115      }
116     
117     public String JavaDoc toString() {
118         return getClass().getName() +
119             "[name=" + name + "]"; // NOI18N
120
}
121
122     /** Use this client property on value/contant components to indicate valid user data.*/
123     public static final String JavaDoc PROP_VALUE_VALID = "value-valid";
124
125
126     protected abstract String JavaDoc getDisplayName();
127
128
129   /**
130    * Convertor is nested in order to have access to private fields in
131    * condition. The convertor does not convert the attribute name,
132    * which is locale dependent. Subclasses must remember to recover
133    * this attribute when reading.
134    */

135   protected abstract static class Convertor extends DOMConvertor {
136
137     /** Creates a new instance of FilerRepositoryConvertor */
138     protected Convertor(String JavaDoc rootElement) {
139       super("-//NetBeans org.netbeans.modules.tasklist//DTD" + rootElement+" 1.0//EN", // NOI18N
140
"http://tasklist.netbeans.org/dtd/conditions-1_0.dtd", rootElement); // NOI18N
141
}
142         
143     public void registerSaver(Object JavaDoc obj, org.netbeans.spi.settings.Saver saver) {
144       // no saver for conditions, they are immutable
145
}
146     
147     public void unregisterSaver(Object JavaDoc obj, org.netbeans.spi.settings.Saver saver) {
148       // no saver for conditions, they are immutable
149
}
150     
151
152     protected void writeCondition(org.w3c.dom.Document JavaDoc document, org.w3c.dom.Element JavaDoc element, FilterCondition cond)
153       throws java.io.IOException JavaDoc, org.w3c.dom.DOMException JavaDoc
154     {
155       // the name attribute is not convertized
156
}
157   
158     protected void readCondition(org.w3c.dom.Element JavaDoc element, FilterCondition condition)
159       throws java.io.IOException JavaDoc, java.lang.ClassNotFoundException JavaDoc
160     {
161       // the name attribute is not convertized
162
}
163
164   }
165
166 }
167
168
Popular Tags