use of org.kie.workbench.common.dmn.api.definition.HasExpression in project kie-wb-common by kiegroup.
the class AddListRowCommandTest method testCanvasCommandExecuteMultipleEntries.
@Test
public void testCanvasCommandExecuteMultipleEntries() {
makeCommand();
// first row
command.newGraphCommand(handler).execute(gce);
final Command<AbstractCanvasHandler, CanvasViolation> firstEntryCanvasCommand = command.newCanvasCommand(handler);
assertEquals(CanvasCommandResultBuilder.SUCCESS, firstEntryCanvasCommand.execute(handler));
verify(command).updateRowNumbers();
verify(command).updateParentInformation();
// second row
final HasExpression secondRowEntry = HasExpression.wrap(list, new LiteralExpression());
final GridRow uiSecondModelRow = new BaseGridRow();
command = spy(new AddListRowCommand(list, secondRowEntry, uiModel, uiSecondModelRow, list.getExpression().size(), uiModelMapper, canvasOperation));
command.newGraphCommand(handler).execute(gce);
final Command<AbstractCanvasHandler, CanvasViolation> secondEntryCanvasCommand = command.newCanvasCommand(handler);
assertEquals(CanvasCommandResultBuilder.SUCCESS, secondEntryCanvasCommand.execute(handler));
verify(command).updateRowNumbers();
verify(command).updateParentInformation();
assertEquals(2, uiModel.getRowCount());
assertEquals(uiModelRow, uiModel.getRows().get(0));
assertEquals(uiSecondModelRow, uiModel.getRows().get(1));
assertEquals(2, uiModel.getColumnCount());
assertEquals(uiRowNumberColumn, uiModel.getColumns().get(ROW_COLUMN_INDEX));
assertEquals(uiExpressionEditorColumn, uiModel.getColumns().get(EXPRESSION_COLUMN_INDEX));
assertEquals(2, uiModel.getRows().get(0).getCells().size());
assertEquals(1, uiModel.getCell(0, ROW_COLUMN_INDEX).getValue().getValue());
assertTrue(uiModel.getCell(0, EXPRESSION_COLUMN_INDEX).getValue() instanceof ExpressionCellValue);
assertEquals(2, uiModel.getRows().get(1).getCells().size());
assertEquals(2, uiModel.getCell(1, ROW_COLUMN_INDEX).getValue().getValue());
assertTrue(uiModel.getCell(1, EXPRESSION_COLUMN_INDEX).getValue() instanceof ExpressionCellValue);
verify(canvasOperation, times(2)).execute();
}
use of org.kie.workbench.common.dmn.api.definition.HasExpression in project kie-wb-common by kiegroup.
the class AddListRowCommandTest method testGraphCommandUndoMultipleEntriesPresent.
@Test
public void testGraphCommandUndoMultipleEntriesPresent() {
final HasExpression firstEntry = HasExpression.wrap(list, new LiteralExpression());
list.getExpression().add(0, firstEntry);
makeCommand();
final Command<GraphCommandExecutionContext, RuleViolation> c = command.newGraphCommand(handler);
// Add row and then undo
assertEquals(GraphCommandResultBuilder.SUCCESS, c.execute(gce));
assertEquals(GraphCommandResultBuilder.SUCCESS, c.undo(gce));
assertEquals(1, list.getExpression().size());
assertEquals(firstEntry, list.getExpression().get(0));
}
use of org.kie.workbench.common.dmn.api.definition.HasExpression in project kie-wb-common by kiegroup.
the class ObserverBuilderControl method updateElementFromDefinition.
@Override
@SuppressWarnings("unchecked")
protected void updateElementFromDefinition(final Element element, final Object definition) {
final Object content = element.getContent();
if (!(content instanceof View)) {
return;
}
final Object newDefinition = ((View) content).getDefinition();
if (newDefinition instanceof HasName && definition instanceof HasName) {
((HasName) newDefinition).getName().setValue(((HasName) definition).getName().getValue());
}
if (newDefinition instanceof DynamicReadOnly && definition instanceof DynamicReadOnly) {
((DynamicReadOnly) newDefinition).setAllowOnlyVisualChange(((DynamicReadOnly) definition).isAllowOnlyVisualChange());
}
if (newDefinition instanceof HasVariable && definition instanceof HasVariable) {
((HasVariable) newDefinition).setVariable(((HasVariable) definition).getVariable());
}
if (newDefinition instanceof BusinessKnowledgeModel && definition instanceof BusinessKnowledgeModel) {
((BusinessKnowledgeModel) newDefinition).setEncapsulatedLogic(((BusinessKnowledgeModel) definition).getEncapsulatedLogic());
}
if (newDefinition instanceof HasExpression && definition instanceof HasExpression) {
((HasExpression) newDefinition).setExpression(((HasExpression) definition).getExpression());
}
if (newDefinition instanceof DMNElement && definition instanceof DMNElement) {
final DMNElement dmnElement = (DMNElement) definition;
if (!StringUtils.isEmpty(dmnElement.getId().getValue())) {
((DMNElement) newDefinition).getId().setValue(dmnElement.getId().getValue());
}
}
final Optional<DMNDiagramElement> currentDMNDiagramElement = getDMNDiagramsSession().getCurrentDMNDiagramElement();
if (currentDMNDiagramElement.isPresent() && newDefinition instanceof HasContentDefinitionId) {
((HasContentDefinitionId) newDefinition).setDiagramId(currentDMNDiagramElement.get().getId().getValue());
}
}
use of org.kie.workbench.common.dmn.api.definition.HasExpression in project kie-wb-common by kiegroup.
the class DeleteRelationColumnCommand method newGraphCommand.
@Override
protected Command<GraphCommandExecutionContext, RuleViolation> newGraphCommand(final AbstractCanvasHandler handler) {
return new AbstractGraphCommand() {
@Override
protected CommandResult<RuleViolation> check(final GraphCommandExecutionContext gce) {
return GraphCommandResultBuilder.SUCCESS;
}
@Override
public CommandResult<RuleViolation> execute(final GraphCommandExecutionContext gce) {
relation.getComponentWidths().remove(uiColumnIndex);
final int iiIndex = uiColumnIndex - RelationUIModelMapperHelper.ROW_INDEX_COLUMN_COUNT;
relation.getRow().forEach(row -> row.getExpression().remove(iiIndex));
relation.getColumn().remove(iiIndex);
return GraphCommandResultBuilder.SUCCESS;
}
@Override
public CommandResult<RuleViolation> undo(final GraphCommandExecutionContext gce) {
relation.getComponentWidths().add(uiColumnIndex, oldUiModelColumn.getWidth());
final int iiIndex = uiColumnIndex - RelationUIModelMapperHelper.ROW_INDEX_COLUMN_COUNT;
relation.getColumn().add(iiIndex, oldInformationItem);
IntStream.range(0, relation.getRow().size()).forEach(rowIndex -> {
final HasExpression hasExpression = oldColumnData.get(rowIndex);
relation.getRow().get(rowIndex).getExpression().add(iiIndex, hasExpression);
});
return GraphCommandResultBuilder.SUCCESS;
}
};
}
use of org.kie.workbench.common.dmn.api.definition.HasExpression in project kie-wb-common by kiegroup.
the class ExpressionContainerGrid method spyHasExpression.
/**
* Proxy {@link HasExpression} to be able intercept interactions with the original
* to update the expression label in {@link ExpressionEditorView} when the {@link Expression} changes.
* @param hasExpression A {@link HasExpression} to be proxied.
* @return A proxy that intercepts interactions with the wrapped {@link HasExpression}
*/
HasExpression spyHasExpression(final HasExpression hasExpression) {
final HasExpression spy = new HasExpression() {
@Override
public Expression getExpression() {
return hasExpression.getExpression();
}
@Override
public void setExpression(final Expression expression) {
hasExpression.setExpression(expression);
onHasExpressionChanged.execute(Optional.ofNullable(expression));
}
@Override
public DMNModelInstrumentedBase asDMNModelInstrumentedBase() {
return hasExpression.asDMNModelInstrumentedBase();
}
@Override
public boolean isClearSupported() {
return hasExpression.isClearSupported();
}
};
return spy;
}
Aggregations