@Override public GridCell<?> getCell(final int rowIndex, final int columnIndex) { if (rowIndex < 0 || rowIndex > rows.size() - 1) { return null; } final int _columnIndex = columns.get(columnIndex).getIndex(); return rows.get(rowIndex).getCells().get(_columnIndex); }
@Override public GridCell<?> getCell(final int rowIndex, final int columnIndex) { if (rowIndex < 0 || rowIndex > rows.size() - 1) { return null; } final int _columnIndex = columns.get(columnIndex).getIndex(); return rows.get(rowIndex).getCells().get(_columnIndex); }
@Override public void expandCell(final int rowIndex, final int columnIndex) { //Data needs to be merged to expand cells if (!isMerged) { return; } final int _columnIndex = columns.get(columnIndex).getIndex(); final GridRow row = rows.get(rowIndex); final GridCell<?> cell = row.getCells().get(_columnIndex); if (cell == null) { return; } indexManager.onExpandCell(rowIndex, _columnIndex); }
@Override public void expandCell(final int rowIndex, final int columnIndex) { //Data needs to be merged to expand cells if (!isMerged) { return; } final int _columnIndex = columns.get(columnIndex).getIndex(); final GridRow row = rows.get(rowIndex); final GridCell<?> cell = row.getCells().get(_columnIndex); if (cell == null) { return; } indexManager.onExpandCell(rowIndex, _columnIndex); }
private Set<GridWidget> collectGridWidgets(final GridWidget gridWidget) { final Set<GridWidget> allGridWidgets = new HashSet<>(); allGridWidgets.add(gridWidget); gridWidget.getModel() .getRows() .stream() .forEach(row -> row.getCells().values() .stream() .filter(cell -> cell != null && cell.getValue() != null) .map(GridCell::getValue) .filter(value -> value instanceof ExpressionCellValue) .map(value -> (ExpressionCellValue) value) .filter(value -> value.getValue().isPresent()) .map(value -> value.getValue().get()) .forEach(editor -> allGridWidgets.addAll(collectGridWidgets(editor)))); return allGridWidgets; }
private void updateRowMergedCells(final GridRow row) { for (GridCell<?> cell : row.getCells().values()) { if (cell.isMerged()) { ((BaseGridRow) row).setHasMergedCells(true); return; } } ((BaseGridRow) row).setHasMergedCells(false); } }
private void updateRowMergedCells(final GridRow row) { for (GridCell<?> cell : row.getCells().values()) { if (cell.isMerged()) { ((BaseGridRow) row).setHasMergedCells(true); return; } } ((BaseGridRow) row).setHasMergedCells(false); } }
@Override public void collapseCell(final int rowIndex, final int columnIndex) { //Data needs to be merged to collapse cells if (!isMerged) { return; } final int _columnIndex = columns.get(columnIndex).getIndex(); final GridRow row = rows.get(rowIndex); final GridCell<?> cell = row.getCells().get(_columnIndex); if (cell == null) { return; } if (!cell.isMerged()) { return; } indexManager.onCollapseCell(rowIndex, _columnIndex); }
@Override public void collapseCell(final int rowIndex, final int columnIndex) { //Data needs to be merged to collapse cells if (!isMerged) { return; } final int _columnIndex = columns.get(columnIndex).getIndex(); final GridRow row = rows.get(rowIndex); final GridCell<?> cell = row.getCells().get(_columnIndex); if (cell == null) { return; } if (!cell.isMerged()) { return; } indexManager.onCollapseCell(rowIndex, _columnIndex); }
private void updateMergeMetaData(final int minBlockRowIndex, final int maxBlockRowIndex, final int columnIndex) { for (int i = minBlockRowIndex; i < maxBlockRowIndex; i++) { final GridRow row = gridData.getRow(i); final BaseGridCell cell = ((BaseGridCell) row.getCells().get(columnIndex)); if (cell != null) { cell.setMergedCellCount(0); } updateRowMergedCells(row); } final GridRow row = gridData.getRow(minBlockRowIndex); final BaseGridCell cell = ((BaseGridCell) row.getCells().get(columnIndex)); if (cell != null) { cell.setMergedCellCount(maxBlockRowIndex - minBlockRowIndex); } updateRowMergedCells(row); }
private void updateMergeMetaData(final int minBlockRowIndex, final int maxBlockRowIndex, final int columnIndex) { for (int i = minBlockRowIndex; i < maxBlockRowIndex; i++) { final GridRow row = gridData.getRow(i); final BaseGridCell cell = ((BaseGridCell) row.getCells().get(columnIndex)); if (cell != null) { cell.setMergedCellCount(0); } updateRowMergedCells(row); } final GridRow row = gridData.getRow(minBlockRowIndex); final BaseGridCell cell = ((BaseGridCell) row.getCells().get(columnIndex)); if (cell != null) { cell.setMergedCellCount(maxBlockRowIndex - minBlockRowIndex); } updateRowMergedCells(row); }
double getExistingEditorWidth() { double existingWidth = DMNGridColumn.DEFAULT_WIDTH; final GridCell<?> cell = model.getRow(0).getCells().get(0); if (cell != null) { final GridCellValue<?> value = cell.getValue(); if (value instanceof ExpressionCellValue) { final ExpressionCellValue ecv = (ExpressionCellValue) value; final Optional<BaseExpressionGrid> editor = ecv.getValue(); if (editor.isPresent()) { final BaseExpressionGrid beg = editor.get(); existingWidth = Collections.max(Arrays.asList(existingWidth, beg.getWidth() + beg.getPadding() * 2, beg.getMinimumWidth() + beg.getPadding() * 2)); } } } return existingWidth; }
@Test public void testIsCollapsedRowMixedValueOneDifferentValue_1() throws Exception { final GridColumn<String> gridColumn = mock(GridColumn.class); final GridCell<String> cellOne = gridCellWithMockedMergedCellCount("one", 3); final GridCell<String> cellTwo = gridCellWithMockedMergedCellCount("one", 0); final GridCell<String> cellThree = gridCellWithMockedMergedCellCount("two", 0); final GridRow gridRowOne = mock(GridRow.class); final GridRow gridRowTwo = mock(GridRow.class); final GridRow gridRowThree = mock(GridRow.class); doReturn(gridRowOne).when(gridData).getRow(0); doReturn(gridRowTwo).when(gridData).getRow(1); doReturn(gridRowThree).when(gridData).getRow(2); doReturn(false).when(gridRowOne).isCollapsed(); doReturn(true).when(gridRowTwo).isCollapsed(); doReturn(true).when(gridRowThree).isCollapsed(); doReturn(Collections.singletonMap(0, cellOne)).when(gridRowOne).getCells(); doReturn(Collections.singletonMap(0, cellTwo)).when(gridRowTwo).getCells(); doReturn(Collections.singletonMap(0, cellThree)).when(gridRowThree).getCells(); Assertions.assertThat(ColumnRenderingStrategyMerged.isCollapsedRowMultiValue(gridData, gridColumn, cellThree, 2)).isTrue(); }
@Test public void testIsCollapsedRowMixedValueOneDifferentValue_3() throws Exception { final GridColumn<String> gridColumn = mock(GridColumn.class); final GridCell<String> cellOne = gridCellWithMockedMergedCellCount("one", 3); final GridCell<String> cellTwo = gridCellWithMockedMergedCellCount("one", 0); final GridCell<String> cellThree = gridCellWithMockedMergedCellCount("two", 0); final GridRow gridRowOne = mock(GridRow.class); final GridRow gridRowTwo = mock(GridRow.class); final GridRow gridRowThree = mock(GridRow.class); doReturn(gridRowOne).when(gridData).getRow(0); doReturn(gridRowTwo).when(gridData).getRow(1); doReturn(gridRowThree).when(gridData).getRow(2); doReturn(false).when(gridRowOne).isCollapsed(); doReturn(true).when(gridRowTwo).isCollapsed(); doReturn(true).when(gridRowThree).isCollapsed(); doReturn(Collections.singletonMap(0, cellOne)).when(gridRowOne).getCells(); doReturn(Collections.singletonMap(0, cellTwo)).when(gridRowTwo).getCells(); doReturn(Collections.singletonMap(0, cellThree)).when(gridRowThree).getCells(); Assertions.assertThat(ColumnRenderingStrategyMerged.isCollapsedRowMultiValue(gridData, gridColumn, cellThree, 2)).isTrue(); }
@Test public void testInsertRowNumbers() throws VetoException { modelSynchronizer.appendRow(); modelSynchronizer.insertRow(0); assertEquals(1, uiModel.getRow(0).getCells().get(0).getValue().getValue()); assertEquals(2, uiModel.getRow(1).getCells().get(0).getValue().getValue()); assertEquals(1, model.getData().get(0).get(0).getNumericValue()); assertEquals(2, model.getData().get(1).get(0).getNumericValue()); }
@Test public void testAppendRowNumbers() throws VetoException { modelSynchronizer.appendRow(); modelSynchronizer.appendRow(); assertEquals(1, uiModel.getRow(0).getCells().get(0).getValue().getValue()); assertEquals(2, uiModel.getRow(1).getCells().get(0).getValue().getValue()); assertEquals(1, model.getData().get(0).get(0).getNumericValue()); assertEquals(2, model.getData().get(1).get(0).getNumericValue()); }
@Test public void testDeleteRowNumbers() throws VetoException { modelSynchronizer.appendRow(); modelSynchronizer.appendRow(); modelSynchronizer.deleteRow(0); assertEquals(1, uiModel.getRow(0).getCells().get(0).getValue().getValue()); assertEquals(1, model.getData().get(0).get(0).getNumericValue()); }
@Test public void checkBooleanDefaultValueNotSet() throws VetoException { final AttributeCol52 column = new AttributeCol52(); column.setAttribute(RuleAttributeWidget.ENABLED_ATTR); modelSynchronizer.appendColumn(column); modelSynchronizer.appendRow(); assertFalse((Boolean) uiModel.getRow(0).getCells().get(2).getValue().getValue()); assertFalse(model.getData().get(0).get(2).getBooleanValue()); } }
@Test public void checkBooleanDefaultValueTrue() throws VetoException { final AttributeCol52 column = new AttributeCol52(); column.setAttribute(RuleAttributeWidget.ENABLED_ATTR); column.setDefaultValue(new DTCellValue52(true)); modelSynchronizer.appendColumn(column); modelSynchronizer.appendRow(); assertTrue((Boolean) uiModel.getRow(0).getCells().get(2).getValue().getValue()); assertTrue(model.getData().get(0).get(2).getBooleanValue()); }
@Test public void checkBooleanDefaultValueFalse() throws VetoException { final AttributeCol52 column = new AttributeCol52(); column.setAttribute(RuleAttributeWidget.ENABLED_ATTR); column.setDefaultValue(new DTCellValue52(false)); modelSynchronizer.appendColumn(column); modelSynchronizer.appendRow(); assertFalse((Boolean) uiModel.getRow(0).getCells().get(2).getValue().getValue()); assertFalse(model.getData().get(0).get(2).getBooleanValue()); }