001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.tasklist.filter;
043:
044: import java.util.prefs.BackingStoreException;
045: import java.util.prefs.Preferences;
046: import javax.swing.JComponent;
047:
048: /**
049: * A condition (type and relation pair) in the filter.
050: * Don't forget to override sameType if you extend this class!
051: *
052: * @author Tor Norbye
053: */
054: abstract class FilterCondition {
055: // transient private String name = null;
056:
057: /**
058: * Creates a condition with the given name.
059: *
060: * @param name user visible name of the filter condition
061: */
062: public FilterCondition() {
063: // this.name = null;
064: }
065:
066: /**
067: * Copy constructor. Use from subclassed clone.
068: */
069: protected FilterCondition(final FilterCondition rhs) {
070: // this.name = rhs.name;
071: }
072:
073: /**
074: * Deep clone, please implement in subclass.
075: */
076: public abstract Object clone();
077:
078: // /**
079: // * Returns the user visible name of this condition
080: // *
081: // * @return name of this condition
082: // */
083: // public String getName() {
084: // if (this.name == null) this.name = getDisplayName();
085: // return this.name;
086: // }
087:
088: /**
089: * Compares two objects.
090: *
091: * @param obj value of the property
092: */
093: public abstract boolean isTrue(Object obj);
094:
095: /**
096: * Creates a component that will represent a constant within the
097: * filter dialog. It should support {@link #PROP_VALUE_VALID}
098: * client property.
099: *
100: * @return created component or null if no component
101: */
102: public JComponent createConstantComponent() {
103: return null;
104: }
105:
106: /**
107: * Gets constant from the specified component and save it.
108: * This method should be also implemented if createConstantComponent()
109: * is implemented.
110: *
111: * @param cmp with createConstantComponent() create component
112: */
113: public void getConstantFrom(JComponent cmp) {
114: assert cmp != null : "getConstantFrom() is not implemented!"; //NOI18N
115: }
116:
117: final boolean isValueValid(JComponent cmp) {
118: Boolean valid = (Boolean) cmp
119: .getClientProperty(PROP_VALUE_VALID);
120: if (valid == null) {
121: return true;
122: } else {
123: return valid.booleanValue();
124: }
125: }
126:
127: /**
128: * Checks whether fc is of the same type.
129: * This method will be used to replace a condition created with
130: * Filter.getConditionsFor(Node.Property) with one contained in a filter.
131: * This method should return true also if this and fc have different
132: * constants for comparing with property values.
133: *
134: * @param fc another condition
135: * @return true fc is of the same type as this
136: */
137: public boolean sameType(FilterCondition fc) {
138: return fc.getClass() == getClass();
139: }
140:
141: public String toString() {
142: return getClass().getName() + "[name=" + getDisplayName() + "]"; // NOI18N
143: // return getClass().getName() +
144: // "[name=" + name + "]"; // NOI18N
145: }
146:
147: /** Use this client property on value/contant components to indicate valid user data.*/
148: public static final String PROP_VALUE_VALID = "value-valid"; //NOI18N
149:
150: protected abstract String getDisplayName();
151:
152: abstract void load(Preferences prefs, String prefix)
153: throws BackingStoreException;
154:
155: abstract void save(Preferences prefs, String prefix)
156: throws BackingStoreException;
157: }
|