Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selecting remote files

Status
Not open for further replies.

Madere

Technical User
Apr 14, 2003
85
GB
Hallo all,

I have a java application that, at some stage, select files from the local filesystem using JFileChooser.showOpenDialog().

Now I want it in a client-server setup. This means opening a GUI for selecting files on the server.
For client-server I use RMI.

I have already tried several scenarios to keep using the JFileChooser, but I cant get the correct setup working.

I am able to get the remote filelist using File.listFiles() bu then it returns a File[] (or as I did an ArrayList, but that is not important). But using the File.listFiles() on the remote side, I do not see any possiblity to keep using the JFileChooser.

In fact i do not want to create the whole file select window myself as JFileChooser is doing.

Does anyone has a solution to select remote files on a client, using RMI, where it looks like that JFileChooser is selecting files locally.

Thanks in advange.
 
I think you should implement the abstract class FileSystemView:
You would implement the methods in that class, so that it looked at the remote file system.

Then you could construct a JFileChooser using the view.

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Sedi,

I created a new class extended from the FileSystemView. No other methods implemented so far.

When I open the JFileChooser dialog on client with my FileSystemView, I can browse on my client filesystem. That is not what I want as you understand.

I must be doing something wrong or it might not be the correct implementation. I see no setDirectory() method in FileSystemView.
 
I guess you need to overwrite the listFiles method to retrive the list of files from the server via RMI.

Cheers,
Dian
 
If you subclass FileSystemView but don't override any methods, then it will behave EXACTLY like FileSystemView. You obviously need to override at least one method whenever you subclass anything in order to modify its behaviour. In this case, you need to override any and all methods which collaborate to provide a view on the file system to make them provide a view on a remote file system instead.

Tim
 
You need to fully implement the FileSystemView to get all the required information from the remote file system- this will not be a trivial task, and you will doubtless need to write several new methods for your RMI server to extract the data required.

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Madere, I think sedj is correct on this. It does look like quite a lot of messing. Not for the faint hearted.

After a quick look at the class, you'd have to override all the methods as sedj says. For example, the ones which return File objects and File[] arrays need to create these by using RMI to get the info needed and rolling them yourself.

Tim
 
Ok,

now something else wrong happens. When using println in the server code (in the getFiles)() method), the message is printed at the client side.

This means I have the Obejct of my FileSystemView class client side. Therefore the getFiles() will work on my local filesystem.

So it looks I am still doing something wrong, or it is not the correct implementation.
 
I'm not sure I follow here what you are saying.

In the FileSystemView's getFiles() method, you need to call to the RMI server a similar kind of request (ie, get me a list of files for 'x' directory). You then need to hand this back to the caller of the FileSystemView's method.

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
That means my own FileSystemView class is coded on client side. Only the getFiles() method should be server sided.

I had my class on the server side. As soon an object was created, the whole class was client side.

I will try with only the getFiles() server side coded.
 
Madere, post us the code you have so far which subclasses FileSystemView.

Tim
 
Yes, post some succinct code.

To clarify, your filesystemview is on the client, and accesses the remote file system via RMI - so RMI is basically a proxy to your file system.

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
I am getting the remote file list now by using a File[] getFiles() on the server side.

The next problem is: how to walk through the directories on the server using the "Look in" and the "Up One Level" button. Because these are related to my client side (till so far).

When I set the JFileChooser.setCurrentDirectory() to my remote directory, then the "My Documents" shows up in the "Look in" bar. And that is client sided. But I want to browse server sided.

Any new ideas?

My current code is splitted over several files, so a little hard to post here.
 
What you could do is write a wrapper on the server which wraps the FileSystemView class on the server and makes its methods available as remote service calls via RMI. Then, on the client, in your class which subclasses FileSystemView, override each method to call its analogue over RMI.

Tim
 
If you override ALL the methods properly this should work too. It's all done through the FileSystemView class and its default implementation. BTW, I should have mentioned in my previous post that you'd need to wrap this default implementation on the server, not the abstract FileSystemView.

Tim
 
Thanks all for the help, but I think there are too much assumptions what should work and how to implement.

I believe I have not seen a solution that really works.
I have already tried several things, but the browsing through directories seems to me the biggest problem now.

So please only reply a solution when you are absolutly sure it works. Maybe I am still doing something else wrong or I do not understand something about RMI.

I already have looked for sample codes on the internet, but did not find something useful.

So if some1 has THE solution, please post.
Thanks.
 
So please only reply a solution when you are absolutly sure it works

Sorry. I don't think my boss would appreciate it if I took hours out to develop and test this for you before suggesting it.

Tim
 
Tim,

I do not mean you have to write and test it for me.
At the moment I feel it is too much of trial and error without really knowing it will work.

I appreciate your effort, but I am looking for a solution that works. Maybe I have to write the JFileChosser completely myself (which I dont like), but then I have control over all components. I only hoped some1 knew a solution working.

I dont have that much time myself to do trial and error, you understand :)
 
Look mate - this is NOT a helpdesk, we take out a lot of time to help people like you.
I don't know 100% if what we have suggested will work, but my 6 years of Java programming experience (which has included Swing, and RMI) tells me that it will work.

Frankly, I could not give a two hoots if you can be bothered to try the solution we have offered - you either take it or leave, but I sure as heck don't like your tone - especially when you say you "don't have time to do trial and error". I'm afraid mate, if you don't have the skills to do it, then the only way you will learn is through trial and error.

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top