public static String getPlaceHolder(FactMappingType factMappingType) { return factMappingType.name(); }
private static boolean isOther(FactMappingType factMappingType) { return FactMappingType.OTHER.equals(factMappingType); }
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 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))); } }
public void commonInsertColumnCommand(ScenarioSimulationContext context, ScenarioSimulationContext.Status status, int index) { FactMappingType factMappingType = FactMappingType.valueOf(status.getColumnGroup().toUpperCase()); Map.Entry<String, String> validPlaceholders = context.getModel().getValidPlaceholders(); String instanceTitle = validPlaceholders.getKey(); String propertyTitle = validPlaceholders.getValue(); final ScenarioGridColumn scenarioGridColumnLocal = getScenarioGridColumnLocal(instanceTitle, propertyTitle, status.getColumnId(), status.getColumnGroup(), factMappingType, context.getScenarioGridPanel(), context.getScenarioGridLayer(), ScenarioSimulationEditorConstants.INSTANCE.defineValidType()); context.getModel().insertColumn(index, scenarioGridColumnLocal); } }
public static String getPlaceHolder(FactMappingType factMappingType) { return factMappingType.name(); }
public List<ScenarioExpect> extractExpectedValues(List<FactMappingValue> factMappingValues) { List<ScenarioExpect> scenarioExpect = new ArrayList<>(); Map<FactIdentifier, List<FactMappingValue>> groupByFactIdentifier = groupByFactIdentifierAndFilter(factMappingValues, FactMappingType.EXPECT); Set<FactIdentifier> inputFacts = factMappingValues.stream() .filter(elem -> FactMappingType.GIVEN.equals(elem.getExpressionIdentifier().getType())) .map(FactMappingValue::getFactIdentifier) .collect(Collectors.toSet()); for (Map.Entry<FactIdentifier, List<FactMappingValue>> entry : groupByFactIdentifier.entrySet()) { FactIdentifier factIdentifier = entry.getKey(); scenarioExpect.add(new ScenarioExpect(factIdentifier, entry.getValue(), !inputFacts.contains(factIdentifier))); } return scenarioExpect; }
/** * This method <i>add</i> or <i>insert</i> a new column to the grid <b>and</b> to the underlying model, depending on the index value. * If index == -1 -> add, otherwise insert. It automatically creates default <code>FactIdentifier</code> (for String class) and <code>ExpressionIdentifier</code> * @param index * @param column */ protected void commonAddColumn(final int index, final GridColumn<?> column) { String group = ((ScenarioGridColumn) column).getInformationHeaderMetaData().getColumnGroup(); String columnId = ((ScenarioGridColumn) column).getInformationHeaderMetaData().getColumnId(); final ExpressionIdentifier ei = ExpressionIdentifier.create(columnId, FactMappingType.valueOf(group)); commonAddColumn(index, column, ei); }
@Override public Rectangle getHeaderBackground(final GridColumn<?> column) { String colorToApply; // GIVEN if(FactMappingType.GIVEN.name().equalsIgnoreCase(column.getHeaderMetaData().get(0).getTitle())) { colorToApply = HEADER_BACKGROUND_LIGHT_BLUE; } // EXPECT else if (FactMappingType.EXPECT.name().equalsIgnoreCase(column.getHeaderMetaData().get(0).getTitle())) { colorToApply = HEADER_BACKGROUND_DARK_BLUE; } // DEFAULT else { colorToApply = HEADER_BACKGROUND_WHITE; } return new Rectangle(0, 0) .setFillColor(colorToApply); }
/** * This method update the instance mapped inside a given column * @param columnIndex * @param column */ public void updateColumnInstance(int columnIndex, final GridColumn<?> column) { checkSimulation(); deleteColumn(columnIndex); String group = ((ScenarioGridColumn) column).getInformationHeaderMetaData().getColumnGroup(); String columnId = ((ScenarioGridColumn) column).getInformationHeaderMetaData().getColumnId(); ExpressionIdentifier ei = ExpressionIdentifier.create(columnId, FactMappingType.valueOf(group)); commonAddColumn(columnIndex, column, ei); }
@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)); }
@Override protected void internalExecute(ScenarioSimulationContext context) { final ScenarioSimulationContext.Status status = context.getStatus(); context.getModel().deleteColumn(status.getColumnIndex()); if (context.getModel().getGroupSize(status.getColumnGroup()) < 1) { FactMappingType factMappingType = FactMappingType.valueOf(status.getColumnGroup().toUpperCase()); Map.Entry<String, String> validPlaceholders = context.getModel().getValidPlaceholders(); String instanceTitle = validPlaceholders.getKey(); String propertyTitle = validPlaceholders.getValue(); context.getModel().insertColumn(status.getColumnIndex(), getScenarioGridColumnLocal(instanceTitle, propertyTitle, String.valueOf(new Date().getTime()), status.getColumnGroup(), factMappingType, context.getScenarioGridPanel(), context.getScenarioGridLayer(), ScenarioSimulationEditorConstants.INSTANCE.defineValidType())); } GridColumn<?> selectedColumn = context.getModel().getSelectedColumn(); boolean toDisable = selectedColumn == null || context.getModel().getColumns().indexOf(selectedColumn) == status.getColumnIndex(); if (context.getRightPanelPresenter() != null && toDisable) { new DisableRightPanelCommand().execute(context); } } }
String columnId = factMappingDescription.getExpressionIdentifier().getName(); FactMappingType type = factMappingDescription.getExpressionIdentifier().getType(); String columnGroup = type.name(); scenarioGrid.setHeaderColumn(1, factMappingDescription, true); verify(scenarioGrid, times(1)).isPropertyAssigned(eq(true), eq(factMappingDescription)); columnId = factMappingGiven.getExpressionIdentifier().getName(); type = factMappingGiven.getExpressionIdentifier().getType(); columnGroup = type.name(); scenarioGrid.setHeaderColumn(1, factMappingGiven, true); verify(scenarioGrid, times(1)).isPropertyAssigned(eq(true), eq(factMappingGiven));
String columnGroup = selectedInformationHeaderMetaData.getColumnGroup(); String originalInstanceTitle = selectedInformationHeaderMetaData.getTitle(); FactMappingType factMappingType = FactMappingType.valueOf(columnGroup.toUpperCase()); Map.Entry<String, String> validPlaceholders = context.getModel().getValidPlaceholders(); boolean cloneInstance = status.isAsProperty() && selectedColumn.isInstanceAssigned();