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.script/nbproject/project.xml (-1 / +1 lines)
Lines 150-156 Link Here
150
                    <build-prerequisite/>
150
                    <build-prerequisite/>
151
                    <compile-dependency/>
151
                    <compile-dependency/>
152
                    <run-dependency>
152
                    <run-dependency>
153
                        <specification-version>7.33</specification-version>
153
                        <specification-version>8.1</specification-version>
154
                    </run-dependency>
154
                    </run-dependency>
155
                </dependency>
155
                </dependency>
156
                <dependency>
156
                <dependency>
(-)a/cnd.script/src/org/netbeans/modules/cnd/makefile/loaders/Bundle.properties (+1 lines)
Line 0 Link Here
1
MakeResolver=Makefiles
(-)a/cnd.script/src/org/netbeans/modules/cnd/makefile/loaders/MakefileDataObject.java (+6 lines)
Lines 55-60 Link Here
55
import org.netbeans.modules.cnd.builds.MakeExecSupport;
55
import org.netbeans.modules.cnd.builds.MakeExecSupport;
56
import org.netbeans.modules.cnd.makefile.parser.MakefileTargetProviderImpl;
56
import org.netbeans.modules.cnd.makefile.parser.MakefileTargetProviderImpl;
57
import org.netbeans.modules.cnd.utils.MIMENames;
57
import org.netbeans.modules.cnd.utils.MIMENames;
58
import org.openide.filesystems.MIMEResolver;
58
import org.openide.loaders.MultiDataObject;
59
import org.openide.loaders.MultiDataObject;
59
import org.openide.util.Lookup;
60
import org.openide.util.Lookup;
60
import org.openide.util.NbBundle.Messages;
61
import org.openide.util.NbBundle.Messages;
Lines 63-68 Link Here
63
/**
64
/**
64
 *  Represents a Makefile object in the Repository.
65
 *  Represents a Makefile object in the Repository.
65
 */
66
 */
67
@MIMEResolver.Registration(
68
        displayName="#MakeResolver",
69
        position=139,
70
        resource="../../script/resources/mime-resolver-make.xml",
71
        showInFileChooser="#MakeResolver")
