# HG changeset patch # Parent d8cca3af97eab0aedd18003558dcef34f0188e69 diff --git a/api.openfile/arch.xml b/api.openfile/arch.xml new file mode 100644 --- /dev/null +++ b/api.openfile/arch.xml @@ -0,0 +1,1140 @@ + + +]> + + + + &api-questions; + + + + +

+ This module provides SPI for implementing custom filters + for Open File Dialog. These filters can be registered using + ServiceProvider. +

+ See + SPI for defining custom Open File Dialog filters. + +
+ + + + + +

+ There are several unit tests in the module. + The project was successfull if filters work the same way they + worked before + OpenFileDialogFilter was moved from + module + utilities. +

+
+ + + + + +

+ The code was only moved from module + utilities to a new module and made public. + Several tests were implemented. Only a few days was needed. + The work should be ready before NetBeans 7.3 Beta. +

+
+ + + + + +

+ The module is important for implementators of modules that support + opening of custom file types. +

+
+ + + + + +

+ The module lets clients add file filters to open file dialog. +

+

+ For example if a module adds support for files with extension, + lets say, .xyz, Open File dialog will offer this file type in + its list of filters. +

+
+ + + + + + + + + + + + +

+ This module deprecates legacy class + org.netbeans.modules.openfile.OpenFileDialogFilter + in module + utilities. This location for this class is + not semantically correct and implementation or friend dependency + is required to use it. Making this API public in a more appropriate + module has been requested by many users. See bug #209998. +

+

+ The project will influence modules with friend or implementation + dependency on module + utilities that use legacy abstract class + OpenFileDialogFilter in package + org.netbeans.modules.openfile. + This class is still there, but it is marked as deprecated and will + be probably removed soon. +

+

+ The change is known to cause an error if the legacy class is + implemented and registered as service with the + supersedes annotation. Example: +

+
+                @ServiceProvider(service = OpenFileDialogFilter.class,
+position = 100,
+supersedes = {
+    "org.netbeans.modules.openfile.FileChooser$TxtFileFilter",
+    "org.netbeans.modules.openfile.FileChooser$JavaFilesFilter"
+})
+public class OpenFileFilter extends OpenFileDialogFilter.ExtensionFilter {
+    // ...
+}                
+            
+

+ As class + org.netbeans.modules.openfile.FileChooser$TxtFileFilter + now extends the new SPI class, not the legacy one, it is not allowed + to supersede it by any subclass of the legacy interface. +

+
+ + + + + +

+ The module is correctly internationalized. +

+
+ + + + + +

+ The module does not implement nor define any standards. +

+
+ + + + + +

+ No settings are read and stored. +

+
+ + + + + +

+ JRE version 1.6 is needed. +

+
+ + + + + +

+ JRE is enough. +

+
+ + + + + + + + + + + + +

+ There are no external dependencies. +

+
+ + + + + +

+ The module is platform-independent. +

+
+ + + + + +

+ There are no special requirements for declaring dependencies. +

+
+ + + + + +

+ Just module JAR. +

+
+ + + + + +

+ Yes. +

+
+ + + + + +

+ There is only public SPI, no private packages. +

+
+ + + + + +

+ Location does not matter. +

+
+ + + + + +

+ No. +

+
+ + + + + +

+ No. +

+
+ + + + + +

+ No. +

+
+ + + + + +

+ No. +

+
+ + + + + +

+ No. +

+
+ + + + + +

+ No. +

+
+ + + + + +

+ No/No. +

+
+ + + + + +

+ No. +

+
+ + + + + +

+ The API is threadsafe. Mainly because it is very simple. +

+
+ + + + + +

+ There is no interaction with the clipboard. +

+
+ + + + + +

+ No Drag & Drop support. +

+
+ + + + + +

+ No I/O is performed. +

+
+ + + + + +

+ No. +

+
+ + + + + +

+ No. +

+
+ + + + + +

+ No. +

+
+ + + + + +

+ No. +

+
+ + + + + +

+ No. +

+
+ + + + + +

+ No. +

+
+ + + + + +

+ Memory consumption is very low. +

+
+ + + + + +

+ No. +

+
+ + + + + +

+ No. +

+
+ + + + + +

+ There is almost no computation that could be influenced. The code + is very simple. +

+
+ + + + + +

+ Implementations of + OpenFileDialogFilter are usually very simple. They woud + have to be implemented really very badly to influence the overall + performance. +

+
+ + + + + +

+ No. +

+
+ + + + + +

+ No. +

+
+ + + + + +

+ No. +

+
+ + + + + +

+ No. +

+
+ + + + + +

+ No. +

+
+ + + + + +

+ No preferences are read/written/shared. +

+
+ + + + + +

