use of org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionCellValue in project kie-wb-common by kiegroup.
the class RelationColumn method getMinimumWidthOfPeers.
private double getMinimumWidthOfPeers() {
final GridCellTuple parent = gridWidget.getParentInformation();
final GridData parentUiModel = parent.getGridWidget().getModel();
final int parentUiRowIndex = parent.getRowIndex();
final int parentUiColumnIndex = parent.getColumnIndex();
double minimumWidth = super.getMinimumWidth();
for (int uiRowIndex = 0; uiRowIndex < parentUiModel.getRowCount(); uiRowIndex++) {
if (uiRowIndex != parentUiRowIndex) {
final GridRow row = parentUiModel.getRow(uiRowIndex);
final GridCell<?> cell = row.getCells().get(parentUiColumnIndex);
if (cell != null) {
final GridCellValue<?> value = cell.getValue();
if (value instanceof ExpressionCellValue) {
final ExpressionCellValue ecv = (ExpressionCellValue) value;
final Optional<BaseExpressionGrid> editor = ecv.getValue();
final double padding = editor.map(BaseExpressionGrid::getPadding).get();
minimumWidth = Math.max(minimumWidth, ecv.getMinimumWidth().orElse(0.0) + padding * 2);
}
}
}
}
return minimumWidth;
}
use of org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionCellValue in project kie-wb-common by kiegroup.
the class AddContextEntryCommandTest method setup.
@Before
@SuppressWarnings("unchecked")
public void setup() {
this.context = new Context();
this.contextEntry = new ContextEntry() {
{
setVariable(new InformationItem() {
{
setName(new Name("variable"));
}
});
}
};
this.defaultResultContextEntry = new ContextEntry();
this.context.getContextEntry().add(defaultResultContextEntry);
this.uiModel = new BaseGridData();
this.uiModelRow = new BaseGridRow();
this.uiDefaultResultModelRow = new BaseGridRow();
this.uiModel.appendRow(uiDefaultResultModelRow);
this.uiModel.appendColumn(uiRowNumberColumn);
this.uiModel.appendColumn(uiNameColumn);
this.uiModel.appendColumn(uiExpressionEditorColumn);
doReturn(uiModel).when(gridWidget).getModel();
doReturn(ruleManager).when(handler).getRuleManager();
doReturn(0).when(uiRowNumberColumn).getIndex();
doReturn(1).when(uiNameColumn).getIndex();
doReturn(2).when(uiExpressionEditorColumn).getIndex();
this.uiModel.setCellValue(0, 2, new ExpressionCellValue(Optional.of(undefinedExpressionEditor)));
final ExpressionEditorDefinitions expressionEditorDefinitions = new ExpressionEditorDefinitions();
expressionEditorDefinitions.add(undefinedExpressionEditorDefinition);
doReturn(parent).when(undefinedExpressionEditor).getParentInformation();
doReturn(Optional.empty()).when(undefinedExpressionEditorDefinition).getModelClass();
doReturn(Optional.of(undefinedExpressionEditor)).when(undefinedExpressionEditorDefinition).getEditor(any(GridCellTuple.class), any(Optional.class), any(HasExpression.class), any(Optional.class), anyBoolean(), anyInt());
this.uiModelMapper = new ContextUIModelMapper(gridWidget, () -> uiModel, () -> Optional.of(context), () -> false, () -> expressionEditorDefinitions, listSelector, 0);
}
use of org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionCellValue in project kie-wb-common by kiegroup.
the class AddContextEntryCommandTest 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 ContextEntry secondRowEntry = new ContextEntry() {
{
setVariable(new InformationItem());
}
};
final GridRow uiSecondModelRow = new BaseGridRow();
command = spy(new AddContextEntryCommand(context, secondRowEntry, uiModel, uiSecondModelRow, context.getContextEntry().size() - 1, 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(3, uiModel.getRowCount());
assertEquals(uiModelRow, uiModel.getRows().get(0));
assertEquals(uiSecondModelRow, uiModel.getRows().get(1));
assertEquals(uiDefaultResultModelRow, uiModel.getRows().get(2));
assertEquals(3, uiModel.getColumnCount());
assertEquals(uiRowNumberColumn, uiModel.getColumns().get(0));
assertEquals(uiNameColumn, uiModel.getColumns().get(1));
assertEquals(uiExpressionEditorColumn, uiModel.getColumns().get(2));
assertEquals(3, uiModel.getRows().get(0).getCells().size());
assertEquals(1, uiModel.getCell(0, 0).getValue().getValue());
assertEquals(ContextEntryDefaultValueUtilities.PREFIX + "1", ((InformationItemCell.HasNameAndDataTypeCell) uiModel.getCell(0, 1).getValue().getValue()).getName().getValue());
assertTrue(uiModel.getCell(0, 2).getValue() instanceof ExpressionCellValue);
assertEquals(3, uiModel.getRows().get(1).getCells().size());
assertEquals(2, uiModel.getCell(1, 0).getValue().getValue());
assertEquals(ContextEntryDefaultValueUtilities.PREFIX + "2", ((InformationItemCell.HasNameAndDataTypeCell) uiModel.getCell(1, 1).getValue().getValue()).getName().getValue());
assertTrue(uiModel.getCell(1, 2).getValue() instanceof ExpressionCellValue);
// Default row
assertEquals(1, uiModel.getRows().get(2).getCells().size());
assertTrue(uiModel.getCell(2, 2).getValue() instanceof ExpressionCellValue);
verify(canvasOperation, times(2)).execute();
}
use of org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionCellValue in project kie-wb-common by kiegroup.
the class FunctionGridTest method testOnItemSelectedExpressionColumnUndefinedExpressionType.
@Test
public void testOnItemSelectedExpressionColumnUndefinedExpressionType() {
setupGrid(0);
// Clear editor for expression at (0, 0)
grid.getModel().setCellValue(0, 0, new ExpressionCellValue(Optional.empty()));
assertNoListItems(grid.getItems(0, 0));
}
use of org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionCellValue in project kie-wb-common by kiegroup.
the class ExpressionContainerGridTest method testSetDefinedExpression.
@Test
public void testSetDefinedExpression() {
when(hasExpression.getExpression()).thenReturn(literalExpression);
grid.setExpression(NODE_UUID, hasExpression, Optional.of(hasName), false);
final GridCellValue<?> gridCellValue = grid.getModel().getCell(0, 0).getValue();
assertThat(gridCellValue).isInstanceOf(ExpressionCellValue.class);
final ExpressionCellValue expressionCellValue = (ExpressionCellValue) gridCellValue;
assertThat(expressionCellValue.getValue().isPresent()).isTrue();
assertThat(expressionCellValue.getValue().get()).isSameAs(literalExpressionEditor);
assertThat(grid.isOnlyVisualChangeAllowed()).isFalse();
verify(literalExpressionEditor).selectFirstCell();
verify(gridLayer).batch();
}
Aggregations