/** * This method <i>set</i> a cell value to the grid <b>without</b> modify underlying model * @param rowIndex * @param columnIndex * @param cellSupplier */ public Range setCellGridOnly(int rowIndex, int columnIndex, Supplier<GridCell<?>> cellSupplier) { checkSimulation(); return super.setCell(rowIndex, columnIndex, cellSupplier); }
@Test public void testSetCellValueWhenExistingBaseGridCell() { final BaseGridColumn<String> column = new BaseGridColumn<>(header, columnRenderer, 25.0); baseGridData.insertColumn(0, column); baseGridData.appendRow(new BaseGridRow()); baseGridData.setCell(0, 0, () -> new BaseGridCell<>(new BaseGridCellValue<>(""))); baseGridData.setCellValue(0, 0, new BaseGridCellValue<>("hello")); assertThat(baseGridData.getCell(0, 0).getValue().getValue()).isEqualTo("hello"); assertThat(baseGridData.getCell(0, 0)).isInstanceOf(BaseGridCell.class); }
@Test public void testSetCellValueWhenExistingCustomGridCell() { final BaseGridColumn<String> column = new BaseGridColumn<>(header, columnRenderer, 25.0); baseGridData.insertColumn(0, column); baseGridData.appendRow(new BaseGridRow()); baseGridData.setCell(0, 0, () -> new CustomGridCell<>(new BaseGridCellValue<>("hello"))); baseGridData.setCellValue(0, 0, new BaseGridCellValue<>("hello")); assertThat(baseGridData.getCell(0, 0).getValue().getValue()).isEqualTo("hello"); assertThat(baseGridData.getCell(0, 0)).isInstanceOf(CustomGridCell.class); }
@Override //Override to sync underlying Model with UiModel public Range setCell(final int rowIndex, final int columnIndex, final Supplier<GridCell<?>> cellSupplier) { final Range range = super.setCell(rowIndex, columnIndex, cellSupplier); synchronizer.setCellValue(range, columnIndex, cellSupplier.get().getValue()); return range; }
@Test public void testSetCellValueWhenExistingBaseGridCell() { final BaseGridColumn<String> column = new BaseGridColumn<>(header, columnRenderer, 25.0); baseGridData.insertColumn(0, column); baseGridData.appendRow(new BaseGridRow()); baseGridData.setCell(0, 0, () -> new BaseGridCell<>(new BaseGridCellValue<>(""))); baseGridData.setCellValue(0, 0, new BaseGridCellValue<>("hello")); assertThat(baseGridData.getCell(0, 0).getValue().getValue()).isEqualTo("hello"); assertThat(baseGridData.getCell(0, 0)).isInstanceOf(BaseGridCell.class); }
@Override //Override to sync underlying Model with UiModel public Range setCell(final int rowIndex, final int columnIndex, final Supplier<GridCell<?>> cellSupplier) { final Range range = super.setCell(rowIndex, columnIndex, cellSupplier); synchronizer.setCellValue(range, columnIndex, cellSupplier.get().getValue()); return range; }
@Test public void testSetCellValueWhenExistingCustomGridCell() { final BaseGridColumn<String> column = new BaseGridColumn<>(header, columnRenderer, 25.0); baseGridData.insertColumn(0, column); baseGridData.appendRow(new BaseGridRow()); baseGridData.setCell(0, 0, () -> new CustomGridCell<>(new BaseGridCellValue<>("hello"))); baseGridData.setCellValue(0, 0, new BaseGridCellValue<>("hello")); assertThat(baseGridData.getCell(0, 0).getValue().getValue()).isEqualTo("hello"); assertThat(baseGridData.getCell(0, 0)).isInstanceOf(CustomGridCell.class); }
/** * This method <i>set</i> a cell value to the grid <b>and</b> to the underlying model * @param rowIndex * @param columnIndex * @param cellSupplier */ @Override public Range setCell(int rowIndex, int columnIndex, Supplier<GridCell<?>> cellSupplier) { checkSimulation(); Range toReturn = super.setCell(rowIndex, columnIndex, cellSupplier); try { Optional<?> optionalValue = getCellValue(getCell(rowIndex, columnIndex)); Object rawValue = optionalValue.orElse(null); String cellValue = (rawValue instanceof String) ? (String) rawValue : null; Scenario scenarioByIndex = simulation.getScenarioByIndex(rowIndex); FactMapping factMappingByIndex = simulation.getSimulationDescriptor().getFactMappingByIndex(columnIndex); FactIdentifier factIdentifier = factMappingByIndex.getFactIdentifier(); ExpressionIdentifier expressionIdentifier = factMappingByIndex.getExpressionIdentifier(); scenarioByIndex.addOrUpdateMappingValue(factIdentifier, expressionIdentifier, cellValue); } catch (Throwable t) { toReturn = super.deleteCell(rowIndex, columnIndex); eventBus.fireEvent(new ScenarioGridReloadEvent()); } return toReturn; }