66
public class MakefileDataObject extends MultiDataObject {
72
public class MakefileDataObject extends MultiDataObject {
67
73
68
    /** Serial version number */
74
    /** Serial version number */
(-)a/cnd.script/src/org/netbeans/modules/cnd/script/resources/mime-resolver.xml (-39 lines)
Lines 23-65 Link Here
23
        <name name="makefile" substring="true"/>
23
        <name name="makefile" substring="true"/>
24
        <resolver mime="text/x-make"/>
24
        <resolver mime="text/x-make"/>
25
    </file>
25
    </file>
26
    <file>
27
        <ext name="sh"/>
28
        <ext name="bash"/>
29
        <ext name="csh"/>
30
        <ext name="ksh"/>
31
        <ext name="sh"/>
32
        <ext name="zsh"/>
33
        <ext name="pl"/>
34
        <resolver mime="text/sh"/>
35
    </file>
36
    <file>
37
        <!-- Only files without extension. -->
38
        <ext name=""/>
39
        <!-- Pattern #! in first 2 bytes and one of patterns in first 40 bytes.  -->
40
        <pattern value="#!" range="2">
41
            <pattern value="/bin/bash" range="40"/>
42
        </pattern>
43
        <pattern value="#!" range="2">
44
            <pattern value="/bin/sh" range="40"/>
45
        </pattern>
46
        <pattern value="#!" range="2">
47
            <pattern value="/sbin/sh" range="40"/>
48
        </pattern>
49
        <pattern value="#!" range="2">
50
            <pattern value="/bin/ksh" range="40"/>
51
        </pattern>
52
        <pattern value="#!" range="2">
53
            <pattern value="/bin/csh" range="40"/>
54
        </pattern>
55
        <pattern value="#!" range="2">
56
            <pattern value="/usr/bin/perl" range="40"/>
57
        </pattern>
58
        <resolver mime="text/sh"/>
59
    </file>
60
    <file>
61
        <ext name="bat"/>
62
        <ext name="cmd"/>
63
        <resolver mime="text/bat"/>
64
    </file>
65
</MIME-resolver>
26
</MIME-resolver>
(-)a/cnd.script/src/org/netbeans/modules/cnd/script/resources/mime-resolver.xml (-21 lines)
Lines 3-29 Link Here
3
        "http://www.netbeans.org/dtds/mime-resolver-1_0.dtd">
3
        "http://www.netbeans.org/dtds/mime-resolver-1_0.dtd">
4
<MIME-resolver>
4
<MIME-resolver>
5
    <file>
5
    <file>
6
        <ext name="mk"/>
7
        <resolver mime="text/x-make"/>
8
    </file>
9
    <file>
10
        <ext name=""/>
11
        <name name="makefile" substring="true"/>
12
        <resolver mime="text/x-make"/>
13
    </file>
14
    <file>
15
        <!--  configure input file-->
16
        <ext name="in"/>
17
        <name name="makefile" substring="true"/>
18
        <resolver mime="text/x-make"/>
19
    </file>
20
    <file>
21
        <!--  automake input file-->
22
        <ext name="am"/>
23
        <name name="makefile" substring="true"/>
24
        <resolver mime="text/x-make"/>
25
    </file>
26
    <file>
27
        <ext name="sh"/>
6
        <ext name="sh"/>
28
        <ext name="bash"/>
7
        <ext name="bash"/>
29
        <ext name="csh"/>
8
        <ext name="csh"/>
(-)a/cnd.source/nbproject/project.xml (-1 / +1 lines)
Lines 88-94 Link Here
88
                    <build-prerequisite/>
88
                    <build-prerequisite/>
89
                    <compile-dependency/>
89
                    <compile-dependency/>
90
                    <run-dependency>
90
                    <run-dependency>
91
                        <specification-version>7.58</specification-version>
91
                        <specification-version>8.1</specification-version>
92
                    </run-dependency>
92
                    </run-dependency>
93
                </dependency>
93
                </dependency>
94
                <dependency>
94
                <dependency>
(-)a/cnd.source/src/org/netbeans/modules/cnd/source/Bundle.properties (+5 lines)
Lines 44-46 Link Here
44
44
45
ExtResolver=C/C++/H/Fortran MIME Resolver (ext-based)
45
ExtResolver=C/C++/H/Fortran MIME Resolver (ext-based)
46
ContentResolver=H MIME Resolver (content-based)
46
ContentResolver=H MIME Resolver (content-based)
47
48
FILECHOOSER_C_SOURCES_FILEFILTER=C Source Files
49
FILECHOOSER_CC_SOURCES_FILEFILTER=C++ Source Files
50
FILECHOOSER_HEADER_SOURCES_FILEFILTER=Header Files
51
FILECHOOSER_FORTRAN_SOURCES_FILEFILTER=Fortran Source Files
(-)a/cnd.source/src/org/netbeans/modules/cnd/source/CCDataObject.java (-1 / +2 lines)
Lines 54-60 Link Here
54
import org.openide.windows.TopComponent;
54
import org.openide.windows.TopComponent;
55
55
56
/** Represents a C++ object in the Repository */
56
/** Represents a C++ object in the Repository */
57
@MIMEResolver.Registration(displayName="#ExtResolver", position=214, resource="resources/mime-resolver-ext-based.xml")
57
@MIMEResolver.Registration(displayName="#ExtResolver", position=214, resource="resources/mime-resolver-ext-based-cpp.xml",
58
        showInFileChooser={"#FILECHOOSER_CC_SOURCES_FILEFILTER"})
58
public class CCDataObject extends SourceDataObject {
59
public class CCDataObject extends SourceDataObject {
59
60
60
    @MIMEResolver.Registration(displayName="#ContentResolver", position=470, resource="resources/mime-resolver-content-based.xml")
61
    @MIMEResolver.Registration(displayName="#ContentResolver", position=470, resource="resources/mime-resolver-content-based.xml")
(-)a/cnd.source/src/org/netbeans/modules/cnd/source/CDataObject.java (-1 / +3 lines)
Lines 48-53 Link Here
48
import org.netbeans.core.spi.multiview.text.MultiViewEditorElement;
48
import org.netbeans.core.spi.multiview.text.MultiViewEditorElement;
49
import org.netbeans.modules.cnd.utils.MIMENames;
49
import org.netbeans.modules.cnd.utils.MIMENames;
50
import org.openide.filesystems.FileObject;
50
import org.openide.filesystems.FileObject;
51
import org.openide.filesystems.MIMEResolver;
51
import org.openide.loaders.DataObjectExistsException;
52
import org.openide.loaders.DataObjectExistsException;
52
import org.openide.nodes.Node;
53
import org.openide.nodes.Node;
53
import org.openide.util.Lookup;
54
import org.openide.util.Lookup;
Lines 57-63 Link Here
57
/** Represents a C++ object in the Repository.
58
/** Represents a C++ object in the Repository.
58
 *
59
 *
59
 */
60
 */
60
61
@MIMEResolver.Registration(displayName="#ExtResolver", position=214, resource="resources/mime-resolver-ext-based-c.xml",
62
        showInFileChooser={"#FILECHOOSER_C_SOURCES_FILEFILTER"})
61
public class CDataObject extends SourceDataObject {
63
public class CDataObject extends SourceDataObject {
62
64
63
    /** Serial version number */
65
    /** Serial version number */
(-)a/cnd.source/src/org/netbeans/modules/cnd/source/FortranDataObject.java (-1 / +3 lines)
Lines 48-53 Link Here
48
import org.netbeans.core.spi.multiview.text.MultiViewEditorElement;
48
import org.netbeans.core.spi.multiview.text.MultiViewEditorElement;
49
import org.netbeans.modules.cnd.utils.MIMENames;
49
import org.netbeans.modules.cnd.utils.MIMENames;
50
import org.openide.filesystems.FileObject;
50
import org.openide.filesystems.FileObject;
51
import org.openide.filesystems.MIMEResolver;
51
import org.openide.loaders.DataObjectExistsException;
52
import org.openide.loaders.DataObjectExistsException;
52
import org.openide.nodes.Node;
53
import org.openide.nodes.Node;
53
import org.openide.util.Lookup;
54
import org.openide.util.Lookup;
Lines 57-63 Link Here
57
/** Represents a Fortran object in the Repository.
58
/** Represents a Fortran object in the Repository.
58
 *
59
 *
59
 */
60
 */
60
61
@MIMEResolver.Registration(displayName="#ExtResolver", position=214, resource="resources/mime-resolver-ext-based-fortran.xml",
62
        showInFileChooser={"#FILECHOOSER_FORTRAN_SOURCES_FILEFILTER"})
61
public class FortranDataObject extends SourceDataObject {
63
public class FortranDataObject extends SourceDataObject {
62
64
63
    /** Serial version number */
65
    /** Serial version number */
(-)a/cnd.source/src/org/netbeans/modules/cnd/source/HDataObject.java (-2 / +3 lines)
Lines 49-61 Link Here
49
import org.netbeans.core.spi.multiview.text.MultiViewEditorElement;
49
import org.netbeans.core.spi.multiview.text.MultiViewEditorElement;
50
import org.netbeans.modules.cnd.utils.MIMENames;
50
import org.netbeans.modules.cnd.utils.MIMENames;
51
import org.openide.filesystems.FileObject;
51
import org.openide.filesystems.FileObject;
52
import org.openide.filesystems.MIMEResolver;
52
import org.openide.loaders.DataObjectExistsException;
53
import org.openide.loaders.DataObjectExistsException;
53
import org.openide.nodes.Node;
54
import org.openide.nodes.Node;
54
import org.openide.util.Lookup;
55
import org.openide.util.Lookup;
55
import org.openide.windows.TopComponent;
56
import org.openide.windows.TopComponent;
56
57
57
58
@MIMEResolver.Registration(displayName="#ExtResolver", position=214, resource="resources/mime-resolver-ext-based-h.xml",
58
59
        showInFileChooser={"#FILECHOOSER_HEADER_SOURCES_FILEFILTER"})
59
/** Represents a .h header object in the Repository */
60
/** Represents a .h header object in the Repository */
60
public class HDataObject extends SourceDataObject {
61
public class HDataObject extends SourceDataObject {
61
62
(-)a/cnd.source/src/org/netbeans/modules/cnd/source/resources/mime-resolver-ext-based.xml (-31 lines)
Lines 47-86 Link Here
47
		    "http://www.netbeans.org/dtds/mime-resolver-1_0.dtd">
47
		    "http://www.netbeans.org/dtds/mime-resolver-1_0.dtd">
48
<MIME-resolver >
48
<MIME-resolver >
49
    <file>
49
    <file>
50
        <ext name="h"/>
51
        <ext name="H"/>
52
        <ext name="hpp"/>
53
        <ext name="hxx"/>
54
        <ext name="SUNWCCh"/>
55
        <ext name="tcc"/>
56
        <resolver mime="text/x-h"/>
57
    </file>
58
    <file>
59
        <ext name="c"/>
50
        <ext name="c"/>
60
        <ext name="i"/>
51
        <ext name="i"/>
61
        <ext name="m"/>
52
        <ext name="m"/>
62
        <resolver mime="text/x-c"/>
53
        <resolver mime="text/x-c"/>
63
    </file>
54
    </file>
64
    <file>
65
        <ext name="cpp"/>
66
        <ext name="cc"/>
67
        <ext name="c++"/>
68
        <ext name="cxx"/>
69
        <ext name="C"/>
70
        <ext name="mm"/>
71
        <resolver mime="text/x-c++"/>
72
    </file>
73
    <file>
74
        <ext name="f"/>
75
        <ext name="F"/>
76
        <ext name="f90"/>
77
        <ext name="F90"/>
78
        <ext name="f95"/>
79
        <ext name="F95"/>
80
        <ext name="f03"/>
81
        <ext name="F03"/>
82
        <ext name="for"/>
83
        <ext name="mod"/>
84
        <resolver mime="text/x-fortran"/>
85
    </file>
86
</MIME-resolver>
55
</MIME-resolver>
(-)a/cnd.source/src/org/netbeans/modules/cnd/source/resources/mime-resolver-ext-based.xml (-28 lines)
Lines 47-67 Link Here
47
		    "http://www.netbeans.org/dtds/mime-resolver-1_0.dtd">
47
		    "http://www.netbeans.org/dtds/mime-resolver-1_0.dtd">
48
<MIME-resolver >
48
<MIME-resolver >
49
    <file>
49
    <file>
50
        <ext name="h"/>
51
        <ext name="H"/>
52
        <ext name="hpp"/>
53
        <ext name="hxx"/>
54
        <ext name="SUNWCCh"/>
55
        <ext name="tcc"/>
56
        <resolver mime="text/x-h"/>
57
    </file>
58
    <file>
59
        <ext name="c"/>
60
        <ext name="i"/>
61
        <ext name="m"/>
62
        <resolver mime="text/x-c"/>
63
    </file>
64
    <file>
65
        <ext name="cpp"/>
50
        <ext name="cpp"/>
66
        <ext name="cc"/>
51
        <ext name="cc"/>
67
        <ext name="c++"/>
52
        <ext name="c++"/>
Lines 70-86 Link Here
70
        <ext name="mm"/>
55
        <ext name="mm"/>
71
        <resolver mime="text/x-c++"/>
56
        <resolver mime="text/x-c++"/>
72
    </file>
57
    </file>
73
    <file>
74
        <ext name="f"/>
75
        <ext name="F"/>
76
        <ext name="f90"/>
77
        <ext name="F90"/>
78
        <ext name="f95"/>
79
        <ext name="F95"/>
80
        <ext name="f03"/>
81
        <ext name="F03"/>
82
        <ext name="for"/>
83
        <ext name="mod"/>
84
        <resolver mime="text/x-fortran"/>
85
    </file>
86
</MIME-resolver>
58
</MIME-resolver>
(-)a/cnd.source/src/org/netbeans/modules/cnd/source/resources/mime-resolver-ext-based.xml (-24 lines)
Lines 47-76 Link Here
47
		    "http://www.netbeans.org/dtds/mime-resolver-1_0.dtd">
47
		    "http://www.netbeans.org/dtds/mime-resolver-1_0.dtd">
48
<MIME-resolver >
48
<MIME-resolver >
49
    <file>
49
    <file>
50
        <ext name="h"/>
51
        <ext name="H"/>
52
        <ext name="hpp"/>
53
        <ext name="hxx"/>
54
        <ext name="SUNWCCh"/>
55
        <ext name="tcc"/>
56
        <resolver mime="text/x-h"/>
57
    </file>
58
    <file>
59
        <ext name="c"/>
60
        <ext name="i"/>
61
        <ext name="m"/>
62
        <resolver mime="text/x-c"/>
63
    </file>
64
    <file>
65
        <ext name="cpp"/>
66
        <ext name="cc"/>
67
        <ext name="c++"/>
68
        <ext name="cxx"/>
69
        <ext name="C"/>
70
        <ext name="mm"/>
71
        <resolver mime="text/x-c++"/>
72
    </file>
73
    <file>
74
        <ext name="f"/>
50
        <ext name="f"/>
75
        <ext name="F"/>
51
        <ext name="F"/>
76
        <ext name="f90"/>
52
        <ext name="f90"/>
(-)a/cnd.source/src/org/netbeans/modules/cnd/source/resources/mime-resolver-ext-based.xml (-28 lines)
Lines 55-86 Link Here
55
        <ext name="tcc"/>
55
        <ext name="tcc"/>
56
        <resolver mime="text/x-h"/>
56
        <resolver mime="text/x-h"/>
57
    </file>
57
    </file>
58
    <file>
59
        <ext name="c"/>
60
        <ext name="i"/>
61
        <ext name="m"/>
62
        <resolver mime="text/x-c"/>
63
    </file>
64
    <file>
65
        <ext name="cpp"/>
66
        <ext name="cc"/>
67
        <ext name="c++"/>
68
        <ext name="cxx"/>
69
        <ext name="C"/>
70
        <ext name="mm"/>
71
        <resolver mime="text/x-c++"/>
72
    </file>
73
    <file>
74
        <ext name="f"/>
75
        <ext name="F"/>
76
        <ext name="f90"/>
77
        <ext name="F90"/>
78
        <ext name="f95"/>
79
        <ext name="F95"/>
80
        <ext name="f03"/>
81
        <ext name="F03"/>
82
        <ext name="for"/>
83
        <ext name="mod"/>
84
        <resolver mime="text/x-fortran"/>
85
    </file>
86
</MIME-resolver>
58
</MIME-resolver>
(-)a/cnd/nbproject/project.xml (-1 / +1 lines)
Lines 163-169 Link Here
163
                    <build-prerequisite/>
163
                    <build-prerequisite/>
164
                    <compile-dependency/>
164
                    <compile-dependency/>
165
                    <run-dependency>
165
                    <run-dependency>
166
                        <specification-version>7.58</specification-version>
166
                        <specification-version>8.1</specification-version>
167
                    </run-dependency>
167
                    </run-dependency>
168
                </dependency>
168
                </dependency>
169
                <dependency>
169
                <dependency>
(-)a/cnd/src/org/netbeans/modules/cnd/loaders/Bundle.properties (+1 lines)
Lines 80-84 Link Here
80
Source=&Source
80
Source=&Source
81
81
82
NameExtResolver=C Make Files
82
NameExtResolver=C Make Files
83
QtNameExtResolver=Qt Files
83
ExtBasedResolver=Common C/C++ Extensions
84
ExtBasedResolver=Common C/C++ Extensions
84
HexBasedResolver=Magic C/C++ Headers
85
HexBasedResolver=Magic C/C++ Headers
(-)a/cnd/src/org/netbeans/modules/cnd/loaders/QtProjectDataObject.java (+7 lines)
Lines 47-52 Link Here
47
import org.netbeans.modules.cnd.builds.QMakeExecSupport;
47
import org.netbeans.modules.cnd.builds.QMakeExecSupport;
48
import org.netbeans.modules.cnd.utils.MIMENames;
48
import org.netbeans.modules.cnd.utils.MIMENames;
49
import org.openide.filesystems.FileObject;
49
import org.openide.filesystems.FileObject;
50
import org.openide.filesystems.MIMEResolver;
50
import org.openide.loaders.DataNode;
51
import org.openide.loaders.DataNode;
51
import org.openide.loaders.DataObjectExistsException;
52
import org.openide.loaders.DataObjectExistsException;
52
import org.openide.loaders.MultiDataObject;
53
import org.openide.loaders.MultiDataObject;
Lines 61-66 Link Here
61
/**
62
/**
62
 * @author Alexey Vladykin
63
 * @author Alexey Vladykin
63
 */
64
 */
65
@MIMEResolver.Registration(
66
    displayName = "#QtNameExtResolver", // NOI18N
67
    position = 215,
68
    resource = "../resources/mime-resolver-ext-based-qt.xml", // NOI18N
69
    showInFileChooser={"#QtNameExtResolver"}
70
)
64
public class QtProjectDataObject extends MultiDataObject {
71
public class QtProjectDataObject extends MultiDataObject {
65
72
66
    public QtProjectDataObject(FileObject pf, MultiFileLoader loader) throws DataObjectExistsException, IOException {
73
    public QtProjectDataObject(FileObject pf, MultiFileLoader loader) throws DataObjectExistsException, IOException {
(-)a/cnd/src/org/netbeans/modules/cnd/resources/mime-resolver-ext-based.xml (-33 lines)
Lines 48-82 Link Here
48
48
49
<MIME-resolver >
49
<MIME-resolver >
50
    <file>
50
    <file>
51
        <ext name="exe"/>
52
        <resolver mime="application/x-exe"/>
53
    </file>
54
    <file>
55
        <ext name="dll"/>
56
        <resolver mime="application/x-shobj+elf"/>
57
    </file>
58
    <file>
59
        <ext name="o"/>
60
        <resolver mime="application/x-object+elf"/>
61
    </file>
62
    <file>
63
        <ext name="so"/>
64
        <resolver mime="application/x-shobj+elf"/>
65
    </file>    
66
    <file>
67
        <ext name="dylib"/>
68
        <resolver mime="application/x-shobj+elf"/>
69
    </file>
70
    <file>
71
        <ext name="a"/>
72
        <resolver mime="application/x-stobj+elf"/>
73
    </file>
74
    <file>
75
        <ext name=""/>
76
        <name name="core" substring="false"/>
77
        <resolver mime="application/x-core+elf"/>
78
    </file>
79
    <file>
80
        <ext name="ui"/>
51
        <ext name="ui"/>
81
        <resolver mime="text/qtui+xml"/>
52
        <resolver mime="text/qtui+xml"/>
82
    </file>
53
    </file>
Lines 92-99 Link Here
92
        <ext name="pro"/>
63
        <ext name="pro"/>
93
        <resolver mime="text/x-qtproject"/>
64
        <resolver mime="text/x-qtproject"/>
94
    </file>
65
    </file>
95
    <file>
96
        <ext name="cmake"/>
97
        <resolver mime="text/x-cmake-include"/>
98
    </file>
99
</MIME-resolver>
66
</MIME-resolver>
(-)a/cnd/src/org/netbeans/modules/cnd/resources/mime-resolver-ext-based.xml (-16 lines)
Lines 77-98 Link Here
77
        <resolver mime="application/x-core+elf"/>
77
        <resolver mime="application/x-core+elf"/>
78
    </file>
78
    </file>
79
    <file>
79
    <file>
80
        <ext name="ui"/>
81
        <resolver mime="text/qtui+xml"/>
82
    </file>
83
    <file>
84
        <ext name="qrc"/>
85
        <resolver mime="text/qtresource+xml"/>
86
    </file>
87
    <file>
88
        <ext name="ts"/>
89
        <resolver mime="text/qttranslation+xml"/>
90
    </file>
91
    <file>
92
        <ext name="pro"/>
93
        <resolver mime="text/x-qtproject"/>
94
    </file>
95
    <file>
96
        <ext name="cmake"/>
80
        <ext name="cmake"/>
97
        <resolver mime="text/x-cmake-include"/>
81
        <resolver mime="text/x-cmake-include"/>
98
    </file>
82
    </file>
(-)a/core.ide/nbproject/project.xml (-1 / +1 lines)
Lines 76-82 Link Here
76
                    <build-prerequisite/>
76
                    <build-prerequisite/>
77
                    <compile-dependency/>
77
                    <compile-dependency/>
78
                    <run-dependency>
78
                    <run-dependency>
79
                        <specification-version>7.21</specification-version>
79
                        <specification-version>8.1</specification-version>
80
                    </run-dependency>
80
                    </run-dependency>
81
                </dependency>
81
                </dependency>
82
                <dependency>
82
                <dependency>
(-)a/core.ide/src/org/netbeans/core/ide/ServiceTabProcessor.java (-2 / +3 lines)
Lines 63-74 Link Here
63
 * processor for {@link ServiceTabNodeRegistration} annotation.
63
 * processor for {@link ServiceTabNodeRegistration} annotation.
64
 * @author Jaroslav Tulach
64
 * @author Jaroslav Tulach
65
 */
65
 */
66
@NbBundle.Messages("PlainResolver=Text Files")
66
@NbBundle.Messages({"PlainResolver=Text Files", "ResourceFiles=Resource Files"})
67
@MIMEResolver.ExtensionRegistration(
67
@MIMEResolver.ExtensionRegistration(
68
    mimeType="text/plain",
68
    mimeType="text/plain",
69
    position=140,
69
    position=140,
70
    displayName="#PlainResolver",
70
    displayName="#PlainResolver",
71
    extension={ "TXT", "txt" }
71
    extension={ "TXT", "txt" },
72
    showInFileChooser={"#PlainResolver", "#ResourceFiles"}
72
)
73
)
73
@ServiceProvider(service=Processor.class)
74
@ServiceProvider(service=Processor.class)
74
@SupportedSourceVersion(SourceVersion.RELEASE_6)
75
@SupportedSourceVersion(SourceVersion.RELEASE_6)
(-)a/html/nbproject/project.xml (-1 / +1 lines)
Lines 221-227 Link Here
221
                    <build-prerequisite/>
221
                    <build-prerequisite/>
222
                    <compile-dependency/>
222
                    <compile-dependency/>
223
                    <run-dependency>
223
                    <run-dependency>
224
                        <specification-version>7.58</specification-version>
224
                        <specification-version>8.1</specification-version>
225
                    </run-dependency>
225
                    </run-dependency>
226
                </dependency>
226
                </dependency>
227
                <dependency>
227
                <dependency>
(-)a/html/src/org/netbeans/modules/html/Bundle.properties (+1 lines)
Lines 66-71 Link Here
66
Templates/Other/html.html=HTML File
66
Templates/Other/html.html=HTML File
67
Templates/Other/xhtml.xhtml=XHTML File
67
Templates/Other/xhtml.xhtml=XHTML File
68
HTMLResolver=HTML and XHTML Files
68
HTMLResolver=HTML and XHTML Files
69
ResourceFiles=Resource Files
69
70
70
# HtmlEditorSupport
71
# HtmlEditorSupport
71
# {0} document name
72
# {0} document name
(-)a/html/src/org/netbeans/modules/html/HtmlDataObject.java (-1 / +2 lines)
Lines 101-107 Link Here
101
@MIMEResolver.Registration(
101
@MIMEResolver.Registration(
102
    displayName="#HTMLResolver",
102
    displayName="#HTMLResolver",
103
    position=300,
103
    position=300,
104
    resource="resolver.xml"
104
    resource="resolver.xml",
105
    showInFileChooser="#ResourceFiles"
105
)
106
)
106
public class HtmlDataObject extends MultiDataObject implements CookieSet.Factory {
107
public class HtmlDataObject extends MultiDataObject implements CookieSet.Factory {
107
    public static final String PROP_ENCODING = "Content-Encoding"; // NOI18N
108
    public static final String PROP_ENCODING = "Content-Encoding"; // NOI18N
(-)a/image/nbproject/project.xml (-1 / +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>8.1</specification-version>
100
                    </run-dependency>
100
                    </run-dependency>
101
                </dependency>
101
                </dependency>
102
                <dependency>
102
                <dependency>
(-)a/image/src/org/netbeans/modules/image/Bundle.properties (+2 lines)
Lines 106-108 Link Here
106
ACS_DecreaseText=N/A
106
ACS_DecreaseText=N/A
107
107
108
LBL_LoadingImage=Loading image...
108
LBL_LoadingImage=Loading image...
109
110
ResourceFiles=Resource Files
(-)a/image/src/org/netbeans/modules/image/ImageDataObject.java (+4 lines)
Lines 84-89 Link Here
84
        displayName="#ImageMimeResolverJPG",
84
        displayName="#ImageMimeResolverJPG",
85
        mimeType=ImageDataLoader.JPEG_MIME_TYPE,
85
        mimeType=ImageDataLoader.JPEG_MIME_TYPE,
86
        extension={"jpg", "JPG", "jpe", "JPE", "jpeg", "JPEG"},
86
        extension={"jpg", "JPG", "jpe", "JPE", "jpeg", "JPEG"},
87
        showInFileChooser={"#ResourceFiles"},
87
        position=110
88
        position=110
88
    )
89
    )
89
    @Messages("ImageMimeResolverJPG=JPEG Image Files")
90
    @Messages("ImageMimeResolverJPG=JPEG Image Files")
Lines 94-99 Link Here
94
        displayName="#ImageMimeResolverGIF",
95
        displayName="#ImageMimeResolverGIF",
95
        mimeType=ImageDataLoader.GIF_MIME_TYPE,
96
        mimeType=ImageDataLoader.GIF_MIME_TYPE,
96
        extension={"gif", "GIF"},
97
        extension={"gif", "GIF"},
98
        showInFileChooser={"#ResourceFiles"},
97
        position=111
99
        position=111
98
    )
100
    )
99
    @Messages("ImageMimeResolverGIF=GIF Image Files")
101
    @Messages("ImageMimeResolverGIF=GIF Image Files")
Lines 104-109 Link Here
104
        displayName="#ImageMimeResolverPNG",
106
        displayName="#ImageMimeResolverPNG",
105
        mimeType=ImageDataLoader.PNG_MIME_TYPE,
107
        mimeType=ImageDataLoader.PNG_MIME_TYPE,
106
        extension={"png", "PNG"},
108
        extension={"png", "PNG"},
109
        showInFileChooser={"#ResourceFiles"},
107
        position=112
110
        position=112
108
    )
111
    )
109
    @Messages("ImageMimeResolverPNG=PNG Image Files")
112
    @Messages("ImageMimeResolverPNG=PNG Image Files")
Lines 113-118 Link Here
113
        displayName="#ImageMimeResolverBMP",
116
        displayName="#ImageMimeResolverBMP",
114
        mimeType=ImageDataLoader.BMP_MIME_TYPE,
117
        mimeType=ImageDataLoader.BMP_MIME_TYPE,
115
        extension={"bmp", "BMP"},
118
        extension={"bmp", "BMP"},
119
        showInFileChooser={"#ResourceFiles"},
116
        position=113
120
        position=113
117
    )
121
    )
118
    @Messages("ImageMimeResolverBMP=BMP Image Files")
122
    @Messages("ImageMimeResolverBMP=BMP Image Files")
(-)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>8.1</specification-version>
347
                    </run-dependency>
347
                    </run-dependency>
348
                </dependency>
348
                </dependency>
349
                <dependency>
349
                <dependency>
(-)a/java.source/src/org/netbeans/modules/java/JavaDataObject.java (-2 / +3 lines)
Lines 76-83 Link Here
76
    position=100,
76
    position=100,
77
    displayName="#JavaResolver",
77
    displayName="#JavaResolver",
78
    extension="java",
78
    extension="java",
79
    mimeType="text/x-java"
79
    mimeType="text/x-java",
80
)    
80
    showInFileChooser={"#JavaResolver"}
81
)
81
public final class JavaDataObject extends MultiDataObject {
82
public final class JavaDataObject extends MultiDataObject {
82
    
83
    
83
    public JavaDataObject(FileObject pf, MultiFileLoader loader) throws DataObjectExistsException {
84
    public JavaDataObject(FileObject pf, MultiFileLoader loader) throws DataObjectExistsException {
(-)a/openide.filesystems/apichanges.xml (+23 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="FileChooserBuilder-addDefaultFileFilters">
53
            <api name="filesystems"/>
54
            <summary>New method FileChooserBuilder.addDefaultFileFilters and accompanying annotations.</summary>
55
            <version major="8" minor="1"/>
56
            <date year="2012" month="8" day="29"/>
57
            <author login="jhavlin"/>
58
            <compatibility addition="yes" deprecation="no"/>
59
            <description>
60
                <p>
61
                    Added <a href="@TOP@org/openide/filesystems/FileChooserBuilder.html#addDefaultFileFilters()">
62
                    new method</a> to <code>FileChooserBuilder</code> that adds all default
63
                    <code>FileFilter</code>s to created file chooser.
64
                </p>
65
                <p>
66
                    Default filters are registered using new parameters in annotations
67
                    <a href="@TOP@org/openide/filesystems/MIMEResolver.Registration.html#showInFileChooser()">MimeResolver.Registration</a>
68
                    and <a href="@TOP@org/openide/filesystems/MIMEResolver.ExtensionRegistration.html#showInFileChooser()">MimeResolver.ExtensionRegistration</a>.
69
                </p>
70
            </description>
71
            <class package="org.openide.filesystems" name="FileChooserBuilder"/>
72
            <class package="org.openide.filesystems" name="MIMEResolver"/>
73
            <issue number="209998"/>
74
        </change>
52
        <change id="fileobject-lookup">
75
        <change id="fileobject-lookup">
53
            <api name="filesystems"/>
76
            <api name="filesystems"/>
54
            <summary>FileObject has getLookup()</summary>
77
            <summary>FileObject has getLookup()</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: 8.0
5
OpenIDE-Module-Specification-Version: 8.1
6
6
(-)a/openide.filesystems/src/org/netbeans/modules/openide/filesystems/FileFilterSupport.java (+470 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.openide.filesystems;
43
44
import java.io.File;
45
import java.util.ArrayList;
46
import java.util.Collections;
47
import java.util.Comparator;
48
import java.util.HashMap;
49
import java.util.HashSet;
50
import java.util.LinkedList;
51
import java.util.List;
52
import java.util.Map;
53
import java.util.Set;
54
import java.util.logging.Level;
55
import java.util.logging.Logger;
56
import java.util.regex.Matcher;
57
import java.util.regex.Pattern;
58
import javax.swing.filechooser.FileFilter;
59
import org.openide.filesystems.FileObject;
60
import org.openide.filesystems.FileUtil;
61
62
/**
63
 * Support methods for creation of registered {@link FileFilter file filters}.
64
 */
65
public final class FileFilterSupport {
66
67
    /**
68
     * The logger.
69
     */
70
    private static final Logger LOG = Logger.getLogger(
71
            FileFilterSupport.class.getName());
72
73
    /**
74
     * Hide the default constructor.
75
     */
76
    private FileFilterSupport() {
77
    }
78
79
    /**
80
     * Construct description for {@link FileFilter} that accepts files with
81
     * specified extension.
82
     *
83
     * @param displayName Human readable display name (e.g. "HTML files")
84
     * @param elements List of accepted filter elements.
85
     *
86
     * @return Display name (description) for the filter.
87
     */
88
    private static String constructFilterDisplayName(String displayName,
89
            List<FilterElement> elements) {
90
        StringBuilder sb = new StringBuilder(displayName);
91
        boolean first = true;
92
        sb.append(" [");                                                //NOI18N
93
        for (FilterElement el : elements) {
94
            if (first) {
95
                first = false;
96
            } else {
97
                sb.append(", ");                                        //NOI18N
98
            }
99
            sb.append(el.getName());
100
        }
101
        sb.append("]");                                                 //NOI18N
102
        return sb.toString();
103
    }
104
105
    /**
106
     * Check whether passed file is accepted by filter for specified list of
107
     * extensions.
108
     *
109
     * @param file File to be accepted or rejected.
110
     * @param elements List of accepted filter elements.
111
     *
112
     * @return True if the file is accepted, false if it is rejected.
113
     *
114
     * @see FileFilterSupport
115
     */
116
    private static boolean accept(File file, List<FilterElement> elements) {
117
        if (file != null) {
118
            if (file.isDirectory()) {
119
                return true;
120
            }
121
            for (FilterElement elm : elements) {
122
                if (elm.accept(file)) {
123
                    return true;
124
                }
125
            }
126
        }
127
        return false;
128
    }
129
130
    public static List<FileFilter> findRegisteredFileFilters() {
131
        List<FileFilter> filters = new LinkedList<FileFilter>();
132
        FileObject root = FileUtil.getConfigFile(
133
                "Services/MIMEResolver");                               //NOI18N
134
        Map<String, Set<FileObject>> filterNameToResolversMap =
135
                new HashMap<String, Set<FileObject>>();
136
        for (FileObject child : root.getChildren()) {
137
            if (child.isFolder()) {
138
                continue;
139
            }
140
            int i = 0;
141
            String f;
142
            while ((f = (String) child.getAttribute("fileChooser." + i))//NOI18N
143
                    != null) {
144
                Set<FileObject> set = filterNameToResolversMap.get(f);
145
                if (set == null) {
146
                    set = new HashSet<FileObject>();
147
                    filterNameToResolversMap.put(f, set);
148
                }
149
                set.add(child);
150
                i++;
151
            }
152
        }
153
        for (Map.Entry<String, Set<FileObject>> e :
154
                filterNameToResolversMap.entrySet()) {
155
            filters.add(createFilter(e.getKey(), e.getValue()));
156
        }
157
        return sortFiltersByDescription(filters);
158
    }
159
160
    private static FileFilter createFilter(final String name,
161
            final Set<FileObject> resolvers) {
162
        ArrayList<FilterElement> elems = new ArrayList<FilterElement>(3);
163
        String lastAtt;
164
        for (FileObject fo : resolvers) {
165
            int i = 0;
166
            while ((lastAtt = (String) fo.getAttribute(
167
                    "ext." + i)) != null) { //NOI18N
168
                addExtensionToList(elems, lastAtt);
169
                i++;
170
            }
171
            int n = 0;
172
            while ((lastAtt = (String) fo.getAttribute("fileName." //NOI18N
173
                    + (n++))) != null) {
174
                addNameToList(elems, lastAtt);
175
            }
176
            String type;
177
            if ((type = (String) fo.getAttribute("mimeType")) != null) {//NOI18N
178
                addMimeTypeExts(elems, type);
179
            }
180
            int t = 0;
181
            while ((type = (String) fo.getAttribute(
182
                    "mimeType." + (t++))) != null) {     //NOI18N
183
                addMimeTypeExts(elems, type);
184
            }
185
        }
186
        sortFilterElements(elems);
187
        return new FileFilterImpl(name, elems);
188
    }
189
190
    /**
191
     * Add all extensions assigned to a MIME Type to the extension list.
192
     */
193
    private static void addMimeTypeExts(List<FilterElement> exts, String type) {
194
        addAllExtensionsToList(exts, FileUtil.getMIMETypeExtensions(type));
195
    }
196
197
    /**
198
     * Add new items to list of extensions, prevent duplicates.
199
     *
200
     * @param list List of extensions to alter.
201
     * @param toAdd List of extensions (without starting dot) to add.
202
     */
203
    private static void addAllExtensionsToList(List<FilterElement> list,
204
            List<String> toAdd) {
205
        for (String s : toAdd) {
206
            addExtensionToList(list, s);
207
        }
208
    }
209
210
    /**
211
     * Add new item to list of extensions, prevent duplacates.
212
     *
213
     * @param list List of extensions to alter.
214
     * @param s Extensions without starting dot.
215
     */
216
    private static void addExtensionToList(List<FilterElement> list,
217
            String ext) {
218
        addFilterElementToList(list, FilterElement.createForExtension(ext));
219
    }
220
221
    private static void addNameToList(List<FilterElement> list, String name) {
222
        Pattern p = Pattern.compile(
223
                "\\[([^,]+), (true|false), (true|false)\\](\\S*)");     //NOI18N
224
        Matcher m = p.matcher(name);
225
        if (m.find()) {
226
            String fileName = m.group(1);
227
            boolean substring = m.group(2).equals("true");              //NOI18N
228
            boolean ignoreCase = m.group(3).equals("true");             //NOI18N
229
            String extension = m.group(4);
230
            addFilterElementToList(list, FilterElement.createForFileName(
231
                    fileName, extension, substring, ignoreCase));
232
        } else {
233
            LOG.log(Level.INFO, "Incorrect name pattern {0}", name);    //NOI18N
234
        }
235
    }
236
237
    private static void addFilterElementToList(List<FilterElement> list,
238
            FilterElement newItem) {
239
240
        for (int i = 0; i < list.size(); i++) {
241
            FilterElement el = list.get(i);
242
            FilterElement.ComparisonResult result = newItem.compare(el);
243
            switch (result) {
244
                case DIFFERENT:
245
                    continue;
246
                case THE_SAME:
247
                case WORSE:
248
                    return;
249
                case BETTER:
250
                    list.set(i, newItem);
251
                    return;
252
            }
253
        }
254
        list.add(newItem);
255
    }
256
257
    private static List<FileFilter> sortFiltersByDescription(
258
            List<FileFilter> list) {
259
260
        Collections.sort(list, new Comparator<FileFilter>() {
261
            @Override
262
            public int compare(FileFilter o1, FileFilter o2) {
263
                return o1.getDescription().compareTo(o2.getDescription());
264
            }
265
        });
266
        return list;
267
    }
268
269
    private static List<FilterElement> sortFilterElements(
270
            List<FilterElement> elements) {
271
        Collections.sort(elements, new Comparator<FilterElement>() {
272
            @Override
273
            public int compare(FilterElement o1, FilterElement o2) {
274
                return o1.getName().compareTo(o2.getName());
275
            }
276
        });
277
        return elements;
278
    }
279
280
    private static class FileFilterImpl extends FileFilter {
281
282
        private final String name;
283
        List<FilterElement> filterElements;
284
285
        public FileFilterImpl(String name, List<FilterElement> elements) {
286
            this.name = name;
287
            this.filterElements = elements;
288
        }
289
290
        @Override
291
        public boolean accept(File pathname) {
292
            return FileFilterSupport.accept(pathname, filterElements);
293
        }
294
295
        @Override
296
        public String getDescription() {
297
            return FileFilterSupport.constructFilterDisplayName(
298
                    name, filterElements);
299
        }
300
    }
301
302
    /**
303
     * Element of File Filter. One accepted extension or file name pattern.
304
     */
305
    private static abstract class FilterElement {
306
307
        public abstract String getName();
308
309
        public abstract boolean accept(File f);
310
311
        /**
312
         * Compare two filter elements. Correct implementation of this method
313
         * prevents adding duplicite elements to the filter.
314
         */
315
        public abstract ComparisonResult compare(FilterElement e);
316
317
        public static FilterElement createForExtension(String ext) {
318
            return new ExtensionBasedFilterElement(ext);
319
        }
320
321
        public static FilterElement createForFileName(String name,
322
                String extension, boolean substring, boolean ignoreCase) {
323
            return new NameBasedFilterElement(name, extension,
324
                    substring, ignoreCase);
325
        }
326
327
        public static enum ComparisonResult {
328
329
            THE_SAME, BETTER, WORSE, DIFFERENT
330
        }
331
332
        private static class ExtensionBasedFilterElement extends FilterElement {
333
334
            private final String extension;
335
336
            public ExtensionBasedFilterElement(String extension) {
337
                if (extension != null) {
338
                    this.extension = extension;
339
                } else {
340
                    throw new NullPointerException();
341
                }
342
            }
343
344
            @Override
345
            public String getName() {
346
                return "." + extension;                                 //NOI18N
347
            }
348
349
            @Override
350
            public boolean accept(File f) {
351
                return f.getName().toLowerCase().endsWith(
352
                        "." + extension.toLowerCase());                 //NOI18N
353
            }
354
355
            @Override
356
            public ComparisonResult compare(FilterElement e) {
357
                if (!(e instanceof ExtensionBasedFilterElement)) {
358
                    return ComparisonResult.DIFFERENT;
359
                }
360
                ExtensionBasedFilterElement x = (ExtensionBasedFilterElement) e;
361
                if (x == null) {
362
                    throw new NullPointerException();
363
                }
364
                if (this.extension.equals(x.extension)) {
365
                    return ComparisonResult.THE_SAME;
366
                } else if (this.extension.equalsIgnoreCase(x.extension)
367
                        && this.extension.length() > 1) {
368
                    if (Character.isUpperCase(x.extension.charAt(0))) {
369
                        return ComparisonResult.BETTER; //this better, x worse
370
                    } else {
371
                        return ComparisonResult.WORSE; // this worse, x better
372
                    }
373
                } else {
374
                    return ComparisonResult.DIFFERENT;
375
                }
376
            }
377
        }
378
379
        private static class NameBasedFilterElement extends FilterElement {
380
381
            String name;
382
            String ext;
383
            boolean substring;
384
            boolean ignoreCase;
385
            Pattern p;
386
387
            public NameBasedFilterElement(String name, String ext,
388
                    boolean substring, boolean ignoreCase) {
389
                this.name = name;
390
                this.ext = ext;
391
                this.substring = substring;
392
                this.ignoreCase = ignoreCase;
393
                StringBuilder sb = new StringBuilder();
394
                if (ignoreCase) {
395
                    sb.append("(?i)");                                  //NOI18N
396
                }
397
                if (substring) {
398
                    sb.append(".*");                                    //NOI18N
399
                }
400
                sb.append(name);                                        //NOI18N
401
                if (substring) {
402
                    sb.append(".*");                                    //NOI18N
403
                }
404
                if (!ext.isEmpty()) {
405
                    sb.append("\\.");                                   //NOI18N
406
                    sb.append(ext);
407
                }
408
                p = Pattern.compile(sb.toString());
409
            }
410
411
            @Override
412
            public String getName() {
413
                return name + (ext.isEmpty() ? "" : "." + ext);         //NOI18N
414
            }
415
416
            @Override
417
            public boolean accept(File f) {
418
                return p.matcher(f.getName()).matches();
419
            }
420
421
            @Override
422
            public ComparisonResult compare(FilterElement e) {
423
                if (e == null) {
424
                    throw new NullPointerException();
425
                } else if (!(e instanceof NameBasedFilterElement)) {
426
                    return ComparisonResult.DIFFERENT;
427
                }
428
                NameBasedFilterElement x = (NameBasedFilterElement) e;
429
                if (this.name.equals(x.name) && this.ext.equals(x.ext)) {
430
                    if (this.substring == x.substring
431
                            && this.ignoreCase == x.ignoreCase) {
432
                        return ComparisonResult.THE_SAME;
433
                    } else {
434
                        return compareFlags(x);
435
                    }
436
                } else if (this.ext.equalsIgnoreCase(x.ext)
437
                        && this.name.equalsIgnoreCase(x.name)
438
                        && (this.ignoreCase || x.ignoreCase)) {
439
                    if (this.substring == x.substring
440
                            && this.ignoreCase == x.ignoreCase) {
441
                        if (Character.isLowerCase(this.name.charAt(0))) {
442
                            return ComparisonResult.BETTER;
443
                        } else {
444
                            return ComparisonResult.WORSE;
445
                        }
446
                    } else {
447
                        return compareFlags(x);
448
                    }
449
                } else {
450
                    return ComparisonResult.DIFFERENT;
451
                }
452
            }
453
454
            private ComparisonResult compareFlags(NameBasedFilterElement x) {
455
                if (this.substring == x.substring
456
                        && this.ignoreCase) {
457
                    return ComparisonResult.BETTER;
458
                } else if (this.ignoreCase == x.ignoreCase
459
                        && this.substring) {
460
                    return ComparisonResult.BETTER;
461
                } else if (this.substring != x.substring
462
                        && this.ignoreCase != x.ignoreCase) {
463
                    return ComparisonResult.DIFFERENT;
464
                } else {
465
                    return ComparisonResult.WORSE;
466
                }
467
            }
468
        }
469
    }
470
}
(-)a/openide.filesystems/src/org/netbeans/modules/openide/filesystems/declmime/FileElement.java (+4 lines)
Lines 75-80 Link Here
75
        return fileCheck.exts;
75
        return fileCheck.exts;
76
    }
76
    }
77
77
78
    List<Type.FileName> getNames() {
79
        return fileCheck.names;
80
    }
81
78
    String getMimeType() {
82
    String getMimeType() {
79
        return mime;
83
        return mime;
80
    }
84
    }
(-)a/openide.filesystems/src/org/netbeans/modules/openide/filesystems/declmime/MIMEResolverImpl.java (-1 / +47 lines)
Lines 374-380 Link Here
374
374
375
    // MIMEResolver ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
375
    // MIMEResolver ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
376
376
377
    private static final class Impl extends MIMEResolver {
377
    private static final class Impl extends MIMEResolver
378
        implements MIMEResolverProcessor.FilterInfo {
379
378
        // This file object describes rules that drive ths instance
380
        // This file object describes rules that drive ths instance
379
        private final FileObject data;
381
        private final FileObject data;
380
382
Lines 522-527 Link Here
522
                }
524
                }
523
            }
525
            }
524
        }
526
        }
527
528
        @Override
529
        public List<String> getExtensions() {
530
            if (smell == null) {
531
                return Collections.emptyList();
532
            } else {
533
                List<String> extensions = new LinkedList<String>();
534
                for (FileElement fe : smell) {
535
                    if (fe != null && fe.getExtensions() != null
536
                            && (fe.getNames() == null
537
                            || fe.getNames().isEmpty())) {
538
                        for (String ext : fe.getExtensions()) {
539
                            if (ext != null && !ext.isEmpty()) {
540
                                extensions.add(ext);
541
                            }
542
                        }
543
                    }
544
                }
545
                return extensions;
546
            }
547
        }
548
549
        @Override
550
        public List<String> getFileNames() {
551
            if (smell == null) {
552
                return Collections.emptyList();
553
            } else {
554
                List<String> fileNames = new LinkedList<String>();
555
                for (FileElement fe : smell) {
556
                    if (fe != null && fe.getNames() != null) {
557
                        for (Type.FileName name : fe.getNames()) {
558
                            String[] exts = fe.getExtensions();
559
                            if (exts == null || exts.length == 0) {
560
                                continue;
561
                            }
562
                            for (String ext : exts) {
563
                                fileNames.add(name.toString() + ext);
564
                            }
565
                        }
566
                    }
567
                }
568
                return fileNames;
569
            }
570
        }
525
    }
571
    }
526
572
527
    
573
    
(-)a/openide.filesystems/src/org/netbeans/modules/openide/filesystems/declmime/MIMEResolverProcessor.java (-3 / +59 lines)
Lines 42-48 Link Here
42
package org.netbeans.modules.openide.filesystems.declmime;
42
package org.netbeans.modules.openide.filesystems.declmime;
43
43
44
import java.io.*;
44
import java.io.*;
45
import java.util.Arrays;
46
import java.util.Collection;
45
import java.util.HashSet;
47
import java.util.HashSet;
48
import java.util.List;
46
import java.util.Set;
49
import java.util.Set;
47
import javax.annotation.processing.Processor;
50
import javax.annotation.processing.Processor;
48
import javax.annotation.processing.RoundEnvironment;
51
import javax.annotation.processing.RoundEnvironment;
Lines 109-114 Link Here
109
            f.stringvalue("ext." + (cnt++), ext); // NOI18N
112
            f.stringvalue("ext." + (cnt++), ext); // NOI18N
110
        }
113
        }
111
        f.position(r.position());
114
        f.position(r.position());
115
        int ccnt = 0;
116
        for (String chooser : r.showInFileChooser()) {
117
            f.bundlevalue("fileChooser." + (ccnt++), chooser);
118
        }
112
        f.bundlevalue("displayName", r.displayName()); // NOI18N
119
        f.bundlevalue("displayName", r.displayName()); // NOI18N
113
        f.write();
120
        f.write();
114
    }
121
    }
Lines 120-132 Link Here
120
        File f = b.file("Services/MIMEResolver/" + getName(e).replace('.', '-') + "-Registration" + SUFFIX); // NOI18N
127
        File f = b.file("Services/MIMEResolver/" + getName(e).replace('.', '-') + "-Registration" + SUFFIX); // NOI18N
121
        f.methodvalue("instanceCreate", MIMEResolver.class.getName(), "create"); // NOI18N
128
        f.methodvalue("instanceCreate", MIMEResolver.class.getName(), "create"); // NOI18N
122
        f.stringvalue("instanceClass", MIMEResolver.class.getName()); // NOI18N
129
        f.stringvalue("instanceClass", MIMEResolver.class.getName()); // NOI18N
123
        f.serialvalue("bytes", generateInstanceResolver(fo, e)); // NOI18N
130
        f.serialvalue("bytes", generateInstanceResolver(fo, e, f, r)); // NOI18N
124
        f.position(r.position());
131
        f.position(r.position());
132
        int ccnt = 0;
133
        for (String chooser : r.showInFileChooser()) {
134
            f.bundlevalue("fileChooser." + (ccnt++), chooser);
135
        }
125
        f.bundlevalue("displayName", r.displayName()); // NOI18N
136
        f.bundlevalue("displayName", r.displayName()); // NOI18N
126
        f.write();
137
        f.write();
127
    }
