This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 209998
Collapse All | Expand All

(-)a/cnd.utils/nbproject/project.xml (-9 lines)
Lines 14-28 Link Here
14
                    </run-dependency>
14
                    </run-dependency>
15
                </dependency>
15
                </dependency>
16
                <dependency>
16
                <dependency>
17
                    <code-name-base>org.netbeans.modules.utilities</code-name-base>
18
                    <build-prerequisite/>
19
                    <compile-dependency/>
20
                    <run-dependency>
21
                        <release-version>1</release-version>
22
                        <specification-version>1.34</specification-version>
23
                    </run-dependency>
24
                </dependency>
25
                <dependency>
26
                    <code-name-base>org.openide.awt</code-name-base>
17
                    <code-name-base>org.openide.awt</code-name-base>
27
                    <build-prerequisite/>
18
                    <build-prerequisite/>
28
                    <compile-dependency/>
19
                    <compile-dependency/>
(-)a/cnd.utils/src/org/netbeans/modules/cnd/utils/filters/CndOpenFileDialogFilter.java (-16 / +13 lines)
Lines 45-53 Link Here
45
import java.util.ArrayList;
45
import java.util.ArrayList;
46
import java.util.List;
46
import java.util.List;
47
import java.util.StringTokenizer;
47
import java.util.StringTokenizer;
48
import org.netbeans.modules.cnd.utils.FileFilterFactory;
48
import javax.swing.filechooser.FileFilter;
49
import org.netbeans.modules.cnd.utils.FileFilterFactory.AbstractFileAndFileObjectFilter;
49
import org.netbeans.modules.cnd.utils.FileFilterFactory.AbstractFileAndFileObjectFilter;
50
import org.netbeans.modules.openfile.OpenFileDialogFilter;
50
import org.openide.filesystems.FileFilterSupport;
51
import org.openide.util.lookup.ServiceProvider;
51
import org.openide.util.lookup.ServiceProvider;
52
52
53
/**
53
/**
Lines 77-140 Link Here
77
        return res.toArray(new String[res.size()]);
77
        return res.toArray(new String[res.size()]);
78
    }
78
    }
79
79
80
    private static class Adapter extends OpenFileDialogFilter {
80
    private static class Adapter extends FileFilter {
81
        private AbstractFileAndFileObjectFilter delegate;
81
        private AbstractFileAndFileObjectFilter delegate;
82
        public Adapter(AbstractFileAndFileObjectFilter delegate) {
82
        public Adapter(AbstractFileAndFileObjectFilter delegate) {
83
            this.delegate = delegate;
83
            this.delegate = delegate;
84
        }
84
        }
85
85
86
        @Override
86
        @Override
87
        public String getDescriptionString() {
88
            return CndOpenFileDialogFilter.convertDescription(delegate.getDescription());
89
        }
90
91
        @Override
92
        public boolean accept(File file) {
87
        public boolean accept(File file) {
93
            return delegate.accept(file);
88
            return delegate.accept(file);
94
        }
89
        }
95
90
96
        @Override
91
        @Override
97
        public String[] getSuffixes() {
92
        public String getDescription() {
98
            return CndOpenFileDialogFilter.convertSuffixes(delegate.getSuffixesAsString());
93
            return FileFilterSupport.constructFilterDisplayName(
94
                    convertDescription(delegate.getDescription()),
95
                    convertSuffixes(delegate.getSuffixesAsString()));
99
        }
96
        }
100
    }
97
    }
101
98
102
    @ServiceProvider(service = org.netbeans.modules.openfile.OpenFileDialogFilter.class)
99
    @ServiceProvider(service = FileFilter.class, path=FileFilterSupport.FILE_FILTER_LOOKUP_PATH)
103
    public static final class CFilter extends Adapter {
100
    public static final class CFilter extends Adapter {
104
        public CFilter() {
101
        public CFilter() {
105
            super(CSourceFileFilter.getInstance());
102
            super(CSourceFileFilter.getInstance());
106
        }
103
        }
107
    }
104
    }
108
105
109
    @ServiceProvider(service = org.netbeans.modules.openfile.OpenFileDialogFilter.class)
106
    @ServiceProvider(service = FileFilter.class, path=FileFilterSupport.FILE_FILTER_LOOKUP_PATH)
110
    public static final class CppFilter extends Adapter {
107
    public static final class CppFilter extends Adapter {
111
        public CppFilter() {
108
        public CppFilter() {
112
            super(CCSourceFileFilter.getInstance());
109
            super(CCSourceFileFilter.getInstance());
113
        }
110
        }
114
    }
111
    }
115
112
116
    @ServiceProvider(service = org.netbeans.modules.openfile.OpenFileDialogFilter.class)
113
    @ServiceProvider(service = FileFilter.class, path=FileFilterSupport.FILE_FILTER_LOOKUP_PATH)
117
    public static final class HeaderFilter extends Adapter {
114
    public static final class HeaderFilter extends Adapter {
118
        public HeaderFilter() {
115
        public HeaderFilter() {
119
            super(HeaderSourceFileFilter.getInstance());
116
            super(HeaderSourceFileFilter.getInstance());
120
        }
117
        }
121
    }
118
    }
122
119
123
    @ServiceProvider(service = org.netbeans.modules.openfile.OpenFileDialogFilter.class)
120
    @ServiceProvider(service = FileFilter.class, path=FileFilterSupport.FILE_FILTER_LOOKUP_PATH)
124
    public static final class FortranFilter extends Adapter {
121
    public static final class FortranFilter extends Adapter {
125
        public FortranFilter() {
122
        public FortranFilter() {
126
            super(FortranSourceFileFilter.getInstance());
123
            super(FortranSourceFileFilter.getInstance());
127
        }
124
        }
128
    }
125
    }
129
126
130
    @ServiceProvider(service = org.netbeans.modules.openfile.OpenFileDialogFilter.class)
127
    @ServiceProvider(service = FileFilter.class, path=FileFilterSupport.FILE_FILTER_LOOKUP_PATH)
131
    public static final class ResourceFilter extends Adapter {
128
    public static final class ResourceFilter extends Adapter {
132
        public ResourceFilter() {
129
        public ResourceFilter() {
133
            super(ResourceFileFilter.getInstance());
130
            super(ResourceFileFilter.getInstance());
134
        }
131
        }
135
    }
132
    }
136
133
137
    @ServiceProvider(service = org.netbeans.modules.openfile.OpenFileDialogFilter.class)
134
    @ServiceProvider(service = FileFilter.class, path=FileFilterSupport.FILE_FILTER_LOOKUP_PATH)
138
    public static final class QtFilter extends Adapter {
135
    public static final class QtFilter extends Adapter {
139
        public QtFilter() {
136
        public QtFilter() {
140
            super(QtFileFilter.getInstance());
137
            super(QtFileFilter.getInstance());
(-)a/java.source/nbproject/project.xml (-1 / +1 lines)
Lines 343-349 Link Here
343
                    <build-prerequisite/>
343
                    <build-prerequisite/>
344
                    <compile-dependency/>
344
                    <compile-dependency/>
345
                    <run-dependency>
345
                    <run-dependency>
346
                        <specification-version>7.58</specification-version>
346
                        <specification-version>7.64</specification-version>
347
                    </run-dependency>
347
                    </run-dependency>
348
                </dependency>
348
                </dependency>
349
                <dependency>
349
                <dependency>
(-)a/java.source/src/org/netbeans/modules/java/JavaOpenFileDialogFilter.java (+68 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2012 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2012 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.java;
43
44
import java.io.File;
45
import javax.swing.filechooser.FileFilter;
46
import org.openide.filesystems.FileFilterSupport;
47
import static org.openide.filesystems.FileFilterSupport.FILE_FILTER_LOOKUP_PATH;
48
import org.openide.util.lookup.ServiceProvider;
49
50
/**
51
 * Open File Dialog filter for Java files.
52
 *
53
 * @author jhavlin
54
 */
