简体   繁体   English

我将如何创建自定义GWT CellTable类?

[英]How would I create a custom GWT CellTable class?

I have a CellTable created in GWT that allows users to update/delete records in a database. 我在GWT中创建了一个CellTable,它允许用户更新/删除数据库中的记录。 This kind of table will be used in about 10 different places with very minimal changes (same number of columns, all with the same type, just need to be able to change the column header titles). 这种表将在大约10个不同的地方使用,并且变化非常小(相同数量的列,都具有相同的类型,只需要能够更改列标题即可)。

How would I go about creating a custom CellTable class? 我将如何创建自定义CellTable类? It'd be a shame to have to copy and paste boilerplate code everywhere. 必须在各处复制和粘贴样板代码真是可惜。

In short, there is nothing preventing you from extending CellTable. 简而言之,没有什么可以阻止您扩展CellTable。 It can be extended just like any other java class. 可以像其他任何Java类一样对其进行扩展。

For example, Let us use a CellTable of such: 例如,让我们使用如下的CellTable:

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. 通过扩展CellTable,您可以像其他任何单元格一样使用单元格表。

MyCellTable table = new MyCellTable("Name", "Address");
table.setRowData( /* ... */ );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM