How to decorate objects in CellTree (TreeViewModel)?

23 views
Skip to first unread message

membersound

unread,
Jan 9, 2013, 10:37:20 AM1/9/13
to google-we...@googlegroups.com
Hi,

I have serveral classes that extend from a baseclass. I display them in a CellTree.
Now, if a specific class (Cat) is displayed, I want this class to have subentries. Similar to:

Dog1
Dog2
Cat1
 - Age Cat1
Dog3
Dog4


How can I achieve this??

class Animal {
    //every animal gets a name
    String name;
}

class Dog extends Animal {}

class cat extends Animal {
    //only cat shall have an age
    int age;
}

//data provider will be set in onLoadModule()
private final ListDataProvider<Animal> animals = new ListDataProvider<Animal>();

//the view model
class AnimalModel implements TreeViewModel {

    @Override
    public <T> NodeInfo<?> getNodeInfo(T value) {
        List<HasCell<Animal, ?>> hasCells = new ArrayList<HasCell<Animal, ?>>();

        hasCells.add(new HasCell<Animal, Animal>() {
            private AnimalCell cell = new AnimalCell();
       
        }


        if (value instanceOf Cat) {
            //what do I have to do in order to display subentries only for cats??
        }

        return new DefaultNodeInfo<Animal>(animals, new CompositeCell<Animal>(hasCells));
    }
}


//renderer for parent items like "Dog1", "Cat1"...
class AnimalCell extends AbstractCell<Port> {

    @Override
    public void render(Context context, Animal animal, SafeHtmlBuilder sb) {
        sb.appendEscaped(animal.getName());
    }
}

Reply all
Reply to author
Forward
0 new messages