开发者

GWT Generate dynamic CellTable

I want to generate dynamic cell table from xml

My xml contains N number of columns (with Details like - columnn name, column type, sortable, isEditable (Y/N),values for a cell etc.,

P开发者_StackOverflow社区roblem is How to generate Cell Table in GWT from a variant(dynamic) xml i.e While creating Cell Table we don't know how many column are present, we don't know about there type, isEditable, isSortable etc.

I can parse xml. Now I want to generate dynamic table I created BeanInfo class which is used for getters and setters. How I can create dynamic getters and setters for these dynamic column(attribute of Bean) and how can set the value in the bean?

Pseudo code:

// 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();
                }
            });

My xml is as follows:

< ?xml version="1.0" encoding="UTF-8"?>

< Data neutralizedCatalog="Repository">

< 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>

From above xml I want to generate Celltable. In above xml example contains col name,datatype etc and values.

How to generate dynamic getters and setter based on xml and used in celltable to display/update value


Parse XML. Get data into ArrayList of column info objects ( for example).

columns.get(0).type - type of column 1

columns.get(0).name - name of column 1

For each column, depending on type and parameters, add column to 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);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