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 org.netbeans.modules.tasklist.impl.ScannerDescriptor;
047: import org.netbeans.spi.tasklist.FileTaskScanner;
048: import org.netbeans.spi.tasklist.PushTaskScanner;
049: import org.netbeans.spi.tasklist.Task;
050:
051: /**
052: *
053: * @author S. Aubrecht
054: */
055: public final class TaskFilter {
056:
057: public static final TaskFilter EMPTY = new TaskFilter(Util
058: .getString("no-filter")); //NOI18N
059:
060: private String name;
061: private KeywordsFilter keywords;
062: private TypesFilter types;
063:
064: TaskFilter(String name) {
065: this .name = name;
066: }
067:
068: TaskFilter() {
069: }
070:
071: private TaskFilter(TaskFilter src) {
072: this .name = src.name;
073: keywords = null == src.keywords ? null
074: : (KeywordsFilter) src.keywords.clone();
075: types = null == src.types ? null : (TypesFilter) src.types
076: .clone();
077: }
078:
079: public boolean accept(Task task) {
080: return null == keywords ? true : keywords.accept(task);
081: }
082:
083: public boolean isEnabled(FileTaskScanner scanner) {
084: return null == types ? true : types.isEnabled(ScannerDescriptor
085: .getType(scanner));
086: }
087:
088: public boolean isEnabled(PushTaskScanner scanner) {
089: return null == types ? true : types.isEnabled(ScannerDescriptor
090: .getType(scanner));
091: }
092:
093: public boolean isTaskCountLimitReached(int currentTaskCount) {
094: return null == types ? false : types
095: .isTaskCountLimitReached(currentTaskCount);
096: }
097:
098: public String getName() {
099: return name;
100: }
101:
102: void setName(String newName) {
103: this .name = newName;
104: }
105:
106: KeywordsFilter getKeywordsFilter() {
107: return keywords;
108: }
109:
110: void setKeywordsFilter(KeywordsFilter f) {
111: this .keywords = f;
112: }
113:
114: TypesFilter getTypesFilter() {
115: return types;
116: }
117:
118: void setTypesFilter(TypesFilter f) {
119: this .types = f;
120: }
121:
122: @Override
123: public Object clone() {
124: return new TaskFilter(this );
125: }
126:
127: @Override
128: public String toString() {
129: return name;
130: }
131:
132: void load(Preferences prefs, String prefix)
133: throws BackingStoreException {
134: name = prefs.get(prefix + "_name", "Filter"); //NOI18N //NOI18N
135: if (prefs.getBoolean(prefix + "_types", false)) { //NOI18N
136: types = new TypesFilter();
137: types.load(prefs, prefix + "_types"); //NOI18N
138: } else {
139: types = null;
140: }
141:
142: if (prefs.getBoolean(prefix + "_keywords", false)) { //NOI18N
143: keywords = new KeywordsFilter();
144: keywords.load(prefs, prefix + "_keywords"); //NOI18N
145: } else {
146: keywords = null;
147: }
148: }
149:
150: void save(Preferences prefs, String prefix)
151: throws BackingStoreException {
152: prefs.put(prefix + "_name", name); //NOI18N
153:
154: if (null != types) {
155: prefs.putBoolean(prefix + "_types", true); //NOI18N
156: types.save(prefs, prefix + "_types"); //NOI18N
157: } else {
158: prefs.putBoolean(prefix + "_types", false); //NOI18N
159: }
160:
161: if (null != keywords) {
162: prefs.putBoolean(prefix + "_keywords", true); //NOI18N
163: keywords.save(prefs, prefix + "_keywords"); //NOI18N
164: } else {
165: prefs.putBoolean(prefix + "_keywords", false); //NOI18N
166: }
167: }
168: }
|