You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Mark Fortner <ph...@yahoo.com> on 2006/03/16 23:49:59 UTC

[vfs] FileSelectInfo Question

Mario,
I'm still struggling with figuring out FileSelectInfo objects.  I'm 
trying to make some Swing VFS components, and doing wholesale replaces 
of File with FileObject code has been rather time consuming and 
aggravating because most of the File methods don't have their equivalent 
counterparts in FileObject.  They're either somewhere else or don't exist.

One example of this is the VFS version of FileFilters which uses the 
accept(FileSelectInfo ) method rather than accept(FileObject ).  There 
doesn't seem to be a way to turn a FileObject into a FileSelectInfo 
object.  And even though you mentioned that the FileSelectInfo gives you 
access to the root, and a few other things, I still don't see what value 
that has when you're trying to filter based on either name or metadata. 

The last time I ran into this problem, I simply created a class called 
VFSFileFilter which implemented accept(FileObject ) and continued on my 
way; however, I realize that that's not the way it's supposed to be 
implemented. 

So... what's the right way?
How do I get accept(FileObject ) to work?  Casting doesn't seem to 
work.  I get runtime exceptions.

Mark

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: [vfs] FileSelectInfo Question

Posted by Mark Fortner <ph...@yahoo.com>.
Mario,
I read the wiki before I sent the question.  I know that so seldom 
happens on this list. :-)

I've implemented a FileChooser based on Swing's code, but using VFS 
instead of the standard java.io.File classes.  However, I've run into a 
couple of problems that I can't seem to get past. Implementing 
Swing-compatible file filters is one of them.  In my VFSFileChooser 
class there are a couple of methods from the Swing JFileChooser that I 
can't figure out how to implement with VFS.  The problem boils down to 
the fact that I can't instantiate or create FileSelectInfo objects used 
by the filter.

    public void setFileFilter(FileFilter filter) {
        FileFilter oldValue = fileFilter;
        fileFilter = filter;
        if (filter != null) {
            if (isMultiSelectionEnabled() && selectedFiles != null
                    && selectedFiles.length > 0) {
                Vector fList = new Vector();
                boolean failed = false;
                for (int i = 0; i < selectedFiles.length; i++) {
                    //if (filter.accept(selectedFiles[i])) { FIXME
                        fList.add(selectedFiles[i]);
                    //} else {
                    //    failed = true;
                    //}
                }
                if (failed) {
                    setSelectedFiles((fList.size() == 0) ? null
                            : (FileObject[]) fList.toArray(new 
FileObject[fList.size()]));
                }
            } else if (selectedFile != null ) { //&& 
!filter.accept(selectedFile) FIXME
                setSelectedFile(null);
            }
        }
        firePropertyChange(FILE_FILTER_CHANGED_PROPERTY, oldValue, 
fileFilter);
    }


    public boolean accept(FileObject f) {
        boolean shown = true;
        if (f != null && fileFilter != null) {
            //shown = fileFilter.accept(f); FIXME
        }
        return shown;
    }

As far as I can tell, I can't instantiate FileSelectInfo, and I can't 
find any method that actually creates FileSelectInfo classes. So when I 
run into code such as the stuff shown above, I'm stuck because I can't 
create a FileSelectInfo object.

In general, most of my problems with FileSelectInfo and a few other 
classes in VFS is that rather than building upon the java.io classes (or 
at the very least deriving an interface based upon the File class and 
building upon that), they go off in some other (incompatible) 
direction.  So when people like me are trying to use VFS with Swing 
classes or other standard Java classes, they run into problem after problem.

I'm hoping that in later releases of VFS, that the some work is done to 
simplify and standardize the API.  This might improve its chances to be 
used on JSR 203.  Even if it means creating adapter classes that bridge 
VFS and java.io classes, this would help improve VFS's adoption.

Mark


Mario Ivankovits wrote:
> Hi!
>   
>> There doesn't seem to be a way to turn a FileObject into a
>> FileSelectInfo object.  And even though you mentioned that the
>> FileSelectInfo gives you access to the root, and a few other things, I
>> still don't see what value that has when you're trying to filter based
>> on either name or metadata.
>>     
> And I dont get your problems with the FileSelectInfo ;-)
>
> Why would you turn a FileObject into a FileSelectInfo. This is something
> VFS do for you.
>
> On http://wiki.apache.org/jakarta-commons/VfsFaq you will find an
> example how to use a selector.
>
> To get the FileObject in question you can call fileSelectInfo.getFile().
>
>
> Ciao,
> Mario
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>
>   


Re: [vfs] FileSelectInfo Question

Posted by Mario Ivankovits <ma...@ops.co.at>.
Hi!
> There doesn't seem to be a way to turn a FileObject into a
> FileSelectInfo object.  And even though you mentioned that the
> FileSelectInfo gives you access to the root, and a few other things, I
> still don't see what value that has when you're trying to filter based
> on either name or metadata.
And I dont get your problems with the FileSelectInfo ;-)

Why would you turn a FileObject into a FileSelectInfo. This is something
VFS do for you.

On http://wiki.apache.org/jakarta-commons/VfsFaq you will find an
example how to use a selector.

To get the FileObject in question you can call fileSelectInfo.getFile().


Ciao,
Mario


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org