@Test public void executeIfSelectedColumn_WithInstanceAndPropertyAndThreeColumns() { final String SECOND = "SECOND"; addNewColumn(scenarioGridColumnMock2, headerMetaDatasMock2, informationHeaderMetaDataMock2, propertyHeaderMetaDataMock2, factIdentifierMock2, factMappingMock2, factMappingValueMock2, COLUMN_NUMBER + 1, COLUMN_NUMBER + 2, COLUMN_NUMBER + 1, MULTIPART_VALUE + "_2", GRID_PROPERTY_TITLE + "_2", GRID_COLUMN_ID + "_2", FACT_ALIAS + "_2", VALUE_CLASS_NAME, SECOND, FULL_CLASS_NAME + "_2", FACT_IDENTIFIER_NAME + "_2"); final String THIRD = "THIRD"; addNewColumn(scenarioGridColumnMock3, headerMetaDatasMock3, informationHeaderMetaDataMock2, propertyHeaderMetaDataMock3, factIdentifierMock2, factMappingMock3, factMappingValueMock3, COLUMN_NUMBER + 1, COLUMN_NUMBER + 2, COLUMN_NUMBER + 2, MULTIPART_VALUE + "_2", GRID_PROPERTY_TITLE + "_3", GRID_COLUMN_ID + "_3", FACT_ALIAS + "_3", VALUE_CLASS_NAME, THIRD, FULL_CLASS_NAME + "_2", FACT_IDENTIFIER_NAME + "_3"); ((DuplicateInstanceCommand) commandSpy).executeIfSelectedColumn(scenarioSimulationContextLocal, scenarioGridColumnMock2); verify(scenarioGridModelMock, times(1)).getInstancesCount(eq(scenarioGridColumnMock2.getFactIdentifier().getClassName())); verify((DuplicateInstanceCommand) commandSpy, times(1)).insertNewColumn(eq(scenarioSimulationContextLocal), eq(scenarioGridColumnMock2), eq(7), eq(Boolean.FALSE)); verify((DuplicateInstanceCommand) commandSpy, times(1)).insertNewColumn(eq(scenarioSimulationContextLocal), eq(scenarioGridColumnMock3), eq(8), eq(Boolean.FALSE)); String expectedDuplicatedLabelSecond = MULTIPART_VALUE + "_2" + DuplicateInstanceCommand.COPY_LABEL + "2"; verify((DuplicateInstanceCommand) commandSpy, times(2)).setInstanceHeader(eq(scenarioSimulationContextLocal), eq(gridColumnMock), eq(expectedDuplicatedLabelSecond), eq(FULL_CLASS_NAME + "_2")); List<String> expectedPropertyNameElementsSecond = Arrays.asList(expectedDuplicatedLabelSecond, SECOND); List<String> expectedPropertyNameElementsThird = Arrays.asList(expectedDuplicatedLabelSecond, THIRD); verify((DuplicateInstanceCommand) commandSpy, times(1)).setPropertyHeader(eq(scenarioSimulationContextLocal), eq(gridColumnMock), eq(expectedPropertyNameElementsSecond), eq(VALUE_CLASS_NAME), eq(GRID_PROPERTY_TITLE + "_2")); verify((DuplicateInstanceCommand) commandSpy, times(1)).setPropertyHeader(eq(scenarioSimulationContextLocal), eq(gridColumnMock), eq(expectedPropertyNameElementsThird), eq(VALUE_CLASS_NAME), eq(GRID_PROPERTY_TITLE + "_3")); verify(scenarioGridModelMock, times(1)).duplicateColumnValues(eq(COLUMN_NUMBER + 1), eq(0)); verify(scenarioGridModelMock, times(1)).duplicateColumnValues(eq(COLUMN_NUMBER + 2), eq(0)); }
@Override protected void executeIfSelectedColumn(ScenarioSimulationContext context, ScenarioGridColumn selectedColumn) { final AbstractScesimGridModel<? extends AbstractScesimModel, ? extends AbstractScesimData> selectedScenarioGridModel = context.getAbstractScesimGridModelByGridWidget(gridWidget); int instancesCount = selectedScenarioGridModel.getInstancesCount(selectedColumn.getFactIdentifier().getClassName()); String alias = selectedColumn.getInformationHeaderMetaData().getTitle().split(COPY_LABEL)[0] + COPY_LABEL + instancesCount; int columnPosition = selectedScenarioGridModel.getInstanceLimits(selectedScenarioGridModel.getColumns().indexOf(selectedColumn)).getMaxRowIndex() + 1; AtomicInteger nextColumnPosition = new AtomicInteger(columnPosition); selectedScenarioGridModel.getInstanceScenarioGridColumns(selectedColumn).forEach( originalColumn -> { ScenarioGridColumn createdColumn = insertNewColumn(context, originalColumn, nextColumnPosition.getAndIncrement(), false); if (originalColumn.isInstanceAssigned()) { setInstanceHeader(context, createdColumn, alias, originalColumn.getFactIdentifier().getClassName()); if (originalColumn.isPropertyAssigned()) { int originalColumnIndex = selectedScenarioGridModel.getColumns().indexOf(originalColumn); final FactMapping originalFactMapping = selectedScenarioGridModel.getAbstractScesimModel().get().getScesimModelDescriptor().getFactMappingByIndex(originalColumnIndex); factMappingValueType = originalFactMapping.getFactMappingValueType(); List<String> propertyNameElements = new ArrayList<>(); propertyNameElements.add(alias); propertyNameElements.addAll(originalFactMapping.getExpressionElementsWithoutClass().stream().map(ExpressionElement::getStep).collect(Collectors.toList())); setPropertyHeader(context, createdColumn, propertyNameElements, originalFactMapping.getClassName(), originalColumn.getPropertyHeaderMetaData().getTitle()); int createdColumnIndex = selectedScenarioGridModel.getColumns().indexOf(createdColumn); selectedScenarioGridModel.duplicateColumnValues(originalColumnIndex, createdColumnIndex); } } }); }
DuplicateInstanceCommand extends AbstractSelectedColumnCommand { @Override protected void executeIfSelectedColumn(ScenarioSimulationContext context, ScenarioGridColumn selectedColumn) { final AbstractScesimGridModel<? extends AbstractScesimModel, ? extends AbstractScesimData> selectedScenarioGridModel = context.getAbstractScesimGridModelByGridWidget(gridWidget); int instancesCount = selectedScenarioGridModel.getInstancesCount(selectedColumn.getFactIdentifier().getClassName()); String alias = selectedColumn.getInformationHeaderMetaData().getTitle().split(COPY_LABEL)[0] + COPY_LABEL + instancesCount; int columnPosition = selectedScenarioGridModel.getInstanceLimits(selectedScenarioGridModel.getColumns().indexOf(selectedColumn)).getMaxRowIndex() + 1; AtomicInteger nextColumnPosition = new AtomicInteger(columnPosition); selectedScenarioGridModel.getInstanceScenarioGridColumns(selectedColumn).forEach( originalColumn -> { ScenarioGridColumn createdColumn = insertNewColumn(context, originalColumn, nextColumnPosition.getAndIncrement(), false); if (originalColumn.isInstanceAssigned()) { setInstanceHeader(context, createdColumn, alias, originalColumn.getFactIdentifier().getClassName()); if (originalColumn.isPropertyAssigned()) { int originalColumnIndex = selectedScenarioGridModel.getColumns().indexOf(originalColumn); final FactMapping originalFactMapping = selectedScenarioGridModel.getAbstractScesimModel().get().getScesimModelDescriptor().getFactMappingByIndex(originalColumnIndex); factMappingValueType = originalFactMapping.getFactMappingValueType(); List<String> propertyNameElements = new ArrayList<>(); propertyNameElements.add(alias); propertyNameElements.addAll(originalFactMapping.getExpressionElementsWithoutClass().stream().map(ExpressionElement::getStep).collect(Collectors.toList())); setPropertyHeader(context, createdColumn, propertyNameElements, originalFactMapping.getClassName(), originalColumn.getPropertyHeaderMetaData().getTitle()); int createdColumnIndex = selectedScenarioGridModel.getColumns().indexOf(createdColumn); selectedScenarioGridModel.duplicateColumnValues(originalColumnIndex, createdColumnIndex); } } }); } }
DuplicateInstanceCommand extends AbstractSelectedColumnCommand { @Override protected void executeIfSelectedColumn(ScenarioSimulationContext context, ScenarioGridColumn selectedColumn) { final AbstractScesimGridModel<? extends AbstractScesimModel, ? extends AbstractScesimData> selectedScenarioGridModel = context.getAbstractScesimGridModelByGridWidget(gridWidget); int instancesCount = selectedScenarioGridModel.getInstancesCount(selectedColumn.getFactIdentifier().getClassName()); String alias = selectedColumn.getInformationHeaderMetaData().getTitle().split(COPY_LABEL)[0] + COPY_LABEL + instancesCount; int columnPosition = selectedScenarioGridModel.getInstanceLimits(selectedScenarioGridModel.getColumns().indexOf(selectedColumn)).getMaxRowIndex() + 1; AtomicInteger nextColumnPosition = new AtomicInteger(columnPosition); selectedScenarioGridModel.getInstanceScenarioGridColumns(selectedColumn).forEach( originalColumn -> { ScenarioGridColumn createdColumn = insertNewColumn(context, originalColumn, nextColumnPosition.getAndIncrement(), false); if (originalColumn.isInstanceAssigned()) { setInstanceHeader(context, createdColumn, alias, originalColumn.getFactIdentifier().getClassName()); if (originalColumn.isPropertyAssigned()) { int originalColumnIndex = selectedScenarioGridModel.getColumns().indexOf(originalColumn); final FactMapping originalFactMapping = selectedScenarioGridModel.getAbstractScesimModel().get().getScesimModelDescriptor().getFactMappingByIndex(originalColumnIndex); factMappingValueType = originalFactMapping.getFactMappingValueType(); List<String> propertyNameElements = new ArrayList<>(); propertyNameElements.add(alias); propertyNameElements.addAll(originalFactMapping.getExpressionElementsWithoutClass().stream().map(ExpressionElement::getStep).collect(Collectors.toList())); setPropertyHeader(context, createdColumn, propertyNameElements, originalFactMapping.getClassName(), originalColumn.getPropertyHeaderMetaData().getTitle()); int createdColumnIndex = selectedScenarioGridModel.getColumns().indexOf(createdColumn); selectedScenarioGridModel.duplicateColumnValues(originalColumnIndex, createdColumnIndex); } } }); } DuplicateInstanceCommand(GridWidget gridWidget); private  DuplicateInstanceCommand(); }
DuplicateInstanceCommand extends AbstractSelectedColumnCommand { @Override protected void executeIfSelectedColumn(ScenarioSimulationContext context, ScenarioGridColumn selectedColumn) { final AbstractScesimGridModel<? extends AbstractScesimModel, ? extends AbstractScesimData> selectedScenarioGridModel = context.getAbstractScesimGridModelByGridWidget(gridWidget); int instancesCount = selectedScenarioGridModel.getInstancesCount(selectedColumn.getFactIdentifier().getClassName()); String alias = selectedColumn.getInformationHeaderMetaData().getTitle().split(COPY_LABEL)[0] + COPY_LABEL + instancesCount; int columnPosition = selectedScenarioGridModel.getInstanceLimits(selectedScenarioGridModel.getColumns().indexOf(selectedColumn)).getMaxRowIndex() + 1; AtomicInteger nextColumnPosition = new AtomicInteger(columnPosition); selectedScenarioGridModel.getInstanceScenarioGridColumns(selectedColumn).forEach( originalColumn -> { ScenarioGridColumn createdColumn = insertNewColumn(context, originalColumn, nextColumnPosition.getAndIncrement(), false); if (originalColumn.isInstanceAssigned()) { setInstanceHeader(context, createdColumn, alias, originalColumn.getFactIdentifier().getClassName()); if (originalColumn.isPropertyAssigned()) { int originalColumnIndex = selectedScenarioGridModel.getColumns().indexOf(originalColumn); final FactMapping originalFactMapping = selectedScenarioGridModel.getAbstractScesimModel().get().getScesimModelDescriptor().getFactMappingByIndex(originalColumnIndex); factMappingValueType = originalFactMapping.getFactMappingValueType(); List<String> propertyNameElements = new ArrayList<>(); propertyNameElements.add(alias); propertyNameElements.addAll(originalFactMapping.getExpressionElementsWithoutClass().stream().map(ExpressionElement::getStep).collect(Collectors.toList())); setPropertyHeader(context, createdColumn, propertyNameElements, originalFactMapping.getClassName(), originalColumn.getPropertyHeaderMetaData().getTitle()); int createdColumnIndex = selectedScenarioGridModel.getColumns().indexOf(createdColumn); selectedScenarioGridModel.duplicateColumnValues(originalColumnIndex, createdColumnIndex); } } }); } DuplicateInstanceCommand(GridWidget gridWidget); private  DuplicateInstanceCommand();  }
DuplicateInstanceCommand extends AbstractSelectedColumnCommand { @Override protected void executeIfSelectedColumn(ScenarioSimulationContext context, ScenarioGridColumn selectedColumn) { final AbstractScesimGridModel<? extends AbstractScesimModel, ? extends AbstractScesimData> selectedScenarioGridModel = context.getAbstractScesimGridModelByGridWidget(gridWidget); int instancesCount = selectedScenarioGridModel.getInstancesCount(selectedColumn.getFactIdentifier().getClassName()); String alias = selectedColumn.getInformationHeaderMetaData().getTitle().split(COPY_LABEL)[0] + COPY_LABEL + instancesCount; int columnPosition = selectedScenarioGridModel.getInstanceLimits(selectedScenarioGridModel.getColumns().indexOf(selectedColumn)).getMaxRowIndex() + 1; AtomicInteger nextColumnPosition = new AtomicInteger(columnPosition); selectedScenarioGridModel.getInstanceScenarioGridColumns(selectedColumn).forEach( originalColumn -> { ScenarioGridColumn createdColumn = insertNewColumn(context, originalColumn, nextColumnPosition.getAndIncrement(), false); if (originalColumn.isInstanceAssigned()) { setInstanceHeader(context, createdColumn, alias, originalColumn.getFactIdentifier().getClassName()); if (originalColumn.isPropertyAssigned()) { int originalColumnIndex = selectedScenarioGridModel.getColumns().indexOf(originalColumn); final FactMapping originalFactMapping = selectedScenarioGridModel.getAbstractScesimModel().get().getScesimModelDescriptor().getFactMappingByIndex(originalColumnIndex); factMappingValueType = originalFactMapping.getFactMappingValueType(); List<String> propertyNameElements = new ArrayList<>(); propertyNameElements.add(alias); propertyNameElements.addAll(originalFactMapping.getExpressionElementsWithoutClass().stream().map(ExpressionElement::getStep).collect(Collectors.toList())); setPropertyHeader(context, createdColumn, propertyNameElements, originalFactMapping.getClassName(), originalColumn.getPropertyHeaderMetaData().getTitle()); int createdColumnIndex = selectedScenarioGridModel.getColumns().indexOf(createdColumn); selectedScenarioGridModel.duplicateColumnValues(originalColumnIndex, createdColumnIndex); } } }); } DuplicateInstanceCommand(GridWidget gridWidget); private  DuplicateInstanceCommand();  static final String COPY_LABEL; }