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

Difference between revisions of "Scout/Concepts/TableData"

(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}...")
 
(Replaced content with "The Scout documentation has been moved to https://eclipsescout.github.io/.")
 
(3 intermediate revisions by one other user not shown)
Line 1: Line 1:
{{ScoutPage|cat=Shared}}
+
The Scout documentation has been moved to https://eclipsescout.github.io/.
TableData is the data transfert object for {{ScoutLink|Concepts|Table}}.
+
 
+
== Description ==
+
TableData is contained in a {{ScoutLink|Concepts|FormData}} or in a {{ScoutLink|Concepts|TablePageData}} to hold the content of a {{ScoutLink|Concepts|Table}} (of a {{ScoutLink|Concepts|TableField}} or of a {{ScoutLink|Concepts|TablePage}}).
+
 
+
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 ==
+
{{ScoutJavadoc|AbstractTableFieldData|C}}
+
 
+
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 ===
+
<source lang="java">
+
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;
+
    }
+
  }
+
}
+
</source>
+
 
+
== Bean based TableData ==
+
{{important|Required version|The API described here requires version 3.10.0 or bigger.}}
+
 
+
{{ScoutJavadoc|AbstractTableFieldBeanData|C}}
+
 
+
This kind of TableData is used by default in TablePageData. It is also possible to use it for a Table Field using the {{ScoutJavadoc|FormData|A}} 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:
+
<source lang="java">
+
@FormData(sdkCommand = SdkCommand.USE, value = AbstractTableFieldBeanData.class, defaultSubtypeSdkCommand = DefaultSubtypeSdkCommand.CREATE)
+
public class TableField extends AbstractTableField {
+
  //... Table inner class.
+
}
+
</source>
+
 
+
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: <source lang="java">@FormData(sdkCommand = SdkCommand.USE, value = AbstractTableFieldBeanData.class, defaultSubtypeSdkCommand = DefaultSubtypeSdkCommand.CREATE)</source>
+
** class declaration: <source lang="java">AbstractTableBeanField<T extends ITable> extends AbstractTableField<T></source>
+
** no table included
+
* AbstractPersonTableField
+
** annotation: <source lang="java">@FormData(sdkCommand = SdkCommand.CREATE, value = AbstractPersonTableFieldData.class)</source>
+
** form-field declaration: <source lang="java">AbstractPersonTableField<T extends PersonTable> extends AbstractTableBeanField<T></source>
+
** table: <source lang="java">PersonTable extends AbstractExtensibleTable</source>
+
** table columns: IdColumn (Long) and NameColumn (String)
+
* PersonWithAgeTableField
+
** no specific FormData annotation
+
** form-field declaration: <source lang="java">PersonWithAgeTableField extends AbstractPersonTableField<PersonWithAgeTable></source>
+
** table: <source lang="java">PersonWithAgeTable extends PersonTable</source>
+
** table columns: AgeColumn (Integer)
+
 
+
=== Example ===
+
<source lang="java">
+
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;
+
    }
+
  }
+
}
+
</source>
+
 
+
== See Also ==
+
* {{ScoutLink|Concepts|FormData}}
+
* {{ScoutLink|Concepts|TablePageData}}
+
* {{ScoutLink|Concepts|Shared Plug-In|Shared Plug-In}}
+

Latest revision as of 05:22, 14 March 2024

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

Back to the top