# Interface TreeModel

All Known Implementing Classes:
  `FileTreeModel`

public interface TreeModel

Arranges tree node objects, a node can essentially be anything and it will be displayed in a hierarchy using the `com.codename1.ui.tree.Tree`

    class StringArrayTreeModel implements TreeModel {
        String[][] arr = new String[][] {
                {"Colors", "Letters", "Numbers"},
                {"Red", "Green", "Blue"},
                {"A", "B", "C"},
                {"1", "2", "3"}
            };

        public Vector getChildren(Object parent) {
            if(parent == null) {
                Vector v = new Vector();
                for(int iter = 0 ; iter  iter + 1 && arr[iter + 1] != null) {
                        for(int i = 0 ; i

    And heres a more "real world" example showing an XML hierarchy in a `Tree`:

    ```java
    class XMLTreeModel implements TreeModel {
    private Element root;
    public XMLTreeModel(Element e) {
    root = e;
    }

    public Vector getChildren(Object parent) {
    if(parent == null) {
    Vector c = new Vector();
    c.addElement(root);
    return c;
    }
    Vector result = new Vector();
    Element e = (Element)parent;
    for(int iter = 0 ; iter

    Another real world example showing the `com.codename1.io.FileSystemStorage` as a tree:

    ```java
    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(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
    @author Shai Almog

- ## Method Summary

  Modifier and Type
  Method
  Description
  `Vector`
  `getChildren(Object parent)`
  Returns the child objects representing the given parent, null should return the root objects
  `boolean`
  `isLeaf(Object node)`
  Is the node a leaf or a folder

- ## Method Details

  - ### getChildren

    Vector getChildren(Object parent)

    Returns the child objects representing the given parent, null should return the root objects

    ###### Parameters

    - `parent`: @param parent the parent object whose children should be returned, null would return the tree roots

    ###### Returns

    the children of the given node within the tree

  - ### isLeaf

    boolean isLeaf(Object node)

    Is the node a leaf or a folder

    ###### Parameters

    - `node`: a node within the tree

    ###### Returns

    true if the node is a leaf that can't be expanded