138
    }
128
139
129
    private byte[] generateInstanceResolver(FileObject fo, Element e) throws LayerGenerationException {
140
    private byte[] generateInstanceResolver(FileObject fo, Element e, File f,
141
            Registration r) throws LayerGenerationException {
130
        try {
142
        try {
131
            InputStream is = fo.openInputStream();
143
            InputStream is = fo.openInputStream();
132
            org.openide.filesystems.FileObject tmp = FileUtil.createMemoryFileSystem().getRoot().createData("resolver.xml");
144
            org.openide.filesystems.FileObject tmp = FileUtil.createMemoryFileSystem().getRoot().createData("resolver.xml");
Lines 140-146 Link Here
140
            }
152
            }
141
            os.close();
153
            os.close();
142
            is.close();
154
            is.close();
143
            final byte[] almostResult = MIMEResolverImpl.toStream(MIMEResolverImpl.forDescriptor(tmp, false));
155
            MIMEResolver resolver = MIMEResolverImpl.forDescriptor(tmp, false);
156
            setFileChooserRelatedAttributes(r, resolver, f);
157
            final byte[] almostResult = MIMEResolverImpl.toStream(resolver);
144
            // XXX: it would be slightly shorter to return the array directly,
158
            // XXX: it would be slightly shorter to return the array directly,
145
            // but the XMLFileSystem insist on deserializing the value, it does
159
            // but the XMLFileSystem insist on deserializing the value, it does
146
            // not support returning plain byte[]
160
            // not support returning plain byte[]
Lines 192-195 Link Here
192
            return getName(e.getEnclosingElement()) + '.' + e.getSimpleName();
206
            return getName(e.getEnclosingElement()) + '.' + e.getSimpleName();
193
        }
207
        }
