Search in sources :

Example 1 with CellValue

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

the class ModelSynchronizerImpl method fireUpdateColumnDataEvent.

protected void fireUpdateColumnDataEvent() {
    final List<CellValue<? extends Comparable<?>>> columnData = new ArrayList<CellValue<? extends Comparable<?>>>();
    for (int rowIndex = 0; rowIndex < model.getData().size(); rowIndex++) {
        columnData.add(null);
    }
    final UpdateColumnDataEvent event = new UpdateColumnDataEvent(0, columnData);
    eventBus.fireEvent(event);
}
Also used : ArrayList(java.util.ArrayList) CellValue(org.kie.workbench.common.widgets.decoratedgrid.client.widget.CellValue) GridCellValue(org.uberfire.ext.wires.core.grids.client.model.GridCellValue) UpdateColumnDataEvent(org.kie.workbench.common.widgets.decoratedgrid.client.widget.events.UpdateColumnDataEvent)

Example 2 with CellValue

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

the class AnalyzerControllerImplTest method updateColumns.

@Test
public void updateColumns() throws Exception {
    final ArrayList<CellValue<? extends Comparable<?>>> columnData = new ArrayList<>();
    columnData.add(mock(CellValue.class));
    controller.onUpdateColumnData(new UpdateColumnDataEvent(10, columnData));
    verify(analyzer).updateColumns(1);
}
Also used : ArrayList(java.util.ArrayList) CellValue(org.kie.workbench.common.widgets.decoratedgrid.client.widget.CellValue) UpdateColumnDataEvent(org.kie.workbench.common.widgets.decoratedgrid.client.widget.events.UpdateColumnDataEvent) Test(org.junit.Test)

Example 3 with CellValue

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

the class DynamicData method assertModelMerging.

