カスタムGWTセルタブルクラスをどのように作成しますか?
-
14-11-2019 - |
質問
私は、ユーザーがデータベース内のレコードを更新/削除することを可能にするGWTで作成可能なセルタブルを持っています。この種のテーブルは、非常に最小限の変更(同じタイプのすべての列、列ヘッダーのタイトルを変更できるだけで、同じ数の列)で約10の異なる場所で使用されます。
カスタムセルタブルクラスの作成方法はありますか?どこでもボイラープレートコードをコピーして貼り付けるための恥になるでしょう。
解決
In short, there is nothing preventing you from extending CellTable. It can be extended just like any other java class.
For example, Let us use a CellTable of such:
CellTable<Contact> table = new CellTable<Contact>();
TextColumn<Contact> nameColumn = new TextColumn<Contact>() { /* ... */ };
table.addColumn(nameColumn, "Name");
TextColumn<Contact> addressColumn = new TextColumn<Contact>() { /* ... */ };
table.addColumn(addressColumn, "Address");
table.setRowData( /* ... */ );
You could extract it into your own class like so:
public class MyCellTable extends CellTable<Contact>{
public MyCellTable(String col1, String col2){
TextColumn<Contact> nameColumn = new TextColumn<Contact>() { /* ... */ };
table.addColumn(nameColumn, col1);
TextColumn<Contact> addressColumn = new TextColumn<Contact>() { /* ... */ };
table.addColumn(addressColumn, col2);
}
}
By extending the CellTable, you can use your cell table like any other.
MyCellTable table = new MyCellTable("Name", "Address");
table.setRowData( /* ... */ );
所属していません StackOverflow