我假設您要製作一張顯示您的小桌子行的大桌子:
table1 table2
col1 | col2 | col3 col1 | col2 | col3 | col4
------------------ -------------------------
a | b | c 1 | 2 | 3 | 4
big table
col1 | col2 | col3 | col1 | col2 | col3 | col4
----------------------------------------------
a | b | c | 1 | 2 | 3 | 4
與例如
CellTable<String[]> table1 = new CellTable<String[]>();
table1.addColumn(new Column<String[], String>(new TextCell()){
public String getValue(String[] object){
return object[0];
}
}, "col1");
此解決方案僅適用,如果你可以編輯源代碼構建小桌子!
我首先定義一個行對象類,它包含大表中單個行的全部信息,例如,
public class RowObject{
public String[] table1RowObject; // the class of the field should be the generic
// type of the table1 CellTable
public MyObject table2RowObject; // the class of the field should
// be the generic type of table2
// ... other tables
}
現在改變泛型類型的小表來RowObject
:
CellTable<RowObject> table1 = new CellTable<RowObject>();
table1.addColumn (new Column<RowObject, String>(new TextCell()){
public String getValue(RowObject object){
// The data of table1 has been moved into the table1RowObject
// old: String[] object; return object[0];
return object.table1RowObject[0];
}
}, "col1");
那麼大的表可以很容易地構造這樣的:
CellTable<RowObject> bigTable = new CellTable<RowObject>();
for (CellTable<RowObject> ct : tablesList){
for (int i = 0; i < ct.getColumnCount(); i++)
bigTable.addColumn(ct.getColumn(i));
}
加載數據的所有表同時在數據提供者的幫助下,例如,
ListDataProvider<RowObject> dataSource = new ListDataProvider<RowObject>();
dataSource.addDataDisplay(table1);
dataSource.addDataDisplay(table2);
dataSource.addDataDisplay(bigTable);
,然後只要你更新dataSource
所有的小表,可能得到在同一時間爲大表進行更新。