# HG changeset patch # User Milos Kleint # Date 1205744946 -3600 # Node ID 316e8498620fc9c067409d28bb52efe8f1bfa63c # Parent a61c2f45645004d3c76bb0f82c0cb24e3de8a8f7 #95974 - additional isVisible(File) method added to VisibilityQuery diff -r a61c2f456450 -r 316e8498620f masterfs/nbproject/project.xml --- a/masterfs/nbproject/project.xml Sun Mar 16 23:31:14 2008 -0700 +++ b/masterfs/nbproject/project.xml Mon Mar 17 10:09:06 2008 +0100 @@ -52,6 +52,7 @@ 1 + 1.12 diff -r a61c2f456450 -r 316e8498620f masterfs/src/org/netbeans/modules/masterfs/GlobalVisibilityQueryImpl.java --- a/masterfs/src/org/netbeans/modules/masterfs/GlobalVisibilityQueryImpl.java Sun Mar 16 23:31:14 2008 -0700 +++ b/masterfs/src/org/netbeans/modules/masterfs/GlobalVisibilityQueryImpl.java Mon Mar 17 10:09:06 2008 +0100 @@ -41,13 +41,14 @@ package org.netbeans.modules.masterfs; +import java.io.File; import java.util.prefs.PreferenceChangeEvent; import java.util.prefs.PreferenceChangeListener; -import org.netbeans.spi.queries.VisibilityQueryImplementation; import org.openide.filesystems.FileObject; import javax.swing.event.ChangeListener; import java.util.prefs.Preferences; import java.util.regex.Pattern; +import org.netbeans.spi.queries.VisibilityQueryImplementation2; import org.openide.util.ChangeSupport; import org.openide.util.NbPreferences; @@ -62,7 +63,7 @@ * * This class has hidden dependency on IDESettings in module org.netbeans.core. */ -public class GlobalVisibilityQueryImpl implements VisibilityQueryImplementation { +public class GlobalVisibilityQueryImpl implements VisibilityQueryImplementation2 { static GlobalVisibilityQueryImpl INSTANCE; private final ChangeSupport cs = new ChangeSupport(this); @@ -84,6 +85,11 @@ public boolean isVisible(FileObject file) { return isVisible(file.getNameExt()); } + + public boolean isVisible(File file) { + return isVisible(file.getName()); + } + boolean isVisible(final String fileName) { Pattern pattern = getIgnoreFilesPattern(); @@ -127,5 +133,6 @@ } }); return retval; - } + } + } diff -r a61c2f456450 -r 316e8498620f queries/apichanges.xml --- a/queries/apichanges.xml Sun Mar 16 23:31:14 2008 -0700 +++ b/queries/apichanges.xml Mon Mar 17 10:09:06 2008 +0100 @@ -104,6 +104,28 @@ + + + VisibilityQuery.isVisible(File) added + + + + + + +

+ Added new method VisibilityQuery.isVisible(File). + It queries all VisibilityQueryImplementation instances found in global lookup. + If such instance implements VisibilityQueryImplementation2, it's isVisible(File) method is used directly. + If not, it attempts to delegate to the isVisible(FileObject) method. That might not work for non-existing files. + All implementations of VisibilityQueryImplementation are encouraged to upgrade to VisibilityQueryImplementation2. +

+
+ + + +
+ Default Encoding of System File System is always UTF-8 diff -r a61c2f456450 -r 316e8498620f queries/manifest.mf --- a/queries/manifest.mf Sun Mar 16 23:31:14 2008 -0700 +++ b/queries/manifest.mf Mon Mar 17 10:09:06 2008 +0100 @@ -1,5 +1,5 @@ Manifest-Version: 1.0 OpenIDE-Module: org.netbeans.modules.queries/1 -OpenIDE-Module-Specification-Version: 1.11 +OpenIDE-Module-Specification-Version: 1.12 OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/queries/Bundle.properties diff -r a61c2f456450 -r 316e8498620f queries/src/org/netbeans/api/queries/VisibilityQuery.java --- a/queries/src/org/netbeans/api/queries/VisibilityQuery.java Sun Mar 16 23:31:14 2008 -0700 +++ b/queries/src/org/netbeans/api/queries/VisibilityQuery.java Mon Mar 17 10:09:06 2008 +0100 @@ -41,6 +41,7 @@ package org.netbeans.api.queries; +import java.io.File; import java.util.ArrayList; import java.util.HashSet; import java.util.List; @@ -48,7 +49,9 @@ import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import org.netbeans.spi.queries.VisibilityQueryImplementation; +import org.netbeans.spi.queries.VisibilityQueryImplementation2; import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileUtil; import org.openide.util.ChangeSupport; import org.openide.util.Lookup; import org.openide.util.LookupEvent; @@ -99,6 +102,33 @@ } return true; } + + /** + * Check whether a file is recommended to be visible. + * Default return value is visible unless at least one VisibilityQueryImplementation + * provider says hidden. + * @param file a file which should be checked + * @return true if it is recommended to show this file + * @since org.netbeans.modules.queries/1 1.12 + */ + public boolean isVisible(File file) { + for (VisibilityQueryImplementation vqi : getVqiInstances()) { + if (vqi instanceof VisibilityQueryImplementation2) { + if (!((VisibilityQueryImplementation2)vqi).isVisible(file)) { + return false; + } + } else { + FileObject fo = FileUtil.toFileObject(file); + if (fo != null) { + if (!vqi.isVisible(fo)) { + return false; + } + } + } + } + return true; + } + /** * Add a listener to changes. diff -r a61c2f456450 -r 316e8498620f queries/src/org/netbeans/spi/queries/VisibilityQueryImplementation2.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/queries/src/org/netbeans/spi/queries/VisibilityQueryImplementation2.java Mon Mar 17 10:09:06 2008 +0100 @@ -0,0 +1,66 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2008 Sun Microsystems, Inc. + */ + +package org.netbeans.spi.queries; + +import java.io.File; + +/** + * Determine whether files should be hidden in views presented to the user. + *

+ * Global lookup is used to find all instances of VisibilityQueryImplementation. + *

+ *

+ * Threading note: implementors should avoid acquiring locks that might be held + * by other threads. Generally treat this interface similarly to SPIs in + * {@link org.openide.filesystems} with respect to threading semantics. + *

+ * @see org.netbeans.api.queries.VisibilityQuery + * @since org.netbeans.modules.queries/1 1.12 + * @author mkleint + */ +public interface VisibilityQueryImplementation2 extends VisibilityQueryImplementation { + /** + * Check whether a file is recommended to be visible. + * @param file a file to considered + * @return true if it is recommended to display this file + */ + boolean isVisible(File file); + +}