Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Scout/Concepts/TableData

< Scout‎ | Concepts
Revision as of 03:22, 15 October 2013 by Jeremie.bresson.unblu.com (Talk | contribs) (Created page with "{{ScoutPage|cat=Shared}} TableData is the data transfert object for {{ScoutLink|Concepts|Table}}. == Description == TableData is contained in a {{ScoutLink|Concepts|FormData}...")

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

The Scout documentation has been moved to https://eclipsescout.github.io/. TableData is the data transfert object for The Scout documentation has been moved to https://eclipsescout.github.io/..

Description

TableData is contained in a The Scout documentation has been moved to https://eclipsescout.github.io/. or in a The Scout documentation has been moved to https://eclipsescout.github.io/. to hold the content of a The Scout documentation has been moved to https://eclipsescout.github.io/. (of a The Scout documentation has been moved to https://eclipsescout.github.io/. or of a The Scout documentation has been moved to https://eclipsescout.github.io/.).

There are two different kinds of TableData:

  • Array based TableData
  • Bean based TableData

Concrete TableData extends abstract classes (different one depending on the type of table data, see below) and are generated by the SDK given the concrete table (in the TableField or in the TablePage).

The bean based tableData was introduced with Scout 3.10.0. It makes inheritance possible: the TableData has the same inheritance graph as the Table.

Usage

Client side, you can import and export the table content of a TableField with importFormData() and exportFormData(). For a table in a TablePage, there is a importPageData() function.

Server side, the SQL Support from Eclipse Scout works with TableData. bug 419140 (work in progress)

Array based TableData

The Scout documentation has been moved to https://eclipsescout.github.io/.

This kind of Table Data is used by default in FormData and is not available for TablePage. It stores the row content as array, and provides some getter and setter methods to ensure that the row content is properly type casted.

Example

public static class Table extends AbstractTableFieldData {
 
  private static final long serialVersionUID = 1L;
  public static final int ID_COLUMN_ID = 0;
  public static final int NAME_COLUMN_ID = 1;
 
  public Table() {
  }
 
  public Long getId(int row) {
    return (Long) getValueInternal(row, ID_COLUMN_ID);
  }
 
  public void setId(int row, Long id) {
    setValueInternal(row, ID_COLUMN_ID, id);
  }
 
  public String getName(int row) {
    return (String) getValueInternal(row, NAME_COLUMN_ID);
  }
 
  public void setName(int row, String name) {
    setValueInternal(row, NAME_COLUMN_ID, name);
  }
 
  @Override
  public int getColumnCount() {
    return 2;
  }
 
  @Override
  public Object getValueAt(int row, int column) {
    switch (column) {
      case ID_COLUMN_ID:
        return getId(row);
      case NAME_COLUMN_ID:
        return getName(row);
      default:
        return null;
    }
  }
 
  @Override
  public void setValueAt(int row, int column, Object value) {
    switch (column) {
      case ID_COLUMN_ID:
        setId(row, (Long) value);
        break;
      case NAME_COLUMN_ID:
        setName(row, (String) value);
        break;
    }
  }
}

Bean based TableData

Important.png
Required version
The API described here requires version 3.10.0 or bigger.


The Scout documentation has been moved to https://eclipsescout.github.io/.

This kind of TableData is used by default in TablePageData. It is also possible to use it for a Table Field using the The Scout documentation has been moved to https://eclipsescout.github.io/. to control the generation of FormData.

In bean based TableData, a row is represented by a bean. Like in any bean, a java field, a setter and a getter is generated for each column.

Using bean based TableData for TableField

To use it in FormData for Table Field, the table field needs to be annotated with:

@FormData(sdkCommand = SdkCommand.USE, value = AbstractTableFieldBeanData.class, defaultSubtypeSdkCommand = DefaultSubtypeSdkCommand.CREATE)
public class TableField extends AbstractTableField {
  //... Table inner class.
}

If you work with template (for a table field), you need to add an empty TableField template (that does not contain any Table) on top of your hierarchy to indicate that want to use bean based table data:

  • AbstractTableBeanField
    • annotation:
      @FormData(sdkCommand = SdkCommand.USE, value = AbstractTableFieldBeanData.class, defaultSubtypeSdkCommand = DefaultSubtypeSdkCommand.CREATE)
    • class declaration:
      AbstractTableBeanField<T extends ITable> extends AbstractTableField<T>
    • no table included
  • AbstractPersonTableField
    • annotation:
      @FormData(sdkCommand = SdkCommand.CREATE, value = AbstractPersonTableFieldData.class)
    • form-field declaration:
      AbstractPersonTableField<T extends PersonTable> extends AbstractTableBeanField<T>
    • table:
      PersonTable extends AbstractExtensibleTable
    • table columns: IdColumn (Long) and NameColumn (String)
  • PersonWithAgeTableField
    • no specific FormData annotation
    • form-field declaration:
      PersonWithAgeTableField extends AbstractPersonTableField<PersonWithAgeTable>
    • table:
      PersonWithAgeTable extends PersonTable
    • table columns: AgeColumn (Integer)

Example

public static class Table extends AbstractTableFieldBeanData {
 
  private static final long serialVersionUID = 1L;
 
  public Table() {
  }
 
  @Override
  public TableRowData addRow() {
    return (TableRowData) super.addRow();
  }
 
  @Override
  public TableRowData addRow(int rowState) {
    return (TableRowData) super.addRow(rowState);
  }
 
  @Override
  public TableRowData createRow() {
    return new TableRowData();
  }
 
  @Override
  public Class<? extends AbstractTableRowData> getRowType() {
    return TableRowData.class;
  }
 
  @Override
  public TableRowData[] getRows() {
    return (TableRowData[]) super.getRows();
  }
 
  @Override
  public TableRowData rowAt(int index) {
    return (TableRowData) super.rowAt(index);
  }
 
  public void setRows(TableRowData[] rows) {
    super.setRows(rows);
  }
 
  public static class TableRowData extends AbstractTableRowData {
 
    private static final long serialVersionUID = 1L;
    public static final String id = "id";
    public static final String name = "name";
    private Long m_id;
    private String m_name;
 
    public TableRowData() {
    }
 
    public Long getId() {
      return m_id;
    }
 
    public void setId(Long id) {
      m_id = id;
    }
 
    public String getName() {
      return m_name;
    }
 
    public void setName(String name) {
      m_name = name;
    }
  }
}

See Also

Back to the top