package com.zaranux.os.client.filesystem;
import com.zaranux.client.java.io.File;
import com.smartgwt.client.types.TreeModelType;
import com.smartgwt.client.widgets.tree.Tree;
import com.smartgwt.client.widgets.tree.TreeNode;
import com.zaranux.os.client.filesystem.ui.DirectoryNode;
import com.allen_sauer.gwt.log.client.Log;
public class RemoteFilesystemTreeData extends Tree {
private static RemoteFilesystemTreeData remoteFilesystemTree = null;
public static RemoteFilesystemTreeData getRemoteFilesystemTree()
{
return getRemoteFilesystemTree(new File[0]);
}
public static RemoteFilesystemTreeData getRemoteFilesystemTree(File[] files)
{
// TODO: it seesm the library does not seperate data form UI
// so for now create a new one ..
//if(remoteFilesystemTree == null)
remoteFilesystemTree = new RemoteFilesystemTreeData(files);
return remoteFilesystemTree;
}
private RemoteFilesystemTreeData(File[] files)
{
setModelType(TreeModelType.CHILDREN);
TreeNode hiddenRoot = new TreeNode();
setRoot(hiddenRoot);
DirectoryNode fsRemoteRoot = new DirectoryNode(new File("/"));
add(fsRemoteRoot, hiddenRoot);
if(files != null)
{
for(File file:files)
{
String path = file.getAbsolutePath();
if(path.startsWith("/"))
path = path.substring(1);
if(path.startsWith("@"))
{
path = "@/" + path.substring(1);
}
String[] segments = path.split("/");
DirectoryNode parent = fsRemoteRoot;
if(segments != null)
{
String pathName = "";
for(int i =0; i< segments.length; i++) // String segment:segments)
{
if(!segments[i].equals(""))
{
if(!(i == 1 && segments[0].equals("@")))
pathName += "/";
pathName += segments[i];
DirectoryNode child = new DirectoryNode(new File(pathName));
add(child,parent);
this.openFolder(parent);
parent = child;
}
}
}
}
}
}
}