Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
自定义行和ListDataProvider GWT的CellTable问题_Gwt_Celltable - Fatal编程技术网

自定义行和ListDataProvider GWT的CellTable问题

自定义行和ListDataProvider GWT的CellTable问题,gwt,celltable,Gwt,Celltable,基本上,我要做的是创建一个包含多个部分的CellTable,由一个跨越所有列的自定义行分隔,以描绘这些部分。到目前为止,我正在为表数据使用ListDataProvider,我正在扩展AbstractCellTableProvider并重写buildRowImpl,以便确定何时需要添加自定义行。这在某种程度上是可行的,但并不是所有的行都显示出来,而且由于某种奇怪的原因,当我单击以选择CellTable中的一行时,它会将重复的行随机添加到CellTable中。我不确定我使用的SelectionMod

基本上,我要做的是创建一个包含多个部分的CellTable,由一个跨越所有列的自定义行分隔,以描绘这些部分。到目前为止,我正在为表数据使用ListDataProvider,我正在扩展AbstractCellTableProvider并重写buildRowImpl,以便确定何时需要添加自定义行。这在某种程度上是可行的,但并不是所有的行都显示出来,而且由于某种奇怪的原因,当我单击以选择CellTable中的一行时,它会将重复的行随机添加到CellTable中。我不确定我使用的SelectionModel是否出现了一些奇怪的情况,但如果有人能够提供帮助,我将不胜感激

下面是我创建的类,它扩展了AbstractCellTableBuilder。默认的行生成器基本上是从buildRowImpl通常执行的操作复制而来的。如果ListDataProvider行值使用If语句与特定条件匹配,则会将其发送到创建单个单元格行的my buildExtraRow

    public class CustomCellTableBuilder extends AbstractCellTableBuilder<SearchColumn>{
    public CustomCellTableBuilder() {

        super(cellTable_2);
        System.out.println("Getting into CustomCellTableBuilder super");
    }

    @Override
    protected void buildRowImpl(SearchColumn rowValue, int absRowIndex){
       //building main rows logic
        System.out.println("Getting into custom buildRowImpl, labelrow = " + labelrow);

        if (rowValue.quantity.equals("test")){
            System.out.println("Going to build extra row if");
            buildExtraRow(absRowIndex, rowValue);
        }
        else {
            System.out.println("rowValue: " + rowValue);
             final String evenRowStyle;
               final String oddRowStyle;
               final String selectedRowStyle;
               final String cellStyle;
               final String evenCellStyle;
               final String oddCellStyle;
               final String firstColumnStyle;
               final String lastColumnStyle;
               final String selectedCellStyle;

               Style style = cellTable_2.getResources().style();
                evenRowStyle = style.evenRow();
                oddRowStyle = style.oddRow();
                selectedRowStyle = " " + style.selectedRow();
                cellStyle = style.cell();
                evenCellStyle = " " + style.evenRowCell();
                oddCellStyle = " " + style.oddRowCell();
                firstColumnStyle = " " + style.firstColumn();
                lastColumnStyle = " " + style.lastColumn();
                selectedCellStyle = " " + style.selectedRowCell();

            // Calculate the row styles.
            SelectionModel<? super SearchColumn> selectionModel = cellTable_2.getSelectionModel();
            boolean isSelected =
                (selectionModel == null || rowValue == null) ? false : selectionModel.isSelected(rowValue);
            boolean isEven = absRowIndex % 2 == 0;
            StringBuilder trClasses = new StringBuilder(isEven ? evenRowStyle : oddRowStyle);
            if (isSelected) {
              trClasses.append(selectedRowStyle);
            }

            // Add custom row styles.
            RowStyles<SearchColumn> rowStyles = cellTable_2.getRowStyles();
            if (rowStyles != null) {
              String extraRowStyles = rowStyles.getStyleNames(rowValue, absRowIndex);
              if (extraRowStyles != null) {
                trClasses.append(" ").append(extraRowStyles);
              }
            }

            // Build the row.
            TableRowBuilder tr = startRow();
            tr.className(trClasses.toString());

            // Build the columns.
            int columnCount = cellTable_2.getColumnCount();
            System.out.println("column count " + columnCount);
            for (int curColumn = 0; curColumn < columnCount; curColumn++) {
              Column<SearchColumn, ?> column = cellTable_2.getColumn(curColumn);
              // Create the cell styles.
              StringBuilder tdClasses = new StringBuilder(cellStyle);
              tdClasses.append(isEven ? evenCellStyle : oddCellStyle);
              if (curColumn == 0) {
                tdClasses.append(firstColumnStyle);
              }
              if (isSelected) {
                tdClasses.append(selectedCellStyle);
              }
              // The first and last column could be the same column.
              if (curColumn == columnCount - 1) {
                tdClasses.append(lastColumnStyle);
              }

              // Add class names specific to the cell.
              Cell.Context context = new Cell.Context(absRowIndex, curColumn, cellTable_2.getValueKey(rowValue));
              String cellStyles = column.getCellStyleNames(context, rowValue);
              if (cellStyles != null) {
                tdClasses.append(" " + cellStyles);
              }

              // Build the cell.
              HorizontalAlignmentConstant hAlign = column.getHorizontalAlignment();
              VerticalAlignmentConstant vAlign = column.getVerticalAlignment();
              TableCellBuilder td = tr.startTD();
              td.className(tdClasses.toString());
              if (hAlign != null) {
                td.align(hAlign.getTextAlignString());
              }
              if (vAlign != null) {
                td.vAlign(vAlign.getVerticalAlignString());
              }
              // Add the inner div.
              DivBuilder div = td.startDiv();
              div.style().outlineStyle(OutlineStyle.NONE).endStyle();

              // Render the cell into the div.
              renderCell(div, context, column, rowValue);

              // End the cell.
              div.endDiv();
              td.endTD();
            }

            // End the row.
            tr.endTR();
        }
    }

    private void buildExtraRow(int absRowIndex, SearchColumn rowValue){
        System.out.println("In buildExtraRow");
        start(true);
        TableRowBuilder row = startRow();
        TableCellBuilder td = row.startTD().colSpan(getColumns().size());
        td.text(label).endTD();
        row.endTR();

        //cellTable_2.redrawRow(absRowIndex);
    }}

与此相关的另一个我感到困惑的问题是ListDataProvider如何与CellTable一起工作。我似乎无法根据ListDataProvider中的内容确定CellTable何时刷新,以及如何根据ListDataProvider中的内容将行添加到CellTable中。

我确定了问题所在,以防将来有人出现问题。单击行时,它会根据选择模型重新绘制该行。所以它重新绘制了行,但由于我已经重写了buildRowImpl,它只是调用了我的自定义行创建,因此它将添加到表中,而不是重新绘制单击的行

searchProvider.getList().add(new SearchColumn("test","","","","","","","",""));