55
@ServiceProvider(service = FileFilter.class, path = FILE_FILTER_LOOKUP_PATH)
56
public class JavaOpenFileDialogFilter extends FileFilter {
57
58
    @Override
59
    public String getDescription() {
60
        return FileFilterSupport.constructFilterDisplayName(
61
                "text/x-java");                                         //NOI18N
62
    }
63
64
    @Override
65
    public boolean accept(File file) {
66
        return FileFilterSupport.accept(file, "text/x-java");           //NOI18N
67
    }
68
}
(-)a/openide.filesystems/apichanges.xml (+13 lines)
Lines 49-54 Link Here
49
        <apidef name="filesystems">Filesystems API</apidef>
49
        <apidef name="filesystems">Filesystems API</apidef>
50
    </apidefs>
50
    </apidefs>
51
    <changes>
51
    <changes>
52
        <change id="FileFilterSupport">
53
            <api name="filesystems"/>
54
            <summary>FileFilterSupport added.</summary>
55
            <date day="1" month="8" year="2012"/>
56
            <author login="jhavlin"/>
57
            <compatibility addition="yes" binary="compatible" source="compatible" deprecation="no" semantic="compatible" modification="no" deletion="no"/>
58
            <description>
59
                Added class FileFilterSupport, that is helpful when implementing
