Search in sources :

Example 1 with GroupedDynamicDataRow

use of org.kie.workbench.common.widgets.decoratedgrid.client.widget.data.GroupedDynamicDataRow in project kie-wb-common by kiegroup.

the class AbstractMergableGridWidget method cloneDynamicDataRow.

@SuppressWarnings({ "rawtypes", "unchecked" })
private DynamicDataRow cloneDynamicDataRow(GroupedDynamicDataRow sourceRowData) {
    GroupedDynamicDataRow rowData = new GroupedDynamicDataRow();
    for (int iCol = 0; iCol < sourceRowData.size(); iCol++) {
        CellValue<? extends Comparable<?>> sourceCell = sourceRowData.get(iCol);
        CellValue.GroupedCellValue cell = sourceCell.convertToGroupedCell();
        if (sourceCell instanceof CellValue.GroupedCellValue) {
            CellValue.GroupedCellValue groupedSourceCell = (CellValue.GroupedCellValue) sourceCell;
            if (groupedSourceCell.isGrouped()) {
                cell.addState(CellValue.CellState.GROUPED);
            }
            if (groupedSourceCell.isOtherwise()) {
                cell.addState(CellValue.CellState.OTHERWISE);
            }
        }
        rowData.add(cell);
    }
    for (DynamicDataRow childRow : sourceRowData.getChildRows()) {
        rowData.addChildRow(cloneRow(childRow));
    }
    return rowData;
}
Also used : GroupedDynamicDataRow(org.kie.workbench.common.widgets.decoratedgrid.client.widget.data.GroupedDynamicDataRow) DynamicDataRow(org.kie.workbench.common.widgets.decoratedgrid.client.widget.data.DynamicDataRow) GroupedDynamicDataRow(org.kie.workbench.common.widgets.decoratedgrid.client.widget.data.GroupedDynamicDataRow)

Example 2 with GroupedDynamicDataRow

use of org.kie.workbench.common.widgets.decoratedgrid.client.widget.data.GroupedDynamicDataRow in project kie-wb-common by kiegroup.

the class AbstractMergableGridWidget method applyModelGrouping.

// Apply grouping by collapsing applicable rows
private void applyModelGrouping(CellValue<?> startCell, boolean bRedraw) {
    data.applyModelGrouping(startCell);
    // Partial redraw
    if (bRedraw) {
        int startRowIndex = startCell.getCoordinate().getRow();
        GroupedDynamicDataRow groupedRow = (GroupedDynamicDataRow) data.get(startRowIndex);
        int minRedrawRow = findMinRedrawRow(startRowIndex - (startRowIndex > 0 ? 1 : 0));
        int maxRedrawRow = findMaxRedrawRow(startRowIndex + (startRowIndex < data.size() - 1 ? 1 : 0));
        for (int iRow = 0; iRow < groupedRow.getChildRows().size() - 1; iRow++) {
            deleteRowElement(startRowIndex);
        }
        redrawRows(minRedrawRow, maxRedrawRow);
        eventBus.fireEvent(ROW_GROUPING_EVENT);
    }
}
Also used : GroupedDynamicDataRow(org.kie.workbench.common.widgets.decoratedgrid.client.widget.data.GroupedDynamicDataRow)

Example 3 with GroupedDynamicDataRow

use of org.kie.workbench.common.widgets.decoratedgrid.client.widget.data.GroupedDynamicDataRow in project kie-wb-common by kiegroup.

the class DynamicDataTestsWithGroupingColumnAdditions method testIndexing_HtmlCoordinates.

