ComponentGridDecorator implements Serializable { public ComponentGridDecorator<T> generateHeaders(ComponentHeaderGenerator generator) { for (Grid.Column column : grid.getColumns()) { grid.getDefaultHeaderRow() .getCell(column.getPropertyId()) .setComponent(generator.getHeader(column.getPropertyId())); } return this; } ComponentGridDecorator(Grid grid, Class<T> typeOfRows); FocusPreserveExtension getFocusPreserveExtension(); Grid getGrid(); Grid.Column addComponentColumn(Object propertyId, ComponentGenerator<T> generator); ComponentGridDecorator<T> setRows(Collection<T> beans); ComponentGridDecorator<T> addAll(Collection<T> beans); ComponentGridDecorator<T> remove(T bean); ComponentGridDecorator<T> add(T bean); ComponentGridDecorator<T> refresh(); ComponentGridDecorator<T> generateHeaders(ComponentHeaderGenerator generator); ComponentGridDecorator<T> generateHeaders(TextHeaderGenerator generator); ComponentGridDecorator<T> generateHeaders(HtmlHeaderGenerator generator);  }
@Test public void testGenerateTextHeaders() { Grid grid = createTestGrid(); ComponentGridDecorator<ExampleBean> decorator = new ComponentGridDecorator<>(grid, ExampleBean.class); String headerText = grid.getDefaultHeaderRow().getCell(COLUMN_CAPTION).getText(); assertThat(headerText, is("Caption")); decorator.generateHeaders(new TextHeaderGenerator() { @Override public String getHeader(Object propertyId) { return "TEXT:"+ propertyId; } }); headerText = grid.getDefaultHeaderRow().getCell(COLUMN_CAPTION).getText(); assertThat(headerText, is("TEXT:caption")); }
@Test public void testGenerateHtmlHeaders() { Grid grid = createTestGrid(); ComponentGridDecorator<ExampleBean> decorator = new ComponentGridDecorator<>(grid, ExampleBean.class); String headerText = grid.getDefaultHeaderRow().getCell(COLUMN_CAPTION).getText(); assertThat(headerText, is("Caption")); decorator.generateHeaders(new HtmlHeaderGenerator() { @Override public String getHeader(Object propertyId) { return "HTML:<b>"+ propertyId + "</b>"; } }); headerText = grid.getDefaultHeaderRow().getCell(COLUMN_CAPTION).getHtml(); assertThat(headerText, is("HTML:<b>caption</b>")); }
@Test public void testGenerateComponentHeaders() { Grid grid = createTestGrid(); ComponentGridDecorator<ExampleBean> decorator = new ComponentGridDecorator<>(grid, ExampleBean.class); String headerText = grid.getDefaultHeaderRow().getCell(COLUMN_CAPTION).getText(); assertThat(headerText, is("Caption")); decorator.generateHeaders(new ComponentHeaderGenerator() { @Override public Label getHeader(Object propertyId) { return new Label("" + propertyId); } }); Component headerComponent = grid.getDefaultHeaderRow().getCell(COLUMN_CAPTION).getComponent(); assertThat(headerComponent, instanceOf(Label.class)); }