60
                custom file filters for Open File dialog.
61
            </description>
62
            <class package="org.openide.filesystems" name="FileFilterSupport"/>
63
            <issue number="209998"/>
64
        </change>
52
        <change id="recursive-listener-with-filter">
65
        <change id="recursive-listener-with-filter">
53
            <api name="filesystems"/>
66
            <api name="filesystems"/>
54
            <summary>addRecursiveListener with a filter</summary>
67
            <summary>addRecursiveListener with a filter</summary>
(-)a/openide.filesystems/manifest.mf (-1 / +1 lines)
Lines 2-6 Link Here
2
OpenIDE-Module: org.openide.filesystems
2
OpenIDE-Module: org.openide.filesystems
3
OpenIDE-Module-Localizing-Bundle: org/openide/filesystems/Bundle.properties
3
OpenIDE-Module-Localizing-Bundle: org/openide/filesystems/Bundle.properties
4
OpenIDE-Module-Layer: org/openide/filesystems/resources/layer.xml
4
OpenIDE-Module-Layer: org/openide/filesystems/resources/layer.xml
5
OpenIDE-Module-Specification-Version: 7.63
5
OpenIDE-Module-Specification-Version: 7.64
6
6
(-)a/openide.filesystems/src/org/openide/filesystems/FileFilterSupport.java (+220 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2012 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2012 Sun Microsystems, Inc.
41
 */
42
package org.openide.filesystems;
43
44
import java.io.File;
45
import java.io.FileFilter;
46
import java.util.Arrays;
47
import java.util.Collections;
48
import java.util.List;
49
import java.util.logging.Level;
50
import java.util.logging.Logger;
51
52
/**
53
 * Support methods for {@link FileFilter file filters} that can be used, for
54
 * example, in Open File dialog. <p> See issue #209998. </p> <p> The following
55
 * example shows how to implement and register a custom filter. </p>
56
 * <pre>
57
 * {@literal
58
 *
59
 * @}{@code ServiceProvider(service=FileFilter.class, path=FileFilterSupport.FILE_FILTER_LOOKUP_PATH)
60
 * public class TXTFilter extends FileFilter {
61
 *   private static final String[] EXTENSIONS = new String[] {".txt"};
62
 *
63
 *   public boolean accept(File f) {
64
 *     return FileFilterSupport.accept(f, EXTENSIONS);
65
 *   }
66
 *
67
 *   public String getDescription() {
68
 *     return FileFilterSupport.constructFilterDisplayName(<bundle-lookup>, EXTENSIONS);
69
 *   }
70
 * }}
71
 * </pre>
72
 *
73
 * @author jhavlin, jlahoda
74
 * @since 7.49
75
 */
76
public final class FileFilterSupport {
77
78
    /**
79
     * Path to use when registering custom filters.
80
     */
81
    public static final String FILE_FILTER_LOOKUP_PATH =
82
            "OpenFileDialogFilter";                                     //NOI18N
83
    /**
84
     * The logger.
85
     */
86
    private static final Logger LOG = Logger.getLogger(
87
            FileFilterSupport.class.getName());
88
89
    /**
90
     * Hide the default constructor.
91
     */
92
    private FileFilterSupport() {
93
    }
94
95
    /**
96
     * Construct description for {@link FileFilter} that accepts files with
97
     * specified extension.
98
     *
99
     * @param displayName Human readable display name (e.g. "HTML files")
100
     * @param extensions List of allowed extensions (e.g. {".htm", ".html"}).
101
     *
102
     * @return Display name (description) for the filter.
103
     */
104
    public static String constructFilterDisplayName(String displayName,
105
            String... extensions) {
106
        StringBuilder sb = new StringBuilder(displayName);
107
        sb.append(" ");                                                 //NOI18N
108
        sb.append(Arrays.asList(extensions).toString());
109
        return sb.toString();
110
    }
111
112
    /**
113
     * Construct description for {@link FileFilter} that accepts files of
114
     * specified MIME type.
115
     *
116
     * @param mimeType MIME type of the file filter.
117
     *
118
     * @return Display name (description) for the filter.
119
     *
120
     */
121
    public static String constructFilterDisplayName(String mimeType) {
122
        return constructFilterDisplayName(getMimeDisplayName(mimeType),
123
                toExtArray(FileUtil.getMIMETypeExtensions(mimeType)));
124
    }
125
126
    /**
127
     * Check whether passed file is accepted by filter for specified list of
128
     * extensions.
129
     *
130
     * @param file File whose extension is checked.
131
     * @param extensions List of allowed extensions.
132
     *
133
     * @return True if the file ends with one of allowed extensions, false
134
     * otherwise.
135
     *
136
     * @see FileFilterSupport
137
     */
138
    public static boolean accept(File file, String... extensions) {
139
        if (file != null) {
140
            if (file.isDirectory()) {
141
                return true;
142
            }
143
            for (String ext : extensions) {
144
                if (compareSuffixes(file.getName(), ext)) {
145
                    return true;
146
                }
147
            }
148
        }
149
        return false;
150
    }
151
152
    /**
153
     * Check whether passed file is accepted by filter for specified MIME type.
154
     *
155
     * @param file File that is checked for a MIME type.
156
     * @param mimeType Accepted MIME type.
157
     *
158
     * @return True if file {@code file} is of MIME type {@code mimeType}, false
159
     * otherwise.
160
     *
161
     * @see FileFilterSupport
162
     */
163
    public static boolean accept(File file, String mimeType) {
164
        List<String> exts = FileUtil.getMIMETypeExtensions(mimeType);
165
        return accept(file, toExtArray(exts));
166
    }
167
168
    /**
169
     * Get display name for a MIME type.
170
     *
171
     * @param mimeType MIME type (e.g. "java").
172
     * @return Display name for the MIME type (e.g. "Java Files"), or the MIME
173
     * type itself if no display name has been set.
174
     */
175
    private static String getMimeDisplayName(String mimeType) {
176
        try {
177
            FileObject factoriesFO = FileUtil.getConfigFile(
178
                    "Loaders/" + mimeType + "/Factories");               //NOI18N
179
            if (factoriesFO != null) {
180
                FileObject[] children = factoriesFO.getChildren();
181
                for (FileObject child : children) {
182
                    String childName = child.getNameExt();
183
                    String displayName = FileUtil.getConfigRoot().
184
                            getFileSystem().getStatus().
185
                            annotateName(childName,
186
                            Collections.singleton(child));
187
                    if (!childName.equals(displayName)) {
188
                        return displayName;
189
                    }
190
                }
191
            }
192
        } catch (Exception e) {
193
            LOG.log(Level.WARNING, null, e);
194
        }
195
        return mimeType;
196
    }
197
198
    /**
199
     * Check whether the given filename has required suffex.
200
     */
201
    private static boolean compareSuffixes(String fileName, String suffix) {
202
        return fileName.toUpperCase().endsWith(suffix.toUpperCase());
203
    }
204
205
    /**
206
     * Convert a list of strings to a string array.
207
     *
208
     * @param listOfStrings List of extensions, without starting perios (e.g.
209
     * "txt", "java").
210
     * @return Array of extensions, with starting period (e.g. ".txt", ".java").
211
     */
212
    private static String[] toExtArray(List<String> listOfStrings) {
213
        String[] array = new String[listOfStrings.size()];
214
        int index = 0;
215
        for (String ext : listOfStrings) {
216
            array[index++] = "." + ext;                                //NOI18N
217
        }
218
        return array;
219
    }
220
}
(-)a/openide.filesystems/test/unit/src/org/openide/filesystems/FileFilterSupportTest.java (+92 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2012 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2012 Sun Microsystems, Inc.
41
 */
42
package org.openide.filesystems;
43
44
import java.io.File;
45
import javax.swing.filechooser.FileFilter;
46
import static org.junit.Assert.*;
47
import org.junit.Test;
48
49
/**
50
 * Test default implementation of OpenFileDialogFilter.
51
 *
52
 * @author jhavlin
53
 */
54
public class FileFilterSupportTest {
55
56
    private final FileFilter filter = new FileFilterImpl();
57
58
    public FileFilterSupportTest() {
59
    }
60
61
    @Test
62
    public void testAccept() {
63
        assertTrue(filter.accept(new File("test.xyz")));
64
        assertTrue(filter.accept(new File("test.XYZ")));
65
        assertTrue(filter.accept(new File("test.uvw")));
66
        assertTrue(filter.accept(new File("test.UVW")));
67
        assertFalse(filter.accept(new File("test.java")));
68
    }
69
70
    @Test
71
    public void testGetDescription() {
72
        assertEquals(
73
                "Custom Example Files [.xyz, .uvw]",
74
                filter.getDescription());
75
    }
76
77
    private static class FileFilterImpl extends FileFilter {
78
79
        private static final String[] EXTENSIONS = new String[]{".xyz", ".uvw"};
80
81
        @Override
82
        public String getDescription() {
83
            return FileFilterSupport.constructFilterDisplayName(
84
                    "Custom Example Files", EXTENSIONS);
85
        }
86
87
        @Override
88
        public boolean accept(File f) {
89
            return FileFilterSupport.accept(f, EXTENSIONS);
90
        }
91
    }
92
}
(-)a/utilities/nbproject/project.xml (-3 / +1 lines)
Lines 96-102 Link Here
96
                    <build-prerequisite/>
96
                    <build-prerequisite/>
97
                    <compile-dependency/>
97
                    <compile-dependency/>
98
                    <run-dependency>
98
                    <run-dependency>
99
                        <specification-version>7.58</specification-version>
99
                        <specification-version>7.64</specification-version>
100
                    </run-dependency>
100
                    </run-dependency>
101
                </dependency>
101
                </dependency>
102
                <dependency>
102
                <dependency>
Lines 182-192 Link Here
182
                </test-type>
182
                </test-type>
183
            </test-dependencies>
183
            </test-dependencies>
184
            <friend-packages>
184
            <friend-packages>
185
                <friend>org.netbeans.modules.cnd.utils</friend>
186
                <friend>org.netbeans.modules.utilities.project</friend>
185
                <friend>org.netbeans.modules.utilities.project</friend>
187
                <friend>org.netbeans.modules.visualweb.gravy</friend>
186
                <friend>org.netbeans.modules.visualweb.gravy</friend>
188
                <package>org.netbeans.modules.openfile</package>
187
                <package>org.netbeans.modules.openfile</package>
189
                <package>org.netbeans.modules.search</package>
190
            </friend-packages>
188
            </friend-packages>
191
        </data>
189
        </data>
192
    </configuration>
190
    </configuration>
(-)a/utilities/src/org/netbeans/modules/openfile/Bundle.properties (-1 lines)
Lines 41-47 Link Here
41
# made subject to such option by the copyright holder.
41
# made subject to such option by the copyright holder.
42
42
43
# OpenFileDialogFilter
43
# OpenFileDialogFilter
44
OFDFD_Java=Java Files
45
OFDFD_Txt=Text Files
44
OFDFD_Txt=Text Files
46
45
47
# OpenFileAction
46
# OpenFileAction
(-)a/utilities/src/org/netbeans/modules/openfile/FileChooser.java (-23 / +20 lines)
Lines 52-62 Link Here
52
import javax.swing.JLabel;
52
import javax.swing.JLabel;
53
import javax.swing.JPanel;
53
import javax.swing.JPanel;
54
import javax.swing.filechooser.FileFilter;
54
import javax.swing.filechooser.FileFilter;
55
import javax.swing.filechooser.FileNameExtensionFilter;
56
import org.openide.DialogDisplayer;
55
import org.openide.DialogDisplayer;
57
import org.openide.NotifyDescriptor;
56
import org.openide.NotifyDescriptor;
57
import org.openide.filesystems.FileFilterSupport;
58
import static org.openide.filesystems.FileFilterSupport.FILE_FILTER_LOOKUP_PATH;
58
import org.openide.util.Lookup;
59
import org.openide.util.Lookup;
59
import org.openide.util.NbBundle;
60
import org.openide.util.NbBundle;
61
import org.openide.util.lookup.Lookups;
60
import org.openide.util.lookup.ServiceProvider;
62
import org.openide.util.lookup.ServiceProvider;
61
63
62
/**
64
/**
Lines 83-90 Link Here
83
     * @see javax.swing.JFileChooser
85
     * @see javax.swing.JFileChooser
84
     */
86
     */
85
    public void addChoosableFileFilters() {
87
    public void addChoosableFileFilters() {
86
        for (OpenFileDialogFilter f :
88
        // Add legacy filters
87
                    Lookup.getDefault().lookupAll(OpenFileDialogFilter.class)) {
89
        for (org.netbeans.modules.openfile.OpenFileDialogFilter f :
90
                Lookup.getDefault().lookupAll(
91
                org.netbeans.modules.openfile.OpenFileDialogFilter.class)) {
92
            addChoosableFileFilter(f);
93
        }
94
        Lookup lkp = Lookups.forPath(FileFilterSupport.FILE_FILTER_LOOKUP_PATH);
95
        for (FileFilter f : lkp.lookupAll(FileFilter.class)) {
88
            addChoosableFileFilter(f);
96
            addChoosableFileFilter(f);
89
        }
97
        }
90
    }
98
    }
Lines 130-162 Link Here
130
        }
138
        }
