Manage/retrieve existing ExpansionComponents

Is there a way to reuse a custom ExpansionComponent for list grid records.

When I expand my "Master"ListGridRecord (calling override getExpansionComponent), I am currently creating a new "Child"ListGrid each time… I was hoping to reuse this already created 'child’ListGrid the next time that 'master’record is expanded.

So, is there a way to set and retrieve expansion components for individual listGridRecords?

Thanks,
SmartGWT Newbee

getExpansionComponent() {
Canvas canvas = super.getExpansionComponent(record);
// reuse the canvas…
return canvas;
}

Thanks svjard,
I tried this, but ‘super.getExpansionComponent(record)’ was returning == null.

  @Override
  protected Canvas getExpansionComponent(final ListGridRecord record) {

    return (super.getExpansionComponent(record) != null ? super
            .getExpansionComponent(record) : createNewPageListGrid());
  }

  private Canvas createNewPageListGrid() {
    VLayout expansionLayout = new VLayout(5);
    expansionLayout.setPadding(5);
    expansionLayout.setWidth100();
    expansionLayout.setHeight(224);
    expansionLayout.setCanDragResize(true);
    expansionLayout.setResizeFrom("B");

    ListGrid listGrid = this.pageListGrid.get();

    expansionLayout.addMember(listGrid);
    return expansionLayout;
  }

Also, how would I ever create my ‘original’ custom expansionLayout the first time the record is expanded. I am using a provider to supply the pageListGrid.
Thanks again, Josh

Ahh yeah the component is a local in getExpansionComponent(), always created each time for each record, and it will never return null, so no reuse per se. If you really want to reuse a component you need to get clever. For example have an “expansionComponent” attribute for records, so you can just do

return (Canvas)record.getAttributeAsObject("expansionComponent");

or the other option is somehow have those components stored in a hashmap or something in another class and do a lookup.

The pageListGrid your getting, that is generic? or specific to a record? When not just return a global grid from that class everytime?

Resolved!

Thanks svjard!
Creating an attribute for the expansionCanvas object worked great… I can see where this might be useful in other places too.
Thanks so much for your help!

Now is there any way to destroy these expansionCanvases when my records get destroyed?