@Test
public void testIndexing_HtmlCoordinates() {
    // [1][-][3] --> [1][x][3] --> [0,0][0,1][0,2]
    // [1][2][3] --> [-][2][3] --> [1,0][1,1][1,2]
    // [-][2][3] -->
    CellValue<? extends Comparable<?>> cv = data.get(0).get(0);
    data.setMerged(true);
    data.applyModelGrouping(cv);
    assertEquals(data.size(), 2);
    Coordinate c;
    c = data.get(0).get(0).getHtmlCoordinate();
    assertEquals(c.getRow(), 0);
    assertEquals(c.getCol(), 0);
    c = data.get(0).get(1).getHtmlCoordinate();
    assertEquals(c.getRow(), 0);
    assertEquals(c.getCol(), 1);
    c = data.get(0).get(2).getHtmlCoordinate();
    assertEquals(c.getRow(), 0);
    assertEquals(c.getCol(), 2);
    c = data.get(1).get(0).getHtmlCoordinate();
    assertEquals(c.getRow(), 1);
    assertEquals(c.getCol(), 0);
    c = data.get(1).get(1).getHtmlCoordinate();
    assertEquals(c.getRow(), 1);
    assertEquals(c.getCol(), 1);
    c = data.get(1).get(2).getHtmlCoordinate();
    assertEquals(c.getRow(), 1);
    assertEquals(c.getCol(), 2);
    data.addColumn(3, makeCellValueList(3), true);
    assertEquals(data.size(), 2);
    assertEquals(data.get(0).size(), 4);
    assertEquals(data.get(1).size(), 4);
    assertTrue(data.get(0) instanceof GroupedDynamicDataRow);
    GroupedDynamicDataRow gdr = (GroupedDynamicDataRow) data.get(0);
    assertEquals(gdr.getChildRows().size(), 2);
    assertEquals(gdr.getChildRows().get(0).size(), 4);
    assertEquals(gdr.getChildRows().get(1).size(), 4);
    // [1][-][3][-] --> [1][x][3][-] --> [0,0][0,1][0,2][0,3]
    // [1][2][3][-] --> [-][2][3][-] --> [1,0][1,1][1,2][1,3]
    c = data.get(0).get(0).getHtmlCoordinate();
    assertEquals(c.getRow(), 0);
    assertEquals(c.getCol(), 0);
    c = data.get(0).get(1).getHtmlCoordinate();
    assertEquals(c.getRow(), 0);
    assertEquals(c.getCol(), 1);
    c = data.get(0).get(2).getHtmlCoordinate();
    assertEquals(c.getRow(), 0);
    assertEquals(c.getCol(), 2);
    c = data.get(0).get(3).getHtmlCoordinate();
    assertEquals(c.getRow(), 0);
    assertEquals(c.getCol(), 3);
    c = data.get(1).get(0).getHtmlCoordinate();
    assertEquals(c.getRow(), 1);
    assertEquals(c.getCol(), 0);
    c = data.get(1).get(1).getHtmlCoordinate();
    assertEquals(c.getRow(), 1);
    assertEquals(c.getCol(), 1);
    c = data.get(1).get(2).getHtmlCoordinate();
    assertEquals(c.getRow(), 1);
    assertEquals(c.getCol(), 2);
    c = data.get(1).get(3).getHtmlCoordinate();
    assertEquals(c.getRow(), 1);
    assertEquals(c.getCol(), 3);
}
Also used : Coordinate(org.kie.workbench.common.widgets.decoratedgrid.client.widget.data.Coordinate) GroupedDynamicDataRow(org.kie.workbench.common.widgets.decoratedgrid.client.widget.data.GroupedDynamicDataRow) Test(org.junit.Test)

Example 4 with GroupedDynamicDataRow

use of org.kie.workbench.common.widgets.decoratedgrid.client.widget.data.GroupedDynamicDataRow in project kie-wb-common by kiegroup.

the class AbstractMergableGridWidget method onUpdateColumnData.

public void onUpdateColumnData(UpdateColumnDataEvent event) {
    int iRowIndex = 0;
    int iColIndex = event.getIndex();
    List<CellValue<? extends Comparable<?>>> columnData = event.getColumnData();
    for (int iRow = 0; iRow < data.size(); iRow++) {
        DynamicDataRow row = data.get(iRow);
        CellValue<? extends Comparable<?>> cell = columnData.get(iRowIndex);
        if (row instanceof GroupedDynamicDataRow) {
            GroupedDynamicDataRow groupedRow = (GroupedDynamicDataRow) row;
            // Setting value on a GroupedCellValue causes all children to assume the same value
            groupedRow.get(iColIndex).setValue(cell.getValue());
            // So set the children's values accordingly
            for (int iGroupedRow = 0; iGroupedRow < groupedRow.getChildRows().size(); iGroupedRow++) {
                cell = columnData.get(iRowIndex);
                groupedRow.getChildRows().get(iGroupedRow).get(iColIndex).setValue(cell.getValue());
                iRowIndex++;
            }
        } else {
            row.get(iColIndex).setValue(cell.getValue());
            iRowIndex++;
        }
    }
    data.assertModelMerging();
    redrawColumns(iColIndex, columns.size() - 1);
}
Also used : GroupedDynamicDataRow(org.kie.workbench.common.widgets.decoratedgrid.client.widget.data.GroupedDynamicDataRow) DynamicDataRow(org.kie.workbench.common.widgets.decoratedgrid.client.widget.data.DynamicDataRow) GroupedDynamicDataRow(org.kie.workbench.common.widgets.decoratedgrid.client.widget.data.GroupedDynamicDataRow)