131
    }
139
    }
132
140
141
    @ServiceProvider(service = FileFilter.class, path = FILE_FILTER_LOOKUP_PATH)
142
    public static class TxtFileFilter extends FileFilter {
133
143
134
    @ServiceProvider(service=org.netbeans.modules.openfile.OpenFileDialogFilter.class)
144
        private static final String[] EXTENSIONS = new String[]{".txt"};//NOI18N
135
    public static class JavaFilesFilter extends OpenFileDialogFilter {
136
145
137
        @Override
146
        @Override
138
        public String getDescriptionString() {
147
        public boolean accept(File f) {
139
            return NbBundle.getMessage(getClass(), "OFDFD_Java"); // NOI18N
148
            return FileFilterSupport.accept(f, EXTENSIONS);
140
        }
149
        }
141
150
142
        @Override
151
        @Override
143
        public String[] getSuffixes() {
152
        public String getDescription() {
144
            return new String[] {".java"};
153
            return FileFilterSupport.constructFilterDisplayName(
154
                    NbBundle.getMessage(getClass(), "OFDFD_Txt"), //NOI18N
155
                    EXTENSIONS);
145
        }
156
        }
146
147
    }
148
149
    @ServiceProvider(service=OpenFileDialogFilter.class)
150
    public static class TxtFileFilter
151
            extends OpenFileDialogFilter.ExtensionFilter {
152
153
        @Override
154
        public FileNameExtensionFilter getFilter() {
155
            return new FileNameExtensionFilter(
156
                            NbBundle.getMessage(getClass(), "OFDFD_Txt"),
157
                            "txt"); // NOI18N
158
        }
159
160
    } // End of TxtFileFilter
157
    } // End of TxtFileFilter
