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()); }
private void cleanScenarios(FactMapping toRemove) { scenarios.forEach(e -> e.removeFactMappingValueByIdentifiers(toRemove.getFactIdentifier(), toRemove.getExpressionIdentifier())); } }
public int getIndexByIdentifier(FactIdentifier factIdentifier, ExpressionIdentifier expressionIdentifier) { return IntStream.range(0, factMappings.size()).filter(index -> { FactMapping factMapping = factMappings.get(index); return factMapping.getExpressionIdentifier().equals(expressionIdentifier) && factMapping.getFactIdentifier().equals(factIdentifier); }).findFirst().orElseThrow(() -> new IllegalArgumentException( new StringBuilder().append("Impossible to find a FactMapping with factIdentifier '").append(factIdentifier.getName()) .append("' and expressionIdentifier '").append(expressionIdentifier.getName()).append("'").toString())); }
private void cleanScenarios(FactMapping toRemove) { scenarios.forEach(e -> e.removeFactMappingValueByIdentifiers(toRemove.getFactIdentifier(), toRemove.getExpressionIdentifier())); } }
public int getIndexByIdentifier(FactIdentifier factIdentifier, ExpressionIdentifier expressionIdentifier) { return IntStream.range(0, factMappings.size()).filter(index -> { FactMapping factMapping = factMappings.get(index); return factMapping.getExpressionIdentifier().equals(expressionIdentifier) && factMapping.getFactIdentifier().equals(factIdentifier); }).findFirst().orElseThrow(() -> new IllegalArgumentException( new StringBuilder().append("Impossible to find a FactMapping with factIdentifier '").append(factIdentifier.getName()) .append("' and expressionIdentifier '").append(expressionIdentifier.getName()).append("'").toString())); }
public Optional<FactMapping> getFactMapping(FactIdentifier factIdentifier, ExpressionIdentifier ei) { List<FactMapping> factMappings = internalFilter(e -> e.getExpressionIdentifier().equals(ei) && e.getFactIdentifier().equals(factIdentifier)); return factMappings.stream().findFirst(); }
public Optional<FactMapping> getFactMapping(FactIdentifier factIdentifier, ExpressionIdentifier ei) { List<FactMapping> factMappings = internalFilter(e -> e.getExpressionIdentifier().equals(ei) && e.getFactIdentifier().equals(factIdentifier)); return factMappings.stream().findFirst(); }
@Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } FactMapping that = (FactMapping) o; return getExpressionElements().equals(that.getExpressionElements()) && Objects.equals(getExpressionIdentifier(), that.getExpressionIdentifier()) && Objects.equals(getFactIdentifier(), that.getFactIdentifier()) && Objects.equals(getClassName(), that.getClassName()) && Objects.equals(getFactAlias(), that.getFactAlias()) && Objects.equals(getExpressionAlias(), that.getExpressionAlias()); }
protected SortedMap<String, FactModelTree> getInstanceMap(SortedMap<String, FactModelTree> sourceMap) { SortedMap<String, FactModelTree> toReturn = new TreeMap<>(); // map instance name to base class if (model != null) { final SimulationDescriptor simulationDescriptor = model.getSimulation().getSimulationDescriptor(); simulationDescriptor.getUnmodifiableFactMappings() .stream() .filter(factMapping -> !Objects.equals(FactMappingType.OTHER, factMapping.getExpressionIdentifier().getType())) .forEach(factMapping -> { String dataObjectName = factMapping.getFactIdentifier().getClassName(); if (dataObjectName.contains(".")) { dataObjectName = dataObjectName.substring(dataObjectName.lastIndexOf(".") + 1); } final String instanceName = factMapping.getFactAlias(); if (!instanceName.equals(dataObjectName)) { final FactModelTree factModelTree = sourceMap.get(dataObjectName); if (factModelTree != null) { toReturn.put(instanceName, factModelTree); } } }); } return toReturn; }
@Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } FactMapping that = (FactMapping) o; return getExpressionElements().equals(that.getExpressionElements()) && Objects.equals(getExpressionIdentifier(), that.getExpressionIdentifier()) && Objects.equals(getFactIdentifier(), that.getFactIdentifier()) && Objects.equals(getClassName(), that.getClassName()) && Objects.equals(getFactAlias(), that.getFactAlias()) && Objects.equals(getExpressionAlias(), that.getExpressionAlias()); }
@Override public int hashCode() { return Objects.hash(getExpressionElements(), getExpressionIdentifier(), getFactIdentifier(), getClassName(), getFactAlias(), getExpressionAlias()); } }
@Override public int hashCode() { return Objects.hash(getExpressionElements(), getExpressionIdentifier(), getFactIdentifier(), getClassName(), getFactAlias(), getExpressionAlias()); } }
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); } }); }
@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); }
@Test public void getScenarioGridColumnLocal() { String columnId = factMappingDescription.getExpressionIdentifier().getName(); String instanceTitle = factMappingDescription.getFactIdentifier().getName(); String propertyTitle = "PROPERTY TITLE"; final FactMappingType type = factMappingDescription.getExpressionIdentifier().getType(); String columnGroup = type.name(); scenarioGrid.getScenarioGridColumnLocal(instanceTitle, propertyTitle, columnId, columnGroup, type, ScenarioSimulationEditorConstants.INSTANCE.insertValue()); verify(scenarioGrid, times(1)).getScenarioHeaderTextBoxSingletonDOMElementFactory(); verify(scenarioGrid, times(1)).getHeaderBuilderLocal(eq(instanceTitle), eq(propertyTitle), eq(columnId), eq(columnGroup), eq(type), eq(scenarioHeaderTextBoxSingletonDOMElementFactoryMock)); }
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(); }
@Test public void setHeaderColumn() { String columnId = factMappingDescription.getExpressionIdentifier().getName(); FactMappingType type = factMappingDescription.getExpressionIdentifier().getType(); String columnGroup = type.name(); scenarioGrid.setHeaderColumn(1, factMappingDescription, true); reset(scenarioGridColumnMock); reset(scenarioGridModelMock); columnId = factMappingGiven.getExpressionIdentifier().getName(); type = factMappingGiven.getExpressionIdentifier().getType(); columnGroup = type.name(); scenarioGrid.setHeaderColumn(1, factMappingGiven, true);
protected void setHeaderColumn(int columnIndex, FactMapping factMapping, boolean editableHeaders) { final FactIdentifier factIdentifier = factMapping.getFactIdentifier(); String columnId = factMapping.getExpressionIdentifier().getName(); String instanceTitle = factMapping.getFactAlias(); String propertyTitle = factMapping.getExpressionAlias(); String columnGroup = factMapping.getExpressionIdentifier().getType().name(); boolean isInstanceAssigned = isInstanceAssigned(factIdentifier); boolean isPropertyAssigned = isPropertyAssigned(isInstanceAssigned, factMapping); String placeHolder = getPlaceholder(isPropertyAssigned); ScenarioGridColumn scenarioGridColumn = getScenarioGridColumnLocal(instanceTitle, propertyTitle, columnId, columnGroup, factMapping.getExpressionIdentifier().getType(), placeHolder); scenarioGridColumn.setInstanceAssigned(isInstanceAssigned); scenarioGridColumn.setPropertyAssigned(isPropertyAssigned); scenarioGridColumn.setFactIdentifier(factIdentifier); scenarioGridColumn.setEditableHeaders(editableHeaders); // by default ScenarioGridColumnBuilders.ScenarioGridColumnBuilder.build() set ColumnWidthMode.auto to all generated columns if (FactMappingType.OTHER.equals(factMapping.getExpressionIdentifier().getType())) { scenarioGridColumn.setColumnWidthMode(ColumnWidthMode.FIXED); scenarioGridColumn.setMinimumWidth(scenarioGridColumn.getWidth()); } ((ScenarioGridModel) model).insertColumnGridOnly(columnIndex, scenarioGridColumn); }
/** * 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; }