Example 5 with GroupedDynamicDataRow

use of org.kie.workbench.common.widgets.decoratedgrid.client.widget.data.GroupedDynamicDataRow in project kie-wb-common by kiegroup.

the class DynamicDataTestsWithGroupingColumnAdditions method testIndexing_PhysicalCoordinates.

@Test
public void testIndexing_PhysicalCoordinates() {
    // [1][-][3] --> [1][x][3] --> [0,0][0,1][0,2] --> [0,0][0,1][0,2]
    // [1][2][3] --> [-][2][3] --> [1,0][1,1][0,2] --> [1,0][1,1][-,-]
    // [-][2][3] -->
    CellValue<? extends Comparable<?>> cv = data.get(0).get(0);
    data.setMerged(true);
    data.applyModelGrouping(cv);
    assertEquals(data.size(), 2);
    Coordinate c;
    c = data.get(0).get(0).getPhysicalCoordinate();
    assertEquals(c.getRow(), 0);
    assertEquals(c.getCol(), 0);
    c = data.get(0).get(1).getPhysicalCoordinate();
    assertEquals(c.getRow(), 0);
    assertEquals(c.getCol(), 1);
    c = data.get(0).get(2).getPhysicalCoordinate();
    assertEquals(c.getRow(), 0);
    assertEquals(c.getCol(), 2);
    c = data.get(1).get(0).getPhysicalCoordinate();
    assertEquals(c.getRow(), 1);
    assertEquals(c.getCol(), 0);
    c = data.get(1).get(1).getPhysicalCoordinate();
    assertEquals(c.getRow(), 1);
    assertEquals(c.getCol(), 1);
    data.addColumn(3, makeCellValueList(3), true);
    assertEquals(data.size(), 2);
    assertEquals(data.get(0).size(), 4);
    assertEquals(data.get(1).size(), 4);
    assertTrue(data.get(0) instanceof GroupedDynamicDataRow);
    GroupedDynamicDataRow gdr = (GroupedDynamicDataRow) data.get(0);
    assertEquals(gdr.getChildRows().size(), 2);
    assertEquals(gdr.getChildRows().get(0).size(), 4);
    assertEquals(gdr.getChildRows().get(1).size(), 4);
    // [1][-][3][-] --> [1][x][3][-] --> [0,0][0,1][0,2][0,3] --> [0,0][0,1][0,2][0,3]
    // [1][2][3][-] --> [-][2][3][-] --> [1,0][1,1][0,2][0,3] --> [1,0][1,1][-,-][-,-]
    c = data.get(0).get(0).getPhysicalCoordinate();
    assertEquals(c.getRow(), 0);
    assertEquals(c.getCol(), 0);
    c = data.get(0).get(1).getPhysicalCoordinate();
    assertEquals(c.getRow(), 0);
    assertEquals(c.getCol(), 1);
    c = data.get(0).get(2).getPhysicalCoordinate();
    assertEquals(c.getRow(), 0);
    assertEquals(c.getCol(), 2);
    c = data.get(0).get(3).getPhysicalCoordinate();
    assertEquals(c.getRow(), 0);
    assertEquals(c.getCol(), 3);
    c = data.get(1).get(0).getPhysicalCoordinate();
    assertEquals(c.getRow(), 1);
    assertEquals(c.getCol(), 0);
    c = data.get(1).get(1).getPhysicalCoordinate();
    assertEquals(c.getRow(), 1);
    assertEquals(c.getCol(), 1);
}
Also used : Coordinate(org.kie.workbench.common.widgets.decoratedgrid.client.widget.data.Coordinate) GroupedDynamicDataRow(org.kie.workbench.common.widgets.decoratedgrid.client.widget.data.GroupedDynamicDataRow) Test(org.junit.Test)

Aggregations

GroupedDynamicDataRow (org.kie.workbench.common.widgets.decoratedgrid.client.widget.data.GroupedDynamicDataRow)9 Test (org.junit.Test)6 Coordinate (org.kie.workbench.common.widgets.decoratedgrid.client.widget.data.Coordinate)6 DynamicDataRow (org.kie.workbench.common.widgets.decoratedgrid.client.widget.data.DynamicDataRow)2