Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    TreeGrid and folder icons

    I'm trying to wrap my head around how the TreeGrid works with an GWTRPCDataSource.

    First I'm using eclipse 3.5, SmartGWT 2.2 and Safari.

    I have gotten to the point where my tree loads and displays labels. I can open and close folders and see the children of the parents. So I'm pretty happy in general.

    However, I'm a little confused. The tree is configured like this:


    TreeGrid treeGrid = new TreeGrid();
    treeGrid.setAutoFetchData(true);
    treeGrid.setDataSource(StackDataSource.getInstance());

    It contains one field:

    TreeGridField field = new TreeGridField("Lessons");
    field.setCanSort(true);
    field.setCellFormatter(new CellFormatter()
    {
    public String format(Object value, ListGridRecord record,
    int rowNum, int colNum) {
    return record.getAttribute("name");
    }
    });
    treeGrid.setFields(field);


    The record that comes across the wire has no indicator that any node in the tree has children. So I'm a bit confused how the TreeGrid knows to display the + that allows you to expand the folder.

    This is also a problem because when I get to the leaves of the tree, they too are displayed with a folder that makes it seem that they have children also.

    There is a model server side of the tree, that contains all the data that the tree holds. To move the data from server side to client side, I created a ClientNode, which contains fields for all the properties that need to be viewed client side but does not for instance, include an array of children.

    So my questions are:

    1) How does the grid know to put the folder and + sign when on the client side there is no indication of the presence of children?

    2) How can I change on any particular line, the icon being displayed? Currently is't the folder Icon. What would I do if I wanted to use a different type, at different levels?

    3) How do I prevent the Tree, from placing a folder and the expand box, on any row? (Related to 1)

    Thanks for your help.


    Tony

    #2
    It turns out, it was relatively simple to solve this problem. Though it took some digging to find the right bits.

    1) Yes, items default to type folder.

    2) When you get the node item to respond properly to the the framework then it displays a different icon.

    3) On my RPC object I added the following method.

    public boolean isFolderProperty()

    Which returned true or false based on the nature of the node, (folder or leaf).

    I have a method that copies attributes from my across the wire node, to the TreeNode. I added this line,

    to.setIsFolder( from.isFolderProperty());

    in this method code:

    private static void copyValues (ClientStackNode from, TreeNode to)

    And now the folders and leafs display properly.

    Tony

    Comment

    Working...
    X