161
158
162
}
159
}
(-)a/utilities/src/org/netbeans/modules/openfile/OpenFileDialogFilter.java (+6 lines)
Lines 47-52 Link Here
47
import java.util.Arrays;
47
import java.util.Arrays;
48
import javax.swing.filechooser.FileFilter;
48
import javax.swing.filechooser.FileFilter;
49
import javax.swing.filechooser.FileNameExtensionFilter;
49
import javax.swing.filechooser.FileNameExtensionFilter;
50
import org.openide.filesystems.FileFilterSupport;
50
51
51
/**
52
/**
52
 * {@code OpenFileDialogFilter} is an abstract class used by {@link FileChooser}
53
 * {@code OpenFileDialogFilter} is an abstract class used by {@link FileChooser}
Lines 107-113 Link Here
107
 * @see OpenFileDialogFilter.ExtensionFilter
108
 * @see OpenFileDialogFilter.ExtensionFilter
108
 *
109
 *
109
 * @author Victor G. Vasilyev <vvg@netbeans.org>
110
 * @author Victor G. Vasilyev <vvg@netbeans.org>
111
 *
112
 * @deprecated Use {@link FileFilter} and {@link FileFilterSupport}.
110
 */
113
 */
114
@Deprecated
111
public abstract class OpenFileDialogFilter extends FileFilter {
115
public abstract class OpenFileDialogFilter extends FileFilter {
112
116
113
    /**
117
    /**
Lines 258-264 Link Here
258
     * @see OpenFileDialogFilter
262
     * @see OpenFileDialogFilter
259
     * @see FileNameExtensionFilter
263
     * @see FileNameExtensionFilter
260
     *
264
     *
265
     * @deprecated Use {@link FileFilter} and {@link FileFilterSupport}.
261
     */
266
     */
267
    @Deprecated
262
    public static abstract class ExtensionFilter extends OpenFileDialogFilter {
268
    public static abstract class ExtensionFilter extends OpenFileDialogFilter {
263
269
264
        private static final char EXTENSION_SEPARATOR = '.';
270
        private static final char EXTENSION_SEPARATOR = '.';

Return to bug 209998