我想从xml生成动态单元格表
我的xml包含N个列(详细信息如-列名称,列类型,可排序,可编辑(Y/N),单元格值等),
问题是如何从变体(动态)xml生成GWT中的单元格表例如,在创建Cell Table时,我们不知道有多少列,也不知道它的类型,isEditable, isSortable等。
我可以解析xml。现在我要生成动态表我创建了BeanInfo类,它用于getter和setter。如何为这些动态列(Bean的属性)创建动态getter和setter,以及如何在Bean中设置值?
伪代码:
// dynamic column.
final Column<BeanInfo, String> dynamicGwtColumn = new Column<BeanInfo, String>(
new DynamicDataTypeCell()) {
@Override
public String getValue(BeanInfo object) {
return object.getDyncamicCellValue();
}
};
dynamicGwtColumn .setSortable(true);
sortHandler.setComparator(dynamicGwtColumn ,
new Comparator<BeanInfo >() {
public int compare(BeanInfo o1, BeanInfo o2) {
return o1..getDyncamicCellValue().compareTo(o2.getDyncamicCellValue());
}
});
cellTable.addColumn(dynamicGwtColumn , "Record ID");
dynamicGwtColumn
.setFieldUpdater(new FieldUpdater<BeanInfo, String>() {
public void update(int index, BeanInfo object,
String value) {
// Called when the user changes the value.
object.setDyncamicCellValue(value);
dataProvider.refresh();
}
});
我的xml文件如下:
& lt;?xml version="1.0" encoding="UTF-8"?>
& lt;数据neutralizedCatalog = "库">
< MetaData>
< RecordAttribute name="ID" displayname="ID" columnname="CID" datatype="VARCHAR2" sortable="true" accessmode="modify" showmvpd="false" length="255" integerlength="0" fractionallength="0" />
< RecordAttribute name="Name" displayname="Name" columnname="CNAME" datatype="VARCHAR2" sortable="true" accessmode="modify" showmvpd="false" length="255" integerlength="0" fractionallength="0" />
< RecordAttribute name="custom1" displayname="custom1" columnname="CCUSTOM1" datatype="VARCHAR2" sortable="true" accessmode="modify" showmvpd="false" length="256" integerlength="0" fractionallength="0" />
</MetaData>
<Records>
< RecordAttribute name="CID" edited="false">
<Value />
</RecordAttribute>
< RecordAttribute name="CNAME" edited="false">
<Value />
</RecordAttribute>
< RecordAttribute name="CCUSTOM1" edited="false">
<Value />
</RecordAttribute>
</Record><Records>
<Recordid="17" name="17" productkeyid="13012" selected="false" accessmode="modify" isedited="false">
<RecordAttribute name="CID" edited="false">
<Value>17</Value>
<OldValue>17</OldValue>
</RecordAttribute>
<RecordAttribute name="CNAME" edited="false">
<Value>17</Value>
<OldValue>17</OldValue>
</RecordAttribute>
<RecordAttribute name="CCUSTOM1" edited="false">
<Value>17</Value>
<OldValue>17</OldValue>
</RecordAttribute>
</Record>
从上面的xml我想生成Celltable。在上面的xml示例中包含col名称,数据类型等和值。
如何生成基于xml的动态getter和setter,并在celltable中用于显示/更新值
解析XML。获取数据到列info对象的ArrayList中(例如)
columns.get(0).type - type of column 1
columns.get(0).name - name of column 1
对于每个列,根据类型和参数,在cellTable
中添加列CellTable<BeanInfo> cellTable = new CellTable<BeanInfo >();
for(AxCol col : columns)) {
Column<BeanInfo, java.lang.Object> cellTableColumn = null;
AbstractCell cellTableCell = null;
if(col.type == "string"){
cellTableCell = new TextCell();
cellTableColumn = new Column<BeanInfo, java.lang.Object>(cellTableCell) {
@Override
public String getValue(BeanInfo object) {
return (BeanInfo) object.getValue();
}
};
}
if(col.type == "image"){
cellTableCell = new ImageCell();
cellTableColumn = new Column<BeanInfo, java.lang.Object>(cellTableCell) {
@Override
public String getValue(BeanInfo object) {
return (BeanInfo) object.getValueForImage();
}
};
}
cellTable.addColumn(cellTableColumn);
}