/**
 * Ensure merging and indexing is reflected in the entire model. This should
 * be called whenever any changes are made to the underlying data externally
 * to the add/remove methods provided publicly herein, such as bulk move
 * operations.
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
public void assertModelMerging() {
    if (data.size() == 0) {
        return;
    }
    // Remove merging first as it initialises all coordinates
    removeModelMerging();
    final int COLUMNS = data.get(0).size();
    // Only apply merging if merged
    if (isMerged) {
        int minRowIndex = 0;
        int maxRowIndex = data.size();
        // Add an empty row to the end of the data to simplify detection of merged cells that run to the end of the table
        DynamicDataRow blankRow = new DynamicDataRow();
        for (int iCol = 0; iCol < COLUMNS; iCol++) {
            CellValue cv = new CellValue(null);
            Coordinate c = new Coordinate(data.size(), iCol);
            cv.setCoordinate(c);
            cv.setHtmlCoordinate(c);
            cv.setPhysicalCoordinate(c);
            blankRow.add(cv);
        }
        data.add(blankRow);
        maxRowIndex++;
        // Look in columns for cells with identical values
        for (int iCol = 0; iCol < COLUMNS; iCol++) {
            CellValue<?> cell1 = data.get(minRowIndex).get(iCol);
            CellValue<?> cell2 = null;
            for (int iRow = minRowIndex + 1; iRow < maxRowIndex; iRow++) {
                cell1.setRowSpan(1);
                cell2 = data.get(iRow).get(iCol);
                // Merge if both cells contain the same value and neither is grouped
                boolean bSplit = true;
                if (!cell1.isEmpty() && !cell2.isEmpty()) {
                    if (cell1.getValue().equals(cell2.getValue())) {
                        bSplit = false;
                        if (cell1 instanceof CellValue.GroupedCellValue) {
                            bSplit = true;
                        }
                        if (cell2 instanceof CellValue.GroupedCellValue) {
                            bSplit = true;
                        }
                    }
                } else if (cell1.isOtherwise() && cell2.isOtherwise()) {
                    bSplit = false;
                    if (cell1 instanceof CellValue.GroupedCellValue) {
                        CellValue.GroupedCellValue gcv = (CellValue.GroupedCellValue) cell1;
                        if (gcv.hasMultipleValues()) {
                            bSplit = true;
                        }
                    }
                    if (cell2 instanceof CellValue.GroupedCellValue) {
                        CellValue.GroupedCellValue gcv = (CellValue.GroupedCellValue) cell2;
                        if (gcv.hasMultipleValues()) {
                            bSplit = true;
                        }
                    }
                }
                if (bSplit) {
                    mergeCells(cell1, cell2);
                    cell1 = cell2;
                }
            }
        }
        // Remove dummy blank row
        data.remove(blankRow);
    }
    // Set indexes after merging has been corrected
    assertModelIndexes();
}
Also used : CellValue(org.kie.workbench.common.widgets.decoratedgrid.client.widget.CellValue)

Example 4 with CellValue

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

the class DynamicDataTestsWithGrouping method testDataGrouping.

@Test
@SuppressWarnings("rawtypes")
public void testDataGrouping() {
    // [1][-][3] --> [1][x][3]
    // [1][2][3] --> [-][2][3]
    // [-][2][3] -->
    CellValue.GroupedCellValue gcv;
    CellValue<? extends Comparable<?>> cv = data.get(0).get(0);
    data.setMerged(true);
    data.applyModelGrouping(cv);
    assertEquals(data.size(), 2);
    cv = data.get(0).get(0);
    assertTrue(cv instanceof GroupedCellValue);
    gcv = (GroupedCellValue) cv;
    assertFalse(gcv.hasMultipleValues());
    assertEquals(cv.getValue(), "1");
    cv = data.get(0).get(1);
    assertTrue(cv instanceof GroupedCellValue);
    gcv = (GroupedCellValue) cv;
    assertTrue(gcv.hasMultipleValues());
    cv = data.get(0).get(2);
    assertTrue(cv instanceof GroupedCellValue);
    gcv = (GroupedCellValue) cv;
    assertFalse(gcv.hasMultipleValues());
    assertEquals(cv.getValue(), "3");
    cv = data.get(1).get(0);
    assertFalse(cv instanceof GroupedCellValue);
    assertEquals(cv.getValue(), "-");
    cv = data.get(1).get(1);
    assertFalse(cv instanceof GroupedCellValue);
    assertEquals(cv.getValue(), "2");
    cv = data.get(1).get(2);
    assertFalse(cv instanceof GroupedCellValue);
    assertEquals(cv.getValue(), "3");
}
Also used : GroupedCellValue(org.kie.workbench.common.widgets.decoratedgrid.client.widget.CellValue.GroupedCellValue) CellValue(org.kie.workbench.common.widgets.decoratedgrid.client.widget.CellValue) GroupedCellValue(org.kie.workbench.common.widgets.decoratedgrid.client.widget.CellValue.GroupedCellValue) GroupedCellValue(org.kie.workbench.common.widgets.decoratedgrid.client.widget.CellValue.GroupedCellValue) Test(org.junit.Test)

Example 5 with CellValue

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

the class TemplateDataTableWidget method onUpdateModel.

public void onUpdateModel(UpdateModelEvent event) {
    // Copy data into the underlying model
    Map<Coordinate, List<List<CellValue<? extends Comparable<?>>>>> updates = event.getUpdates();
    for (Map.Entry<Coordinate, List<List<CellValue<? extends Comparable<?>>>>> e : updates.entrySet()) {
        // Coordinate of change
        Coordinate originCoordinate = e.getKey();
        int originRowIndex = originCoordinate.getRow();
        int originColumnIndex = originCoordinate.getCol();
        // Changed data
        List<List<CellValue<? extends Comparable<?>>>> data = e.getValue();
        InterpolationVariable[] vars = model.getInterpolationVariablesList();
        for (int iRow = 0; iRow < data.size(); iRow++) {
            List<CellValue<? extends Comparable<?>>> rowData = data.get(iRow);
            int targetRowIndex = originRowIndex + iRow;
            for (int iCol = 0; iCol < rowData.size(); iCol++) {
                int targetColumnIndex = originColumnIndex + iCol;
                CellValue<? extends Comparable<?>> changedCell = rowData.get(iCol);
                InterpolationVariable var = vars[targetColumnIndex];
                TemplateDataColumn col = new TemplateDataColumn(var.getVarName(), var.getDataType(), var.getFactType(), var.getFactField());
                String dcv = cellValueFactory.convertToModelCell(col, changedCell);
                List<String> columnData = model.getTable().get(var.getVarName());
                columnData.set(targetRowIndex, dcv);
            }
        }
    }
}
Also used : InterpolationVariable(org.drools.workbench.models.datamodel.rule.InterpolationVariable) Coordinate(org.kie.workbench.common.widgets.decoratedgrid.client.widget.data.Coordinate) ArrayList(java.util.ArrayList) List(java.util.List) CellValue(org.kie.workbench.common.widgets.decoratedgrid.client.widget.CellValue) Map(java.util.Map)

Aggregations

CellValue (org.kie.workbench.common.widgets.decoratedgrid.client.widget.CellValue)5 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)2 UpdateColumnDataEvent (org.kie.workbench.common.widgets.decoratedgrid.client.widget.events.UpdateColumnDataEvent)2 List (java.util.List)1 Map (java.util.Map)1 InterpolationVariable (org.drools.workbench.models.datamodel.rule.InterpolationVariable)1 GroupedCellValue (org.kie.workbench.common.widgets.decoratedgrid.client.widget.CellValue.GroupedCellValue)1 Coordinate (org.kie.workbench.common.widgets.decoratedgrid.client.widget.data.Coordinate)1 GridCellValue (org.uberfire.ext.wires.core.grids.client.model.GridCellValue)1