194
    }
208
    }
209
210
    private Set<String> unq(String[] array) {
211
        return unq(Arrays.asList(array));
212
    }
213
214
    private Set<String> unq(Collection collection) {
215
        Set<String> s = new HashSet();
216
        s.addAll(collection);
217
        return s;
218
    }
219
220
    private void setFileChooserRelatedAttributes(Registration r,
221
            MIMEResolver resolver, File f) {
222
223
        if (r.showInFileChooser().length > 0) {
224
            String[] types = MIMEResolverImpl.getMIMETypes(resolver);
225
            List<String> exts = ((FilterInfo) resolver).getExtensions();
226
            int cnt = 0;
227
            for (String ext : unq(exts)) {
228
                f.stringvalue("ext." + (cnt++), ext);              // NOI18N
229
            }
230
            int tcnt = 0;
231
            for (String type : unq(types)) {
232
                f.stringvalue("mimeType." + (tcnt++), type);       // NOI18N
233
            }
234
            int ncnt = 0;
235
            for (String name : ((FilterInfo) resolver).getFileNames()) {
236
                f.stringvalue("fileName." + (ncnt++), name);        //NOI18N
237
            }
238
        }
239
    }
240
241
    /**
242
     * Interface of objects that provide information for construction of
243
     * FileFilters.
244
     */
