Created
March 2, 2016 09:35
-
-
Save codenameone/2877412809a8cff646af to your computer and use it in GitHub Desktop.
This sample shows the entire Codename One FileSystemStorage hierachy as a tree that can be expaneded
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Form hi = new Form("FileSystemTree", new BorderLayout()); | |
TreeModel tm = new TreeModel() { | |
@Override | |
public Vector getChildren(Object parent) { | |
String[] files; | |
if(parent == null) { | |
files = FileSystemStorage.getInstance().getRoots(); | |
return new Vector<Object>(Arrays.asList(files)); | |
} else { | |
try { | |
files = FileSystemStorage.getInstance().listFiles((String)parent); | |
} catch(IOException err) { | |
Log.e(err); | |
files = new String[0]; | |
} | |
} | |
String p = (String)parent; | |
Vector result = new Vector(); | |
for(String s : files) { | |
result.add(p + s); | |
} | |
return result; | |
} | |
@Override | |
public boolean isLeaf(Object node) { | |
return !FileSystemStorage.getInstance().isDirectory((String)node); | |
} | |
}; | |
Tree t = new Tree(tm) { | |
@Override | |
protected String childToDisplayLabel(Object child) { | |
String n = (String)child; | |
int pos = n.lastIndexOf("/"); | |
if(pos < 0) { | |
return n; | |
} | |
return n.substring(pos); | |
} | |
}; | |
hi.add(BorderLayout.CENTER, t); | |
hi.show(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sample usage of FileSystemStorage & Tree.
From the Codename One project