public static String getPropertyName(final Simulation simulation, final int columnIndex) { return String.join(".", simulation.getSimulationDescriptor().getFactMappingByIndex(columnIndex).getExpressionElementsWithoutClass() .stream() .map(ExpressionElement::getStep) .collect(Collectors.toSet())); }
public Optional<FactMappingValue> getFactMappingValueByIndex(int index) { FactMapping factMappingByIndex; try { factMappingByIndex = simulationDescriptor.getFactMappingByIndex(index); } catch (IndexOutOfBoundsException e) { throw new IllegalArgumentException( new StringBuilder().append("Impossible to retrieve FactMapping at index ").append(index).toString(), e); } return getFactMappingValue(factMappingByIndex.getFactIdentifier(), factMappingByIndex.getExpressionIdentifier()); }
public Optional<FactMappingValue> getFactMappingValueByIndex(int index) { FactMapping factMappingByIndex; try { factMappingByIndex = simulationDescriptor.getFactMappingByIndex(index); } catch (IndexOutOfBoundsException e) { throw new IllegalArgumentException( new StringBuilder().append("Impossible to retrieve FactMapping at index ").append(index).toString(), e); } return getFactMappingValue(factMappingByIndex.getFactIdentifier(), factMappingByIndex.getExpressionIdentifier()); }
/** * Returns <code>true</code> if property mapped to the column at given index is the same as the provided one * @param columnIndex * @param propertyName * @return */ public boolean isSameSelectedColumnProperty(int columnIndex, String propertyName) { SimulationDescriptor simulationDescriptor = simulation.getSimulationDescriptor(); final FactMapping factMappingByIndex = simulationDescriptor.getFactMappingByIndex(columnIndex); return factMappingByIndex.getExpressionAlias().equals(propertyName); }
/** * Returns <code>true</code> if type mapped to the column at given index is the same as the provided one * @param columnIndex * @param className * @return */ public boolean isSameSelectedColumnType(int columnIndex, String className) { SimulationDescriptor simulationDescriptor = simulation.getSimulationDescriptor(); final FactMapping factMappingByIndex = simulationDescriptor.getFactMappingByIndex(columnIndex); return factMappingByIndex.getClassName().equals(className); }
protected boolean isUnique(String value, int rowIndex, int columnIndex) { Range instanceLimits = getInstanceLimits(columnIndex); SimulationDescriptor simulationDescriptor = simulation.getSimulationDescriptor(); FactIdentifier factIdentifier = simulationDescriptor.getFactMappingByIndex(columnIndex).getFactIdentifier(); return IntStream.range(0, getColumnCount()) .filter(index -> index < instanceLimits.getMinRowIndex() || index > instanceLimits.getMaxRowIndex()) .filter(index -> !Objects.equals(factIdentifier, simulationDescriptor.getFactMappingByIndex(index).getFactIdentifier())) .mapToObj(index -> getColumns().get(index)) .filter(elem -> elem.getHeaderMetaData().size() > rowIndex) .map(elem -> (ScenarioHeaderMetaData) elem.getHeaderMetaData().get(rowIndex)) .noneMatch(elem -> Objects.equals(elem.getTitle(), value)); }
public void removeFactMappingByIndex(int index) { cleanScenarios(simulationDescriptor.getFactMappingByIndex(index)); simulationDescriptor.removeFactMappingByIndex(index); }
public void removeFactMappingByIndex(int index) { cleanScenarios(simulationDescriptor.getFactMappingByIndex(index)); simulationDescriptor.removeFactMappingByIndex(index); }
/** * If the <code>FactIdentifier</code> of the given <code>FactMapping</code> equals the one at <b>index</b>, update the <code>FactMapping.FactAlias</code> at <b>index</b> * position with the provided <b>value</b> * @param simulationDescriptor * @param factMappingReference * @param index * @param value */ protected void updateFactMapping(SimulationDescriptor simulationDescriptor, FactMapping factMappingReference, int index, String value) { final FactIdentifier factIdentifierReference = factMappingReference.getFactIdentifier(); FactMapping factMappingToCheck = simulationDescriptor.getFactMappingByIndex(index); final FactIdentifier factIdentifierToCheck = factMappingToCheck.getFactIdentifier(); if (Objects.equals(FactIdentifier.EMPTY, factIdentifierReference)) { if (Objects.equals(factIdentifierToCheck, factIdentifierReference) && Objects.equals(factMappingReference.getFactAlias(), factMappingToCheck.getFactAlias())) { ((ScenarioGridColumn) columns.get(index)).getInformationHeaderMetaData().setTitle(value); factMappingToCheck.setFactAlias(value); } } else if (Objects.equals(factIdentifierToCheck, factIdentifierReference)) { ((ScenarioGridColumn) columns.get(index)).getInformationHeaderMetaData().setTitle(value); factMappingToCheck.setFactAlias(value); } }
public void updateHeader(int columnIndex, int headerRowIndex, String value) { final ScenarioHeaderMetaData editedMetadata = (ScenarioHeaderMetaData) getColumns().get(columnIndex).getHeaderMetaData().get(headerRowIndex); // do not update if old and new value are the same if (Objects.equals(editedMetadata.getTitle(), value)) { return; } SimulationDescriptor simulationDescriptor = simulation.getSimulationDescriptor(); FactMapping factMappingToEdit = simulationDescriptor.getFactMappingByIndex(columnIndex); if (editedMetadata.isInstanceHeader()) { // we have to update title and value for every column of the group IntStream.range(0, getColumnCount()).forEach(index -> { updateFactMapping(simulationDescriptor, factMappingToEdit, index, value); }); eventBus.fireEvent(new ReloadRightPanelEvent(false)); } else { editedMetadata.setTitle(value); factMappingToEdit.setExpressionAlias(value); } }
protected void refreshErrorsRow(int rowIndex) { SimulationDescriptor simulationDescriptor = simulation.getSimulationDescriptor(); Scenario scenarioByIndex = simulation.getScenarioByIndex(rowIndex); IntStream.range(0, getColumnCount()).forEach(columnIndex -> { ScenarioGridCell cell = (ScenarioGridCell) getCell(rowIndex, columnIndex); if (cell == null) { return; } final FactMapping factMappingByIndex = simulationDescriptor.getFactMappingByIndex(columnIndex); Optional<FactMappingValue> factMappingValue = scenarioByIndex.getFactMappingValue(factMappingByIndex.getFactIdentifier(), factMappingByIndex.getExpressionIdentifier()); if (factMappingValue.isPresent()) { cell.setErrorMode(factMappingValue.get().isError()); } else { cell.setErrorMode(false); } }); }
@Test(expected = IndexOutOfBoundsException.class) public void removeFactMappingByIndex() { int testingIndex = 0; simulationDescriptor.addFactMapping(factIdentifier, expressionIdentifier); assertNotNull(simulationDescriptor.getFactMappingByIndex(testingIndex)); simulationDescriptor.removeFactMappingByIndex(testingIndex); simulationDescriptor.getFactMappingByIndex(testingIndex); }
@Test(expected = IndexOutOfBoundsException.class) public void removeFactMappingByIndex() { int testingIndex = 0; simulationDescriptor.addFactMapping(factIdentifier, expressionIdentifier); assertNotNull(simulationDescriptor.getFactMappingByIndex(testingIndex)); simulationDescriptor.removeFactMappingByIndex(testingIndex); simulationDescriptor.getFactMappingByIndex(testingIndex); }
/** * This method update the type mapped inside a give column and updates the underlying model * @param columnIndex * @param column * @param value * @param lastLevelClassName * @param keepData */ public void updateColumnProperty(int columnIndex, final GridColumn<?> column, String value, String lastLevelClassName, boolean keepData) { checkSimulation(); List<GridCellValue<?>> originalValues = new ArrayList<>(); if (keepData) { IntStream.range(0, getRowCount()) .forEach(rowIndex -> originalValues.add(getCell(rowIndex, columnIndex).getValue())); } deleteColumn(columnIndex); String group = ((ScenarioGridColumn) column).getInformationHeaderMetaData().getColumnGroup(); String columnId = ((ScenarioGridColumn) column).getInformationHeaderMetaData().getColumnId(); String[] elements = value.split("\\."); ExpressionIdentifier ei = ExpressionIdentifier.create(columnId, FactMappingType.valueOf(group)); commonAddColumn(columnIndex, column, ei); final FactMapping factMappingByIndex = simulation.getSimulationDescriptor().getFactMappingByIndex(columnIndex); IntStream.range(0, elements.length) .forEach(stepIndex -> factMappingByIndex.addExpressionElement(elements[stepIndex], lastLevelClassName)); if (keepData) { IntStream.range(0, getRowCount()) .forEach(rowIndex -> setCellValue(rowIndex, columnIndex, originalValues.get(rowIndex))); } }
protected void commonAddRow(int rowIndex) { Scenario scenario = simulation.addScenario(rowIndex); final SimulationDescriptor simulationDescriptor = simulation.getSimulationDescriptor(); IntStream.range(1, getColumnCount()).forEach(columnIndex -> { final FactMapping factMappingByIndex = simulationDescriptor.getFactMappingByIndex(columnIndex); scenario.addMappingValue(factMappingByIndex.getFactIdentifier(), factMappingByIndex.getExpressionIdentifier(), null); String placeHolder = ((ScenarioGridColumn) columns.get(columnIndex)).isPropertyAssigned() ? ScenarioSimulationEditorConstants.INSTANCE.insertValue() : ScenarioSimulationEditorConstants.INSTANCE.defineValidType(); setCell(rowIndex, columnIndex, () -> new ScenarioGridCell(new ScenarioGridCellValue(null, placeHolder))); }); updateIndexColumn(); }
@Override public Range deleteCell(int rowIndex, int columnIndex) { FactMapping factMapping = simulation.getSimulationDescriptor().getFactMappingByIndex(columnIndex); simulation.getScenarioByIndex(rowIndex) .removeFactMappingValueByIdentifiers(factMapping.getFactIdentifier(), factMapping.getExpressionIdentifier()); return super.deleteCell(rowIndex, columnIndex); }
IntStream.range(instanceLimits.getMinRowIndex(), instanceLimits.getMaxRowIndex() + 1) .filter(currentIndex -> currentIndex != columnIndex) .forEach(currentIndex -> simulationDescriptor.getFactMappingByIndex(currentIndex).setFactAlias(createdFactMapping.getFactAlias())); selectColumn(columns.indexOf(column)); } catch (Throwable t) {
@Test public void removeFactMapping() { assertEquals(2, simulation.getUnmodifiableScenarios().get(0).getUnmodifiableFactMappingValues().size()); assertEquals(1, simulation.getSimulationDescriptor().getUnmodifiableFactMappings().size()); simulation.removeFactMapping(simulation.getSimulationDescriptor().getFactMappingByIndex(0)); assertEquals(1, simulation.getUnmodifiableScenarios().get(0).getUnmodifiableFactMappingValues().size()); assertEquals(0, simulation.getSimulationDescriptor().getUnmodifiableFactMappings().size()); }
@Test public void removeFactMapping() { assertEquals(2, simulation.getUnmodifiableScenarios().get(0).getUnmodifiableFactMappingValues().size()); assertEquals(1, simulation.getSimulationDescriptor().getUnmodifiableFactMappings().size()); simulation.removeFactMapping(simulation.getSimulationDescriptor().getFactMappingByIndex(0)); assertEquals(1, simulation.getUnmodifiableScenarios().get(0).getUnmodifiableFactMappingValues().size()); assertEquals(0, simulation.getSimulationDescriptor().getUnmodifiableFactMappings().size()); }
/** * 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; }