245
    interface FilterInfo {
246
247
        List<String> getExtensions();
248
249
        List<String> getFileNames();
250
    }
195
}
251
}
(-)a/openide.filesystems/src/org/openide/filesystems/FileChooserBuilder.java (+14 lines)
Lines 57-62 Link Here
57
import javax.swing.filechooser.FileFilter;
57
import javax.swing.filechooser.FileFilter;
58
import javax.swing.filechooser.FileSystemView;
58
import javax.swing.filechooser.FileSystemView;
59
import javax.swing.filechooser.FileView;
59
import javax.swing.filechooser.FileView;
60
import org.netbeans.modules.openide.filesystems.FileFilterSupport;
60
import org.openide.util.*;
61
import org.openide.util.*;
61
62
62
/**
63
/**
Lines 446-451 Link Here
446
    }
447
    }
447
448
448
    /**
449
    /**
450
     * Add all default file filters to the file chooser.
451
     *
452
     * @see MIMEResolver.Registration#showInFileChooser()
453
     * @see MIMEResolver.ExtensionRegistration#showInFileChooser()
454
     * @return this
455
     * @since 8.1
456
     */
457
    public FileChooserBuilder addDefaultFileFilters() {
458
        filters.addAll(FileFilterSupport.findRegisteredFileFilters());
459
        return this;
460
    }
