Would anyone have a link to a webpage that can give me an example of how to get all the directories on my web server?
I would then like to put them in a JTree.
Also, please view the below code. Can someone tell me if this would be the right kind of class for the JTree.
After that I can figure out the modifications I need to make to it. I am not sure if the method getRoot() in
this case will work to get the remote working directory. Thank you for any help.
public class RemoteFileSystemModel extends AbstractTreeModel implements Serializable {
private String root;
public RemoteFileSystemModel() {
}
public RemoteFileSystemModel(String startPath) {
root = startPath;
}
public Object getRoot() {
return new File(root);
}
public Object getChild(Object parent, int index) {
File directory = (File)parent;
String[] children = directory.list();
return new File( directory, children[index] );
}
public int getChildCount(Object parent) {
File fileSysEntity = (File)parent;
if (fileSysEntity.isDirectory()) {
String[] children = fileSysEntity.list();
return children.length;
} else {
return 0;
}
}
public boolean isLeaf( Object node ) {
return ((File)node).isFile();
}
public void valueForPathChanged( TreePath path, Object newValue ) {}
public int getIndexOfChild( Object parent, Object child ) {
File directory = (File)parent;
File fileSysEntity = (File)child;
String[] children = directory.list();
int result = -1;
for (int i = 0; i < children.length; ++i) {
if(fileSysEntity.getName().equals(children[i])) {
result = i;
break;
}
}
return result;
}
}