new Vaadin Grid and TreeTable?

Hi all,

In my application I use the
com.vaadin.ui.Table
component and also the
com.vaadin.ui.TreeTable
component.
As the TreeTable extends the Table it is possible to create methods that can be used by both components:

public void doSomethingWithTableAndTreeTable(Table table) {} With Vaadin 7.4 I want to replace the use of the Table by the Grid, but then the common superclass will be
com.vaadin.ui.AbstractComponent
and the method would look like:

public void doSomethingWithTableAndTreeTable(AbstractComponent component) {} So some important information about the (Table) components will not be accessible in the method.
Do you have any suggestions how to solve that issue?
Or are there any plans to refactor the TreeTable too?

Regards

You could include type checking once inside a proxy method which calls a class specific method, but this most likely doesn’t get you the simplicity you’re looking for

public void doSomethingWithTableAndTreeTableAndGrid(AbstractComponent component)
{
    if(null == component) { throw new NullPointerException("Component may not be null"); }

    if(component instanceof Table) { doSomethingWithTableAndTreeTable((Table) component); }
    
    else if(component instance of Grid) { doSomethingWithTableAndTreeTable((Grid) component); }
    
    else { throw new IllegalArgumentException("Component must be of type Table or Grid"); }
}

private void doSomethingWithTableAndTreeTable(Table table) {...}

private void doSomethingWithGrid(Grid grid) {...}

With that approach I would still have to duplicate the private methods even if they are doing usually the same, e.g. reading information from the footer or header :frowning:
I think the best way would be to introduce a common super class or an interface.

Are there any plans to refactor the TreeTable too in one of the coming Vaadin versions?

I expect Grid will support TreeTable functionality. But I don’t know when. Grid team should know better.

Anyway, what do you need to handle in that common method? If you can share at least some thoughts maybe we can think of something smart. Is it UI component specific or datasource? If it involves only data or also data you should provide the data container for the data processes and work the UI stuff separately.

The concrete usecase is that in the application I have some Tables (will be replaced by the new Grid) and some TreeTables.

I do have a self written util that can export these components to PDF.
One example for my problem is that with Table / TreeTable the column header is read via

table.getColumnHeader(propertyId); With the Grid that would be something like

grid.getHeaderRow(rowIndex).getCell(propertyId) So for the same operation I would have to create several implementations because of the different APIs.

My application uses Grid to display a bunch of tabular data. But now I have a need to display some tabular data that also has a hierarchy and need something like a TreeTable - but since I’ve already developed a bunch of functionality on top of Grid (e.g. column filters) I’d definitely use TreeTable functionality integrated with Grid. Has anything been done in that area since this posting 2 years ago? Any info - especially pointers to examples - would be much appreciated.

We just resently published this add-on that may help you. There is also another discussion thread about the topic on this forum.

https://vaadin.com/directory#!addon/vaadin-treegrid

Hi Tatu,
Thanks for pointing me to TreeGrid. But I’m having some difficulty trying to figure out how I would use it in the context of my application. I currently have a “framework” class that uses a Grid with a BeanItemContainer to display rows of my database data. I.e., I take advantage of the fact that my rows are all Java Beans and you provide a convenient class to display beans. I was trying to extend this framework class to also allow me to display hierarchical data - still Java Beans - but hierarchical in nature - using TreeGrid. But looking at the example code, it seems like one has to extend HierarchicalContainer - which, isn’t a BeanItemContainer. Since Java only has single inheritance, does that mean I basically have to re-implement BeanItemContainer myself? Or is there a “hierarchical” class that subclasses it already?

Any info/help would be much appreciated,
Tom

BeanItemContainer is not a subclass of HierarchicalContainer, nor it implements interface Container.Hierarchical. However I think it should be rather straightforward excercise to implement MyContainer extends BeanItemContainer implements Container.Hierarchical type of container.

You can in fact see one example of that in the treegrid’s demo project.

-Olli