461
462
    /**
449
     * Set a selection approver which can display an &quot;Overwrite file?&quot;
463
     * Set a selection approver which can display an &quot;Overwrite file?&quot;
450
     * or similar dialog if necessary, when the user presses the accept button
464
     * or similar dialog if necessary, when the user presses the accept button
451
     * in the file chooser dialog.
465
     * in the file chooser dialog.
(-)a/openide.filesystems/src/org/openide/filesystems/MIMEResolver.java (+18 lines)
Lines 215-220 Link Here
215
         * specify it by defining their {@link LayerBuilder#position() position}.
215
         * specify it by defining their {@link LayerBuilder#position() position}.
216
         */        
216
         */        
217
        public int position() default Integer.MAX_VALUE;
217
        public int position() default Integer.MAX_VALUE;
218
        /**
219
         * Show file filters for this MIME type. Set localized names of file
220
         * filters that should contain files resolved by this resolver.
221
         *
222
         * @see FileChooserBuilder#addDefaultFileFilters()
223
         * @since 8.1
224
         */
225
        public String[] showInFileChooser() default {};
218
    }
226
    }
219
227
220
    /** Recognize mime type by looking into header of XML files. The
228
    /** Recognize mime type by looking into header of XML files. The
Lines 338-342 Link Here
338
        /** Display name to present this type of objects to the user.
346
        /** Display name to present this type of objects to the user.
339
         */
347
         */
340
        public String displayName();
348
        public String displayName();
349
        /**
350
         * Show file filters for registered MIME types. Set localized names of
351
         * file filters that should accept files resolved by this resolver. Only
352
         * types resolved by file name or extension (not by file content) are
353
         * supported.
354
         *
355
         * @see FileChooserBuilder#addDefaultFileFilters()
356
         * @since 8.1
357
         */
358
        public String[] showInFileChooser() default {};
341
    }
359
    }