+ No. +

+
+ + + + + +

+ No. +

+
+ + + + + +

+ No. +

+
+ +
diff --git a/api.openfile/build.xml b/api.openfile/build.xml new file mode 100644 --- /dev/null +++ b/api.openfile/build.xml @@ -0,0 +1,5 @@ + + + Builds, tests, and runs the project org.netbeans.api.openfile + + diff --git a/api.openfile/manifest.mf b/api.openfile/manifest.mf new file mode 100644 --- /dev/null +++ b/api.openfile/manifest.mf @@ -0,0 +1,5 @@ +Manifest-Version: 1.0 +OpenIDE-Module: org.netbeans.api.openfile +OpenIDE-Module-Localizing-Bundle: org/netbeans/api/openfile/Bundle.properties +OpenIDE-Module-Specification-Version: 1.0 + diff --git a/api.openfile/nbproject/project.properties b/api.openfile/nbproject/project.properties new file mode 100644 --- /dev/null +++ b/api.openfile/nbproject/project.properties @@ -0,0 +1,4 @@ +is.autoload=true +javac.source=1.6 +javac.compilerargs=-Xlint -Xlint:-serial +javadoc.arch=${basedir}/arch.xml diff --git a/api.openfile/nbproject/project.xml b/api.openfile/nbproject/project.xml new file mode 100644 --- /dev/null +++ b/api.openfile/nbproject/project.xml @@ -0,0 +1,22 @@ + + + org.netbeans.modules.apisupport.project + + + org.netbeans.api.openfile + + + + unit + + org.netbeans.libs.junit4 + + + + + + org.netbeans.spi.openfile + + + + diff --git a/api.openfile/src/org/netbeans/api/openfile/Bundle.properties b/api.openfile/src/org/netbeans/api/openfile/Bundle.properties new file mode 100644 --- /dev/null +++ b/api.openfile/src/org/netbeans/api/openfile/Bundle.properties @@ -0,0 +1,1 @@ +OpenIDE-Module-Name=Open File API diff --git a/utilities/src/org/netbeans/modules/openfile/OpenFileDialogFilter.java b/api.openfile/src/org/netbeans/spi/openfile/OpenFileDialogFilter.java copy from utilities/src/org/netbeans/modules/openfile/OpenFileDialogFilter.java copy to api.openfile/src/org/netbeans/spi/openfile/OpenFileDialogFilter.java --- a/utilities/src/org/netbeans/modules/openfile/OpenFileDialogFilter.java +++ b/api.openfile/src/org/netbeans/spi/openfile/OpenFileDialogFilter.java @@ -40,7 +40,7 @@ * Portions Copyrighted 2010 Sun Microsystems, Inc. */ -package org.netbeans.modules.openfile; +package org.netbeans.spi.openfile; import java.io.File; import java.util.ArrayList; @@ -49,10 +49,10 @@ import javax.swing.filechooser.FileNameExtensionFilter; /** - * {@code OpenFileDialogFilter} is an abstract class used by {@link FileChooser} - * for filtering the set of files shown to the user in the Open dialog - - *
- * Main Menu ► File ► Open File... + * {@code OpenFileDialogFilter} is an abstract class used by NetBeans file + * chooser for filtering the set of files shown to the user in the Open + * dialog -
+ * Main Menu > File > Open File... *

* This class is designed to be used as an abstraction of the service provider * in the NetBeans modules that provide opening of the standalone files via the @@ -61,7 +61,7 @@ * dialog the module should declare a non-abstract successor of this class, and * annotate it as a service provider like this: *

- * @ServiceProvider(service=org.netbeans.modules.openfile.OpenFileDialogFilter.class)
+ * @ServiceProvider(service=org.netbeans.spi.openfile.OpenFileDialogFilter.class)
  * public class AFileTypeFilter extends OpenFileDialogFilter {
  *     ...
  *     // implementation of the class
@@ -103,7 +103,6 @@
  *
  * @see javax.swing.filechooser.FileFilter
  * @see javax.swing.filechooser.FileNameExtensionFilter
- * @see FileChooser
  * @see OpenFileDialogFilter.ExtensionFilter
  *
  * @author Victor G. Vasilyev 
@@ -153,7 +152,7 @@
      *
      * @param fileName a file name
      * @param suffix an extension from a collection obtained via the
-     * {@link #getExtensions()} method.
+     * {@link #getSuffixes()} method.
      *
      * @return true if fileName matches with
      *         suffix, otherwaise true.
@@ -167,7 +166,7 @@
      * the list of applicable file name suffixes associated with this filter.
      *
      * 

- * Note, it is final method. To define the filter description + * Note, it is final method. To define the filter description * a successor class should override the method * {@link #getDescriptionString() }.

* @return a description string of the file filter that will be visible in @@ -213,7 +212,7 @@ /** * Returns acceptable file name suffixes. - * + * * @return an array of the non-null strings that contains file name suffixes. */ public abstract String[] getSuffixes(); @@ -265,7 +264,7 @@ /** * Returns an instance of the {@link FileNameExtensionFilter } class. - * + * * @return an initialized non-null instance of the * {@link FileNameExtensionFilter } class. */ @@ -288,7 +287,7 @@ @Override public String[] getSuffixes() { - ArrayList suffixList = new ArrayList(); + ArrayList suffixList = new ArrayList(); for(String extension : getFilter().getExtensions()) { suffixList.add(EXTENSION_SEPARATOR + extension); } diff --git a/api.openfile/test/unit/src/org/netbeans/spi/openfile/OpenFileDialogFilterTest.java b/api.openfile/test/unit/src/org/netbeans/spi/openfile/OpenFileDialogFilterTest.java new file mode 100644 --- /dev/null +++ b/api.openfile/test/unit/src/org/netbeans/spi/openfile/OpenFileDialogFilterTest.java @@ -0,0 +1,111 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2012 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle 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 2012 Sun Microsystems, Inc. + */ +package org.netbeans.spi.openfile; + +import java.io.File; +import java.util.Arrays; +import java.util.List; +import static org.junit.Assert.*; +import org.junit.Test; + +/** + * Test default implementation of OpenFileDialogFilter. + * + * @author jhavlin + */ +public class OpenFileDialogFilterTest { + + private final OpenFileDialogFilter filter = new OpenFileDialogFilterImpl(); + + public OpenFileDialogFilterTest() { + } + + @Test + public void testAccept() { + assertTrue(filter.accept(new File("test.xyz"))); + assertTrue(filter.accept(new File("test.XYZ"))); + assertTrue(filter.accept(new File("test.uvw"))); + assertTrue(filter.accept(new File("test.UVW"))); + assertFalse(filter.accept(new File("test.java"))); + } + + @Test + public void testCompareSuffixes() { + assertTrue(filter.compareSuffixes("test.xml", ".xml")); + assertTrue(filter.compareSuffixes("test.xml", ".XML")); + assertTrue(filter.compareSuffixes("test.XML", ".xml")); + assertFalse(filter.compareSuffixes("test.xml", ".html")); + } + + @Test + public void testGetDescription() { + assertEquals( + "Custom Example Files [.xyz, .uvw]", + filter.getDescription()); + } + + @Test + public void testGetDescriptionString() { + assertEquals("Custom Example Files", filter.getDescriptionString()); + } + + @Test + public void testGetSuffixes() { + List suffixes = Arrays.asList(filter.getSuffixes()); + assertEquals(2, suffixes.size()); + assertTrue(suffixes.contains(".xyz")); + assertTrue(suffixes.contains(".uvw")); + } + + public class OpenFileDialogFilterImpl extends OpenFileDialogFilter { + + @Override + public String getDescriptionString() { + return "Custom Example Files"; + } + + @Override + public String[] getSuffixes() { + return new String[]{".xyz", ".uvw"}; + } + } +} diff --git a/java.source/nbproject/project.xml b/java.source/nbproject/project.xml --- a/java.source/nbproject/project.xml +++ b/java.source/nbproject/project.xml @@ -77,6 +77,14 @@ + org.netbeans.api.openfile + + + + 1.0 + + + org.netbeans.api.progress diff --git a/java.source/src/org/netbeans/modules/java/Bundle.properties b/java.source/src/org/netbeans/modules/java/Bundle.properties --- a/java.source/src/org/netbeans/modules/java/Bundle.properties +++ b/java.source/src/org/netbeans/modules/java/Bundle.properties @@ -68,4 +68,7 @@ TP_ExecutableBadge=Contains main class. TXT_OpenClassFile= Open Class File -CTL_SourceTabCaption=&Source \ No newline at end of file +CTL_SourceTabCaption=&Source + +#Open File Dialog filter +OFDFD_Java=Java Files diff --git a/java.source/src/org/netbeans/modules/java/JavaOpenFileDialogFilter.java b/java.source/src/org/netbeans/modules/java/JavaOpenFileDialogFilter.java new file mode 100644 --- /dev/null +++ b/java.source/src/org/netbeans/modules/java/JavaOpenFileDialogFilter.java @@ -0,0 +1,65 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2012 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle 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 2012 Sun Microsystems, Inc. + */ +package org.netbeans.modules.java; + +import org.netbeans.spi.openfile.OpenFileDialogFilter; +import org.openide.util.NbBundle; +import org.openide.util.lookup.ServiceProvider; + +/** + * Open File Dialog filter for Java files. + * + * @author jhavlin + */ +@ServiceProvider(service = OpenFileDialogFilter.class) +public class JavaOpenFileDialogFilter extends OpenFileDialogFilter { + + @Override + public String getDescriptionString() { + return NbBundle.getMessage(getClass(), "OFDFD_Java"); //NOI18N + } + + @Override + public String[] getSuffixes() { + return new String[]{".java"}; //NOI18N + } +} diff --git a/nbbuild/cluster.properties b/nbbuild/cluster.properties --- a/nbbuild/cluster.properties +++ b/nbbuild/cluster.properties @@ -230,6 +230,7 @@ nb.cluster.ide=\ api.debugger,\ api.java.classpath,\ + api.openfile,\ api.xml,\ bugtracking,\ bugtracking.bridge,\ diff --git a/utilities/nbproject/project.xml b/utilities/nbproject/project.xml --- a/utilities/nbproject/project.xml +++ b/utilities/nbproject/project.xml @@ -50,6 +50,14 @@ org.netbeans.modules.utilities + org.netbeans.api.openfile + + + + 1.0 + + + org.netbeans.modules.queries diff --git a/utilities/src/org/netbeans/modules/openfile/Bundle.properties b/utilities/src/org/netbeans/modules/openfile/Bundle.properties --- a/utilities/src/org/netbeans/modules/openfile/Bundle.properties +++ b/utilities/src/org/netbeans/modules/openfile/Bundle.properties @@ -41,7 +41,6 @@ # made subject to such option by the copyright holder. # OpenFileDialogFilter -OFDFD_Java=Java Files OFDFD_Txt=Text Files # OpenFileAction diff --git a/utilities/src/org/netbeans/modules/openfile/FileChooser.java b/utilities/src/org/netbeans/modules/openfile/FileChooser.java --- a/utilities/src/org/netbeans/modules/openfile/FileChooser.java +++ b/utilities/src/org/netbeans/modules/openfile/FileChooser.java @@ -83,8 +83,15 @@ * @see javax.swing.JFileChooser */ public void addChoosableFileFilters() { - for (OpenFileDialogFilter f : - Lookup.getDefault().lookupAll(OpenFileDialogFilter.class)) { + // Add legacy filters + for (org.netbeans.modules.openfile.OpenFileDialogFilter f : + Lookup.getDefault().lookupAll( + org.netbeans.modules.openfile.OpenFileDialogFilter.class)) { + addChoosableFileFilter(f); + } + for (org.netbeans.spi.openfile.OpenFileDialogFilter f : + Lookup.getDefault().lookupAll( + org.netbeans.spi.openfile.OpenFileDialogFilter.class)) { addChoosableFileFilter(f); } } @@ -130,25 +137,9 @@ } } - - @ServiceProvider(service=org.netbeans.modules.openfile.OpenFileDialogFilter.class) - public static class JavaFilesFilter extends OpenFileDialogFilter { - - @Override - public String getDescriptionString() { - return NbBundle.getMessage(getClass(), "OFDFD_Java"); // NOI18N - } - - @Override - public String[] getSuffixes() { - return new String[] {".java"}; - } - - } - - @ServiceProvider(service=OpenFileDialogFilter.class) + @ServiceProvider(service = org.netbeans.spi.openfile.OpenFileDialogFilter.class) public static class TxtFileFilter - extends OpenFileDialogFilter.ExtensionFilter { + extends org.netbeans.spi.openfile.OpenFileDialogFilter.ExtensionFilter { @Override public FileNameExtensionFilter getFilter() { diff --git a/utilities/src/org/netbeans/modules/openfile/OpenFileDialogFilter.java b/utilities/src/org/netbeans/modules/openfile/OpenFileDialogFilter.java --- a/utilities/src/org/netbeans/modules/openfile/OpenFileDialogFilter.java +++ b/utilities/src/org/netbeans/modules/openfile/OpenFileDialogFilter.java @@ -107,7 +107,10 @@ * @see OpenFileDialogFilter.ExtensionFilter * * @author Victor G. Vasilyev + * + * @deprecated Use {@link org.netbeans.spi.openfile.OpenFileDialogFilter}. */ +@Deprecated public abstract class OpenFileDialogFilter extends FileFilter { /** @@ -258,7 +261,10 @@ * @see OpenFileDialogFilter * @see FileNameExtensionFilter * + * @deprecated Use + * {@link org.netbeans.spi.openfile.OpenFileDialogFilter.ExtensionFilter}. */ + @Deprecated public static abstract class ExtensionFilter extends OpenFileDialogFilter { private static final char EXTENSION_SEPARATOR = '.';