gwtuibindercomposite-controlscellbrowser

GWT CellBrowser with CompositeCell


I am trying to build a CellBrowser as given below.

Week 1 -> Mathematics
Week 2    [] Algebra
Week 3    [] Trigonometry
          Science
          [] Physics
          [] Chemistry         

The problem is, I am not able to get the headings (Mathematics and Science) as given in the above code. The heading are from different Object, and my CompositeCell (CheckBox and TextCell) seems to be expecting/applying for all items.

Basically, I am trying to build the list in CellBrowser with some of them having (CheckBox and TextCell) while some of them having only (TextCell).

Please advise.


Solution

  • You have to override the render method either of your CompositeCell or the CheckBoxCell. Something like this:

    public class MyCompositeCell extends CompositeCell<Course>
    {
        @Override
        protected <X> void render(Context ctx,Course value, 
                                SafeHtmlBuilder sb, HasCell<Course, X> hasCell) {
        if (hasCell.getCell() instanceof CheckBoxCell && !value.hasCheckBox())
            return;
        super.render(ctx,value, sb, hasCell);
    }
    

    The function hasCheckBox() is just an example. Either you access a flag in your DTO (Course) or you can pass a flag directly to the Cell.

    Alternatively you can modify the render method of your CheckBoxCell:

    public class MyCheckBoxCell extends CheckBoxCell<Course> {
    
        @Override
        public void render(Context ctx,Transformation value, SafeHtmlBuilder sb) {
            if (!value.hasCheckBox())
                return;
            super.render(ctx,value, sb);
        }