Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » scout » Table with dynamic number of columns
Table with dynamic number of columns [message #889307] Tue, 19 June 2012 05:34 Go to next message
Patrick Bänziger is currently offline Patrick BänzigerFriend
Messages: 27
Registered: September 2011
Junior Member
Hello everyone

In my application, I need to create a form describing a set of „changes". Usually those are describe in a „Name-Value" like style.
Until now, I used a table with a single column (String column with HTML) to describe the changes, using multiline-cells. Something like this:

Event name: Birthday party
Location: Grand Central Park
Duration: 180 minutes

Event name: Funeral
Location: Grand Central Cemetery
Duration: 60 minutes

Now the question came up whether we could transform this into a horizontal form (i.e. a table with more than one column).

While one set of changes would have the same number of columns, another set may have a larger (or smaller) number of columns.
Until now, I just had a fixed number of columns or made as many columns as one might need (and just hide the ones that are not necessary).

But in general (or for an unknown number of columns, is it possible in Scout to tell a table at runtime to create N columns which we can then fill?

Re: Table with dynamic number of columns [message #889338 is a reply to message #889307] Tue, 19 June 2012 06:19 Go to previous messageGo to next message
Adrian MoserFriend
Messages: 67
Registered: March 2011
Have a look at AbstractTableCustomizer.
If you override injectCustomColumns(), you can add columns to the list at runtime.

You need to add your TableCustomizer to your table by overriding
public ITableCustomizer getTableCustomizer()

Hope that helps

[Updated on: Tue, 19 June 2012 06:23]

Report message to a moderator

Re: Table with dynamic number of columns [message #889381 is a reply to message #889307] Tue, 19 June 2012 07:19 Go to previous messageGo to next message
Ivan Motsch is currently offline Ivan MotschFriend
Messages: 100
Registered: March 2010
Senior Member
This is an example:

import java.util.ArrayList;
import java.util.List;

import org.eclipse.scout.commons.annotations.Order;
import org.eclipse.scout.commons.exception.ProcessingException;
import org.eclipse.scout.rt.client.ui.basic.cell.Cell;
import org.eclipse.scout.rt.client.ui.basic.table.AbstractTable;
import org.eclipse.scout.rt.client.ui.basic.table.HeaderCell;
import org.eclipse.scout.rt.client.ui.basic.table.ITableRow;
import org.eclipse.scout.rt.client.ui.basic.table.columns.AbstractColumn;
import org.eclipse.scout.rt.client.ui.basic.table.columns.AbstractDoubleColumn;
import org.eclipse.scout.rt.client.ui.basic.table.columns.AbstractLongColumn;
import org.eclipse.scout.rt.client.ui.basic.table.columns.IColumn;
import org.eclipse.scout.rt.client.ui.desktop.outline.pages.AbstractPageWithTable;
import org.eclipse.scout.rt.client.ui.desktop.outline.pages.ISearchForm;
import org.eclipse.scout.rt.shared.TEXTS;
import org.eclipse.scout.service.SERVICES;

public class DynamicColumnsTablePage extends AbstractPageWithTable<DynamicColumnsTablePage.Table> {
  private List<IColumn<?>> m_injectedColumns;

  protected String getConfiguredIconId() {
    return Icons.TreeNode;

  protected boolean getConfiguredLeaf() {
    return true;

  protected Class<? extends ISearchForm> getConfiguredSearchForm() {
    return DynamicDataSearchForm.class;

  protected boolean getConfiguredSearchRequired() {
    return true;

  protected String getConfiguredTitle() {
    return TEXTS.get("DynamicColumns");

  protected Object[][] execLoadTableData(SearchFilter filter) throws ProcessingException {
    DynamicDataSearchFormData formData = (DynamicDataSearchFormData) filter.getFormData();
    DynamicDataMatrixData matrixData = SERVICES.getService(IDynamicDataPageService.class).getStatisticsMatrixData(formData);
    if (matrixData == null) {
      return new Object[0][];
    //create dynamic columns based on matrix data assuming matrixData has a property "getColumnSpecs" with  bean ColumnSpec
    //fill rows
    return matrixData.getRows();
  private void updateDynamicColumns(ColumnSpec[] columnSpecs) throws ProcessingException {
    if (columnSpecs.length == 0) {
    Table table = getTable();
    m_injectedColumns = new ArrayList<IColumn<?>>();
    for (ColumnSpec spec: columnSpecs) {
      //XXX switch on spec.getType() or something like that...
      m_injectedColumns.add(createDynamicDoubleColumn(spec.getId(), spec.getText()));

  private IColumn<?> createDynamicDoubleColumn(final String columnId, final String label) {
    return new AbstractDoubleColumn() {
      protected String getConfiguredHeaderText() {
        return label;

      public String getColumnId() {
        return columnId;

      protected int getConfiguredWidth() {
        return 120;

      protected Double execParseValue(ITableRow row, Object rawValue) throws ProcessingException {
        rawValue = preprocessDynamicColumnsCell(this, row, rawValue);
        return super.execParseValue(row, rawValue);

   * @return {@link DecoratedValue#getValue()} after decorating the table cell
  private Object preprocessDynamicColumnsCell(IColumn<?> col, ITableRow row, Object rawValue) throws ProcessingException {
    DecoratedValue rawCell = (DecoratedValue) rawValue;
    if (rawCell != null) {
      return rawCell.getValue();
    return rawValue;

  public class Table extends AbstractTable {

    protected boolean getConfiguredSortEnabled() {
      return false;

    protected void injectColumnsInternal(List<IColumn<?>> columnList) {
      if (m_injectedColumns != null) {

icon14.gif  Re: Table with dynamic number of columns [message #889480 is a reply to message #889307] Tue, 19 June 2012 09:19 Go to previous message
Patrick Bänziger is currently offline Patrick BänzigerFriend
Messages: 27
Registered: September 2011
Junior Member
Great, thank you both for your speedy replies!
Previous Topic:migrate from 3.7 to 3.8
Next Topic:Provide Service Config Properties from Plug-in
Goto Forum:

Current Time: Thu Nov 26 00:48:32 GMT 2015

Powered by FUDForum. Page generated in 0.02439 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software