342
}
360
}
(-)a/openide.filesystems/test/unit/src/org/netbeans/modules/openide/filesystems/FileFilterSupportTest.java (+113 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.openide.filesystems;
43
44
import java.io.File;
45
import java.util.List;
46
import javax.swing.filechooser.FileFilter;
47
import org.netbeans.junit.NbTestCase;
48
import org.openide.filesystems.MIMEResolver;
49
import org.openide.util.NbBundle;
50
51
/**
52
 * Test registered FileFilters.
53
 *
54
 * @author jhavlin
55
 */
56
@NbBundle.Messages({
57
    "RESOLVER=Resolver",
58
    "FILECHOOSER=BNM Files"
59
})
60
@MIMEResolver.Registration(
61
    displayName = "#RESOLVER",
62
resource = "mime-resolver-filechooser.xml",
63
showInFileChooser = "#FILECHOOSER")
64
public class FileFilterSupportTest extends NbTestCase {
65
66
    public FileFilterSupportTest(String name) {
67
        super(name);
68
    }
69
70
    /**
71
     * This test, although it is quite short, tests a lot of ascpects of default
72
     * file filters. The resolver definition XML file contains several
73
     * duplicities, which are detected and ignored. If this detection fails,
74
     * filter description and {@code accept} method is changed, and it is cought
75
     * by this test.
76
     */
77
    public void testRegisteredFilters() {
78
        List<FileFilter> list = FileFilterSupport.findRegisteredFileFilters();
79
        assertNotNull(list);
80
        assertFalse(list.isEmpty());
81
82
        boolean found = false;
83
        for (FileFilter filter : list) {
84
85
            if (filter.getDescription().startsWith("BNM Files")) {
86
                found = true;
87
                checkBnmFilesFilter(filter);
88
            }
89
        }
90
        assertTrue("Registered File Filter was not found.", found);
91
    }
92
93
    private void checkBnmFilesFilter(FileFilter f) {
94
        assertEquals("BNM Files [.bnm, bnmHelp, bnmProject, bnminfo, bnmsettings]",
95
                f.getDescription());
96
        assertTrue(f.accept(new File("first.bnm")));
97
        assertTrue(f.accept(new File("second.BNM")));
98
        assertTrue(f.accept(new File("third.bNm")));
99
        assertTrue(f.accept(new File("bnmProject")));
100
        assertTrue(f.accept(new File("PREFIXbnmProjectAndSuFfIx")));
101
        assertFalse(f.accept(new File("bnmproject")));
102
        assertTrue(f.accept(new File("bnmSettings")));
103
        assertTrue(f.accept(new File("BNMSETTINGS")));
104
        assertFalse(f.accept(new File("bnmSettingsX")));
105
        assertTrue(f.accept(new File("bnmInfo")));
106
        assertTrue(f.accept(new File("AbnmInfoB")));
107
        assertTrue(f.accept(new File("aBNMINFOb")));
108
        assertTrue(f.accept(new File("bnmHelp")));
109
        assertFalse(f.accept(new File("bnmhelp")));
110
        assertFalse(f.accept(new File("bnmHelpX")));
111
        assertFalse(f.accept(new File("foo.txt")));
112
    }
113
}
(-)a/openide.filesystems/test/unit/src/org/netbeans/modules/openide/filesystems/declmime/MIMEResolverProcessorTest.java (-3 / +36 lines)
Lines 58-74 Link Here
58
 *
58
 *
59
 * @author Jaroslav Tulach <jtulach@netbeans.org>
59
 * @author Jaroslav Tulach <jtulach@netbeans.org>
60
 */
60
 */
61
@MIMEResolver.Registration(resource="mime-resolver-rule.xml", displayName="#MYNAME", position=91)
61
@MIMEResolver.Registration(
62
        resource="mime-resolver-rule.xml",
63
        displayName="#MYNAME",
64
        position=91,
65
        showInFileChooser="#XML_BNM_FILES"
66
)
62
@NbBundle.Messages({
67
@NbBundle.Messages({
63
    "MYNAME=My Name",
68
    "MYNAME=My Name",
64
    "EXTNAME=XYZ extension",
69
    "EXTNAME=XYZ extension",
65
    "SPACENAME=Cosmic space"
70
    "SPACENAME=Cosmic space",
71
    "ABCXYX_FILES=ABC and XYZ Files",
72
    "TEST_FILES=Test Files",
73
    "XML_BNM_FILES=XML and BNM Files"
66
})
74
})
67
@MIMEResolver.ExtensionRegistration(
75
@MIMEResolver.ExtensionRegistration(
68
    displayName="#EXTNAME", 
76
    displayName="#EXTNAME", 
69
    extension={"abc", "xyz"}, 
77
    extension={"abc", "xyz"}, 
70
    mimeType="text/x-yz",
78
    mimeType="text/x-yz",
71
    position=92
79
    position=92,
80
    showInFileChooser={"#ABCXYX_FILES", "#TEST_FILES"}
72
)
81
)
73
@MIMEResolver.NamespaceRegistration(
82
@MIMEResolver.NamespaceRegistration(
74
    displayName="#SPACENAME",
83
    displayName="#SPACENAME",
Lines 147-152 Link Here
147
        assertTrue("contains xyz", arr.contains("xyz"));
156
        assertTrue("contains xyz", arr.contains("xyz"));
148
    }
157
    }
149
    
158
    
159
    public void testExtensionFileFilterRegistration() {
160
        final String PATH = "Services/MIMEResolver/"
161
                + "org-netbeans-modules-openide-filesystems-declmime-MIMEResolverProcessorTest-Registration.xml";
162
        FileObject fo = FileUtil.getConfigFile(PATH);
163
        assertNotNull(fo);
164
        assertEquals("xml", fo.getAttribute("ext.0"));
165
        assertEquals("[importantName, true, false]bnm", fo.getAttribute("fileName.0"));
166
        assertEquals("text/x-ant+xml", fo.getAttribute("mimeType.0"));
167
        assertEquals("text/x-bnm", fo.getAttribute("mimeType.1"));
168
        assertEquals("XML and BNM Files", fo.getAttribute("fileChooser.0"));
169
    }
170
171
    public void testResourceFileFilterRegistration() {
172
        final String PATH = "Services/MIMEResolver/"
173
                + "org-netbeans-modules-openide-filesystems-declmime-MIMEResolverProcessorTest-Extension.xml";
174
        FileObject fo = FileUtil.getConfigFile(PATH);
175
        assertNotNull(fo);
176
        assertEquals("abc", fo.getAttribute("ext.0"));
177
        assertEquals("xyz", fo.getAttribute("ext.1"));
178
        assertEquals("text/x-yz", fo.getAttribute("mimeType"));
179
        assertEquals("ABC and XYZ Files", fo.getAttribute("fileChooser.0"));
180
        assertEquals("Test Files", fo.getAttribute("fileChooser.1"));
181
    }
182
150
    public void testNameElement() throws Exception {
183
    public void testNameElement() throws Exception {
151
        MIMEResolver resolver = findResolver("Cosmic space");
184
        MIMEResolver resolver = findResolver("Cosmic space");
152
        assertMimeType(resolver, "text/x-my+xml", "namespace.axml", "namespace.bxml");
185
        assertMimeType(resolver, "text/x-my+xml", "namespace.axml", "namespace.bxml");
(-)a/openide.filesystems/test/unit/src/org/netbeans/modules/openide/filesystems/declmime/mime-resolver-rule.xml (+5 lines)
Lines 10-13 Link Here
10
            </xml-rule>
10
            </xml-rule>
11
        </resolver>
11
        </resolver>
12
    </file>
12
    </file>
13
    <file>
14
        <ext name="bnm"/>
15
        <name name="importantName" substring="true" ignorecase="false" />
16
        <resolver mime="text/x-bnm"/>
17
    </file>
13
</MIME-resolver>
18
</MIME-resolver>
(-)a/openide.filesystems/test/unit/src/org/netbeans/modules/openide/filesystems/declmime/mime-resolver-rule.xml (-8 / +58 lines)
Lines 1-13 Link Here
1
<?xml version="1.0"?>
1
<?xml version="1.0"?>
2
<MIME-resolver>
2
<MIME-resolver>
3
    <file>
3
    <file>
4
        <ext name="xml"/>
4
        <ext name="bnm"/>
5
        <resolver mime="text/x-ant+xml">
5
        <resolver mime="text/x-bnm"/>
6
            <xml-rule>
6
    </file>
7
                <element name="project">
7
8
                    <attr name="default"/>
8
    <!-- BNM PROJECT -->
9
                </element>
9
    <file>
10
            </xml-rule>
10
        <!--
11
        </resolver>
11
            Duplicite resolver that accept less files than the following one.
12
            Should not be used in the filter.
13
        -->
14
        <ext name=""/>
15
        <name name="bnmProject" substring="false" ignorecase="false" />
16
        <resolver mime="text/x-bnm-project"/>
17
    </file>
18
    <file>
19
        <ext name=""/>
20
        <name name="bnmProject" substring="true" ignorecase="false" />
21
        <resolver mime="text/x-bnm-project"/>
22
    </file>
23
24
    <!-- BNM SETTINGS -->
25
    <file>
26
        <ext name=""/>
27
        <name name="bnmSettings" substring="false" />
28
        <resolver mime="text/x-bnm-settings"/>
29
    </file>
30
    <file>
31
        <!--
32
            Duplicite resolver that accept less files than the previous one.
33
            Should not be used in the filter.
34
        -->
35
        <ext name=""/>
36
        <name name="bnmSettings" substring="false" ignorecase="true" />
37
        <resolver mime="text/x-bnm-settings"/>
38
    </file>
39
40
    <!-- BNM INFO -->
41
    <file>
42
        <ext name=""/>
43
        <name name="bnmInfo" substring="true" />
44
        <resolver mime="text/x-bnm-info"/>
45
    </file>
46
    <file>
47
        <!--
48
            Duplicite resolver that accept the same files as the previous one,
49
            only differs in case of file name, that is ignored.
50
            Should not be used in the filter.
51
        -->
52
        <ext name=""/>
53
        <name name="BNMInfo" substring="true" />
54
        <resolver mime="text/x-bnm-info"/>
55
    </file>
56
57
    <!-- BNM HELP -->
58
    <file>
59
        <ext name=""/>
60
        <name name="bnmHelp" substring="false" ignorecase="false" />
61
        <resolver mime="text/x-bnm-help"/>
12
    </file>
62
    </file>
13
</MIME-resolver>
63
</MIME-resolver>
(-)a/utilities/nbproject/project.xml (-1 / +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>8.1</specification-version>
100
                    </run-dependency>
100
                    </run-dependency>
101
                </dependency>
101
                </dependency>
102
                <dependency>
102
                <dependency>
(-)a/utilities/src/org/netbeans/modules/openfile/FileChooser.java (-162 lines)
Lines 1-162 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2010 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
 * Contributor(s):
28
 *
29
 * The Original Software is NetBeans. The Initial Developer of the Original
30
 * Software is Sun Microsystems, Inc. Portions Copyright 2004-2007 Sun
31
 * Microsystems, Inc. All Rights Reserved.
32
 *
33
 * If you wish your version of this file to be governed by only the CDDL
34
 * or only the GPL Version 2, indicate your decision by adding
35
 * "[Contributor] elects to include this software in this distribution
36
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
37
 * single choice of license, a recipient has the option to distribute
38
 * your version of this file under either the CDDL, the GPL Version 2 or
39
 * to extend the choice of license to its licensees as provided above.
40
 * However, if you add GPL Version 2 code and therefore, elected the GPL
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
43
 */
44
45
package org.netbeans.modules.openfile;
46
47
import java.awt.GridLayout;
48
import java.io.File;
49
import java.util.ArrayList;
50
import java.util.List;
51
import javax.swing.JFileChooser;
52
import javax.swing.JLabel;
53
import javax.swing.JPanel;
54
import javax.swing.filechooser.FileFilter;
55
import javax.swing.filechooser.FileNameExtensionFilter;
56
import org.openide.DialogDisplayer;
57
import org.openide.NotifyDescriptor;
58
import org.openide.util.Lookup;
59
import org.openide.util.NbBundle;
60
import org.openide.util.lookup.ServiceProvider;
61
62
/**
63
 *
64
 * @author  Jesse Glick
65
 * @author  Marian Petras
66
 */
67
class FileChooser extends JFileChooser {
68
69
    /** Creates a new instance of FileChooser */
70
    FileChooser() {
71
        setFileSelectionMode(JFileChooser.FILES_ONLY);
72
        setMultiSelectionEnabled(true);
73
        
74
        /* initialize file filters */
75
        FileFilter currentFilter = getFileFilter();
76
        addChoosableFileFilters();
77
        setFileFilter(currentFilter);
78
    }
79
80
    /**
81
     * Adds filters to the list of user choosable file filters.
82
     *
83
     * @see javax.swing.JFileChooser
84
     */
85
    public void addChoosableFileFilters() {
86
        for (OpenFileDialogFilter f :
87
                    Lookup.getDefault().lookupAll(OpenFileDialogFilter.class)) {
88
            addChoosableFileFilter(f);
89
        }
90
    }
91
    
92
    @Override
93
    public void approveSelection() {
94
        final File[] selectedFiles = getSelectedFiles();
95
96
        /* check the files: */
97
        List<String> errorMsgs = null;
98
        for (int i = 0; i < selectedFiles.length; i++) {
99
            String msgPatternRef = null;
100
            File file = selectedFiles[i];
101
102
            if (!file.exists()) {
103
                msgPatternRef = "MSG_FileDoesNotExist";                 //NOI18N
104
            } else if (file.isDirectory()) {
105
                msgPatternRef = "MSG_FileIsADirectory";                 //NOI18N
106
            } else if (!file.isFile()) {
107
                msgPatternRef = "MSG_FileIsNotPlainFile";               //NOI18N
108
            }
109
            if (msgPatternRef == null) {
110
                continue;
111
            }
112
113
            if (errorMsgs == null) {
114
                errorMsgs = new ArrayList<String>(selectedFiles.length - i);
115
            }
116
            errorMsgs.add(NbBundle.getMessage(FileChooser.class,
117
                                              msgPatternRef, file.getName()));
118
        }
119
        if (errorMsgs == null) {
120
            super.approveSelection();
121
        } else {
122
            JPanel panel = new JPanel(new GridLayout(errorMsgs.size(), 0,
123
                                                     0, 2));        //gaps
124
            for (String errMsg : errorMsgs) {
125
                panel.add(new JLabel(errMsg));
126
            }
127
            DialogDisplayer.getDefault().notify(
128
                    new NotifyDescriptor.Message(
129
                            panel, NotifyDescriptor.WARNING_MESSAGE));
130
        }
131
    }
132
133
134
    @ServiceProvider(service=org.netbeans.modules.openfile.OpenFileDialogFilter.class)
135
    public static class JavaFilesFilter extends OpenFileDialogFilter {
136
137
        @Override
138
        public String getDescriptionString() {
139
            return NbBundle.getMessage(getClass(), "OFDFD_Java"); // NOI18N
140
        }
141
142
        @Override
143
        public String[] getSuffixes() {
144
            return new String[] {".java"};
145
        }
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
161
162
}
(-)a/utilities/src/org/netbeans/modules/openfile/OpenFileAction.java (-2 / +64 lines)
Lines 45-61 Link Here
45
package org.netbeans.modules.openfile;
45
package org.netbeans.modules.openfile;
46
46
47
import java.awt.FileDialog;
47
import java.awt.FileDialog;
48
import java.awt.GridLayout;
48
import java.awt.event.ActionEvent;
49
import java.awt.event.ActionEvent;
49
import java.awt.event.ActionListener;
50
import java.awt.event.ActionListener;
50
import java.io.File;
51
import java.io.File;
52
import java.util.ArrayList;
53
import java.util.List;
51
import javax.swing.JFileChooser;
54
import javax.swing.JFileChooser;
55
import javax.swing.JLabel;
56
import javax.swing.JPanel;
52
import javax.swing.filechooser.FileSystemView;
57
import javax.swing.filechooser.FileSystemView;
58
import org.openide.DialogDisplayer;
59
import org.openide.NotifyDescriptor;
53
import org.openide.awt.ActionID;
60
import org.openide.awt.ActionID;
54
import org.openide.awt.ActionReference;
61
import org.openide.awt.ActionReference;
55
import org.openide.awt.ActionRegistration;
62
import org.openide.awt.ActionRegistration;
63
import org.openide.filesystems.FileChooserBuilder;
64
import org.openide.filesystems.FileChooserBuilder.SelectionApprover;
56
import org.openide.filesystems.FileUtil;
65
import org.openide.filesystems.FileUtil;
57
import org.openide.loaders.DataObject;
66
import org.openide.loaders.DataObject;
58
import org.openide.util.HelpCtx;
67
import org.openide.util.HelpCtx;
68
import org.openide.util.Lookup;
69
import org.openide.util.NbBundle;
59
import org.openide.util.UserCancelException;
70
import org.openide.util.UserCancelException;
60
import org.openide.windows.TopComponent;
71
import org.openide.windows.TopComponent;
61
import org.openide.windows.WindowManager;
72
import org.openide.windows.WindowManager;
Lines 92-101 Link Here
92
     * @return  the initialized file chooser
103
     * @return  the initialized file chooser
93
     */
104
     */
94
    protected JFileChooser prepareFileChooser() {
105
    protected JFileChooser prepareFileChooser() {
95
        JFileChooser chooser = new FileChooser();
106
        FileChooserBuilder fcb = new FileChooserBuilder(OpenFileAction.class);
107
        fcb.setSelectionApprover(new OpenFileSelectionApprover());
108
        fcb.setFilesOnly(true);
109
        fcb.addDefaultFileFilters();
110
        for (OpenFileDialogFilter filter :
111
                Lookup.getDefault().lookupAll(OpenFileDialogFilter.class)) {
112
            fcb.addFileFilter(filter);
113
        }
114
        JFileChooser chooser = fcb.createFileChooser();
115
        chooser.setMultiSelectionEnabled(true);
116
        chooser.getCurrentDirectory().listFiles(); //preload
96
        chooser.setCurrentDirectory(getCurrentDirectory());
117
        chooser.setCurrentDirectory(getCurrentDirectory());
97
        HelpCtx.setHelpIDString(chooser, getHelpCtx().getHelpID());
118
        HelpCtx.setHelpIDString(chooser, getHelpCtx().getHelpID());
98
        
99
        return chooser;
119
        return chooser;
100
    }
120
    }
101
    
121
    
Lines 198-201 Link Here
198
        return currentDirectory;
218
        return currentDirectory;
199
    }
219
    }
200
220
221
    private static class OpenFileSelectionApprover
222
            implements SelectionApprover {
223
224
        @Override
225
        public boolean approve(File[] selectedFiles) {
226
            /* check the files: */
227
            List<String> errorMsgs = null;
228
            for (int i = 0; i < selectedFiles.length; i++) {
229
                String msgPatternRef = null;
230
                File file = selectedFiles[i];
231
232
                if (!file.exists()) {
233
                    msgPatternRef = "MSG_FileDoesNotExist";             //NOI18N
234
                } else if (file.isDirectory()) {
235
                    msgPatternRef = "MSG_FileIsADirectory";             //NOI18N
236
                } else if (!file.isFile()) {
237
                    msgPatternRef = "MSG_FileIsNotPlainFile";           //NOI18N
238
                }
239
                if (msgPatternRef == null) {
240
                    continue;
241
                }
242
                if (errorMsgs == null) {
243
                    errorMsgs = new ArrayList<String>(selectedFiles.length - i);
244
                }
245
                errorMsgs.add(NbBundle.getMessage(OpenFileAction.class,
246
                        msgPatternRef, file.getName()));
247
            }
248
            if (errorMsgs == null) {
249
                return true;
250
            } else {
251
                JPanel panel = new JPanel(
252
                        new GridLayout(errorMsgs.size(), 0, 0, 2));   //gaps
253
                for (String errMsg : errorMsgs) {
254
                    panel.add(new JLabel(errMsg));
255
                }
256
                DialogDisplayer.getDefault().notify(
257
                        new NotifyDescriptor.Message(
258
                        panel, NotifyDescriptor.WARNING_MESSAGE));
259
                return false;
260
            }
261
        }
262
    }
201
}
263
}
(-)a/utilities/src/org/netbeans/modules/openfile/OpenFileDialogFilter.java (-1 / +7 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.MIMEResolver;
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
 * @deprecated Use {@link MIMEResolver.Registration} and its parameter
112
 * {@code showInFileChooser}.
110
 */
113
 */
114
@Deprecated
111
public abstract class OpenFileDialogFilter extends FileFilter {
115
public abstract class OpenFileDialogFilter extends FileFilter {
112
116
113
    /**
117
    /**
Lines 257-264 Link Here
257
     *
261
     *
258
     * @see OpenFileDialogFilter
262
     * @see OpenFileDialogFilter
259
     * @see FileNameExtensionFilter
263
     * @see FileNameExtensionFilter
260
     *
264
     * @deprecated Use {@link MIMEResolver.ExtensionRegistration} and its
265
     * parameter {@code showInFileChooser}.
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 = '.';
(-)a/xml/nbproject/project.xml (-1 / +1 lines)
Lines 202-208 Link Here
202
                    <build-prerequisite/>
202
                    <build-prerequisite/>
203
                    <compile-dependency/>
203
                    <compile-dependency/>
204
                    <run-dependency>
204
                    <run-dependency>
205
                        <specification-version>7.58</specification-version>
205
                        <specification-version>8.1</specification-version>
206
                    </run-dependency>
206
                    </run-dependency>
207
                </dependency>
207
                </dependency>
208
                <dependency>
208
                <dependency>
(-)a/xml/src/org/netbeans/modules/xml/Bundle.properties (-1 / +3 lines)
Lines 73-76 Link Here
73
73
74
#--
74
#--
75
75
76
CTL_SourceTabCaption=&Source
76
CTL_SourceTabCaption=&Source
77
78
ResourceFiles=Resource Files
(-)a/xml/src/org/netbeans/modules/xml/XMLDataObject.java (-1 / +6 lines)
Lines 82-94 Link Here
82
    @MIMEResolver.Registration(
82
    @MIMEResolver.Registration(
83
        displayName="org.netbeans.modules.xml.resources.Bundle#XMLFirstResolver",
83
        displayName="org.netbeans.modules.xml.resources.Bundle#XMLFirstResolver",
84
        position=60001,
84
        position=60001,
85
        resource="resources/xml-mime-resolver.xml"
85
        resource="resources/xml-mime-resolver-basic.xml",
86
        showInFileChooser="#ResourceFiles"
86
    )
87
    )
87
    /**
88
    /**
88
     * Special MIME type so that other XML data objects do not inherit our editor
89
     * Special MIME type so that other XML data objects do not inherit our editor
89
     */
90
     */
90
    public static final String MIME_PLAIN_XML = "text/plain+xml";
91
    public static final String MIME_PLAIN_XML = "text/plain+xml";
91
    
92
    
93
    @MIMEResolver.Registration(
94
        displayName = "org.netbeans.modules.xml.resources.Bundle#XMLFirstResolver",
95
    position = 60004,
96
    resource = "resources/xml-mime-resolver-other.xml")
92
    /**
97
    /**
93
     * XSD pseudo-MIME type
98
     * XSD pseudo-MIME type
94
     */
99
     */
(-)a/xml/src/org/netbeans/modules/xml/resources/xml-mime-resolver.xml (-5 lines)
Lines 50-60 Link Here
50
50
51
    <file>
51
    <file>
52
        <ext name="xml"/>
52
        <ext name="xml"/>
53
        <ext name="wsdl"/>
54
        <resolver mime="text/xml"/>
53
        <resolver mime="text/xml"/>
55
    </file>
54
    </file>
56
    <file>
57
        <ext name="xsd"/>
58
        <resolver mime="text/xsd+xml"/>
59
    </file>
60
</MIME-resolver>
55
</MIME-resolver>
(-)a/xml/src/org/netbeans/modules/xml/resources/xml-mime-resolver.xml (-1 lines)
Lines 49-55 Link Here
49
<MIME-resolver>
49
<MIME-resolver>
50
50
51
    <file>
51
    <file>
52
        <ext name="xml"/>
53
        <ext name="wsdl"/>
52
        <ext name="wsdl"/>
54
        <resolver mime="text/xml"/>
53
        <resolver mime="text/xml"/>
55
    </file>
54
    </file>

Return to bug 209998