Gwt 为什么在CellTable中没有合适的CompositeCell示例?

Gwt 为什么在CellTable中没有合适的CompositeCell示例?,gwt,cell,composite,gwt-celltable,Gwt,Cell,Composite,Gwt Celltable,我已经搜索了GoogleCode、GWT ShowCase、GWT开发者笔记和Google小组,了解如何获取/设置CompositeCell的值。没有一个明确的例子解释如何在CellTable中使用它 让我们看看一些代码。。。首先是一个抽象类 公共抽象类ToggleableGrid扩展了CellTable{ 私有静态最终字符串默认值_TABLE_WIDTH=“100%”; 私有静态最终显示模式默认\ U模式=DisplayMode.VIEW; 受保护的void setDefaults(){ 设置

我已经搜索了GoogleCode、GWT ShowCase、GWT开发者笔记和Google小组,了解如何获取/设置CompositeCell的值。没有一个明确的例子解释如何在CellTable中使用它

让我们看看一些代码。。。首先是一个抽象类

公共抽象类ToggleableGrid扩展了CellTable{
私有静态最终字符串默认值_TABLE_WIDTH=“100%”;
私有静态最终显示模式默认\ U模式=DisplayMode.VIEW;
受保护的void setDefaults(){
设置宽度(默认的表格宽度);
//将消息设置为在表为空时显示。
setEmptyTableWidget(新标签(UiMessages.INSTANCE.no_results());
//添加一个选择模型,以便我们可以选择单元格
最终选择模型选择模型=新的多重选择模型();
setSelectionModel(selectionModel,DefaultSelectionEventManager.createDefaultManager());
}
公共无效设置输入(列表内容){
setInput(内容,默认_模式);
}
公共无效设置输入(列表内容,显示模式){
setDefaults();
resetTableColumns();
final ListDataProvider dataProvider=新ListDataProvider(内容);
final ListHandler sortHandler=新ListHandler(dataProvider.getList());
addColumnSortHandler(sortHandler);
初始化结构(constructMetadata(),sortHandler,模式);
dataProvider.addDataDisplay(此);
}
//看http://stackoverflow.com/questions/3772480/remove-all-columns-from-a-celltable
//强制混凝土类在添加的所有列上保持句柄
私有void resetTableColumns(){
for(最后一列:allColumns()){
移除柱(柱);
}
allColumns().clear();
}
公共布尔值isInEditMode(显示模式currentDisplayMode){
布尔结果=假;
如果(currentDisplayMode==DisplayMode.EDIT){
结果=真;
}
返回结果;
}
受保护的抽象集allColumns();
受保护的抽象表元数据constructMetadata();
受保护的抽象void initializeStructure(TableMetadata元数据、ListHandler sortHandler、DisplayMode);
受保护的void setColumnHorizontalAlignment(列、水平对齐常量对齐){
列。设置水平对齐(对齐);
}
@凌驾
公共void addColumn(列、字符串columnHeaderName){
最终StringBuffer sb=新StringBuffer();
附加(columnHeaderName)附加(“”);
final SafeHtml header=new onlytobeusedgeneratedCodeStringblessedassafehtml(sb.toString());
addColumn(列、标题);
allColumns()。添加(列);
}
}

然后是一个具体的实现

公共类EnergyOfferGrid扩展为TogleableGrid{
私有静态最终整数最大数量价格点数=10;
private Set columns=new HashSet();
@凌驾
受保护的集合allColumns(){
返回列;
}
@凌驾
受保护的TableMetadata构造函数元数据(){
final TableMetadata=new TableMetadata();
//toDo考虑在公共包中保留的预定义集合
//使用坡度
metadata.addColumnMetadata(UiMessages.INSTANCE.use_slope(),新字符串[]{UiMessages.INSTANCE.yes(),UiMessages.INSTANCE.no()},新字符串[]{“true”,“false”});
返回元数据;
}
@凌驾
受保护的void initializeStructure(TableMetadata元数据、ListHandler sortHandler、DisplayMode currentDisplayMode){
addHourColumn(sortHandler);
addUseSlopeColumn(元数据、排序器、currentDisplayMode);
对于(inti=1;i();
//传递此DTO,以便将新条目的价格和mw值保持在一起
最终OfferPriceMwPairDTO newOfferPriceMwPairDTO=新OfferPriceMwPairDTO();
//价格
最终HasCell priceCell=generatePriceCell(colIndex、newOfferPriceMwPairDTO、currentDisplayMode);
hasCells.add(priceCell);
//兆瓦
final HasCell mwCell=generateMwCell(colIndex、newOfferPriceMwPairDTO、currentDisplayMode);
hascell.add(mwCell);
//复合材料
最终CompositeCell priceMwCell=生成复合单元(hasCells);
最终列priceMwColumn=新列(priceMwCell){
@凌驾
公共EnergyOfferTo getValue(EnergyOfferTo energyOffer){
//我们这样做是为了满足匿名类型的契约,
//但要知道,此列的复合单元格将委托给其单个单元格impls以获取值
返回null;
}
};
addColumn(priceMwColumn,String.valueOf(colIndex));
setColumnWidth(priceMwColumn,8,单位为PCT);
setColumnHorizontalAlignment(priceMwColumn、HasHorizontalAlignment.ALIGN_RIGHT);
}
受保护的HasCell generatePriceCell(最终int-colIndex,最终OfferPriceMpairdTo-NewOfferPriceMpaird,显示模式currentDisplayMode){
HasCell-pricell;
if(isInEditMode(currentDisplayMode)){
priceCell=新的HasCell(){
私有TextInputCell单元格=新的TextInputCell();
@凌驾
公共单元getCell(){
返回单元;
}
@凌驾
公共字段更新程序getFieldUpdater(){
返回新的FieldUpdater(){
@凌驾
公共void更新(int索引,energyOfferTo energyOffer,字符串值){
if(value!=null&&!value.isEmpty()){
//数字格式异常应通过事件总线的handle方法捕获和处理
最终双精度值asdouble=NumberFormat.getDecimalFormat().parse(值);
最终BigDecimal价格=BigDecimal.valueOf(valueAsDouble);
最终的offerPriceCurve列表=energyOffer.getOfferPriceCurve();
最终OfferPriceMwPairDTO OfferPriceMwPairDTO=offerPriceCurve.get(colIndex);
如果(offerPriceMwPairDTO==null){//我们有一个新的价格值