Hello. I'm attempting to create a File Chooser Dialog where the files
are displayed in a natural sort order as opposed to the lexical sort
order that Linux ls provides. This is so the files are sorted in a more
XP'ish ordering.
I already have the NaturalSortOrder Comparator that we use in other
parts of our application but I don't know how to force the
JFileChooserDialog to use my custom comparator. I tried overriding the
getFiles(File dir, boolean useFileHiding) method in the FileSystemView
that my JFileChooser uses, but that appears to not even get called.
What method actually queries the filesystem to gather the list of files
for display so I can override it to perform my own sorting before they
are shown to the user? Thank you so much for any help.
>I already have the NaturalSortOrder Comparator that we use in other
>parts of our application but I don't know how to force the
>JFileChooserDialog to use my custom comparator.
I did not see an single method that took a Comparator so I think you
are SOL for a simple implementation.
You will have to study the code for a FileSystemView and clone Sun's
windowsFileSystemView and modify the code where in uses File.listFiles
to insert a sort after.
I noticed some code that made me feel a little queasy poking around.
What the heck is this??
FileSystemView
public File getChild(File parent, String fileName) {
if (parent instanceof ShellFolder) {
File[] children = getFiles(parent, false);
for (int i = 0; i < children.length; i++) {
if (children[i].getName().equals(fileName)) {
return children[i];
}
}
}
return createFileObject(parent, fileName);
}

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
Andrey Kuznetsov - 05 Dec 2005 08:17 GMT
> I noticed some code that made me feel a little queasy poking around.
> What the heck is this??
I ask this question pretty often ;-)

Signature
Andrey Kuznetsov
http://uio.imagero.com Unified I/O for Java
http://reader.imagero.com Java image reader
http://jgui.imagero.com Java GUI components and utilities
Oliver Wong - 06 Dec 2005 22:56 GMT
> I noticed some code that made me feel a little queasy poking around.
> What the heck is this??
[quoted text clipped - 12 lines]
> return createFileObject(parent, fileName);
> }
There's a lot of code like that in Eclipse. They have an interface
called an IResource, which for almost all intents and purposes is a
reference to a file; except it may refer to a file which doesn't actually
exist in the file system.
So you'd have code like the one you showed here which will try to return
a IResource which points to the actual file on the system if it exists
(which implies first checking for its existence), or create an IResource
which sort of points to where the file would be, if it existed.
- Oliver