我想从xml生成动态单元格表
我的xml包含N个列(详情如下:列名,列类型,可排序,isEditable(Y / N),单元格值等,
问题是如何从变量(动态)xml生成GWT中的Cell Table 即在创建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”?&gt;
&LT; Data neutralizedCatalog =“Repository”&gt;
< 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中用于显示/更新值
答案 0 :(得分:0)
解析XML。将数据获取到列信息对象的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);
}