use of org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridColumn in project kie-wb-common by kiegroup.
the class BaseExpressionGridGeneralTest method testUpdateWidthOfPeers.
/*
* Test that parent column width is updated to sum of nested columns
* The update is forced from nested column at position indexOfColumnToUpdate
* The default width of parent column is 100
*/
private void testUpdateWidthOfPeers(final int indexOfColumnToUpdate, final double... widthsOfNestedColumns) {
// parent column
final BaseExpressionGrid parentGrid = mock(BaseExpressionGrid.class);
final GridData parentGridData = mock(GridData.class);
final DMNGridColumn parentColumn = mockColumn(100, null);
doReturn(parentGrid).when(parentCell).getGridWidget();
doReturn(parentGridData).when(parentGrid).getModel();
doReturn(Collections.singletonList(parentColumn)).when(parentGridData).getColumns();
doReturn(Collections.singleton(parentGrid)).when(gridLayer).getGridWidgets();
// nested columns
final List<DMNGridColumn> columns = Arrays.stream(widthsOfNestedColumns).mapToObj(width -> mockColumn(width, grid)).collect(Collectors.toList());
grid.getModel().appendRow(new DMNGridRow());
columns.stream().forEach(column -> grid.getModel().appendColumn(column));
// force the peers width update
columns.get(indexOfColumnToUpdate).updateWidthOfPeers();
// assert parent width is equal to sum of nested columns widths
final double padding = BaseExpressionGrid.DEFAULT_PADDING * 2;
Assertions.assertThat(parentColumn.getWidth()).isEqualTo(Arrays.stream(widthsOfNestedColumns).sum() + padding);
}
use of org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridColumn in project kie-wb-common by kiegroup.
the class BaseExpressionGridGeneralTest method mockColumn.
@SuppressWarnings("unchecked")
private DMNGridColumn mockColumn(final double width, final GridWidget gridWidget) {
final GridColumn.HeaderMetaData headerMetaData = mock(GridColumn.HeaderMetaData.class);
final GridColumnRenderer columnRenderer = mock(GridColumnRenderer.class);
return new DMNGridColumn(headerMetaData, columnRenderer, gridWidget) {
{
setWidth(width);
}
};
}
use of org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridColumn in project kie-wb-common by kiegroup.
the class ExpressionEditorColumnTest method mockEditor.
@SuppressWarnings("unchecked")
private BaseExpressionGrid mockEditor(final double padding, final double... widthOfCells) {
final GridColumn.HeaderMetaData headerMetaData = mock(GridColumn.HeaderMetaData.class);
final GridColumnRenderer gridColumnRenderer = mock(GridColumnRenderer.class);
final BaseExpressionGrid gridWidget = mock(BaseExpressionGrid.class);
final GridCellTuple parent = new GridCellTuple(0, 0, null);
final HasExpression hasExpression = mock(HasExpression.class);
final Optional<LiteralExpression> expression = Optional.of(mock(LiteralExpression.class));
final Optional<HasName> hasName = Optional.of(mock(HasName.class));
return new BaseExpressionGrid(parent, Optional.empty(), hasExpression, expression, hasName, gridPanel, gridLayer, new GridDataCache.CacheResult(new DMNGridData(), false), renderer, definitionUtils, sessionManager, sessionCommandManager, canvasCommandFactory, cellEditorControls, listSelector, translationService, 0) {
@Override
protected BaseUIModelMapper makeUiModelMapper() {
return null;
}
@Override
protected void initialiseUiColumns() {
for (double width : widthOfCells) {
model.appendColumn(new DMNGridColumn<GridWidget, Object>(headerMetaData, gridColumnRenderer, gridWidget) {
{
setMinimumWidth(width);
setWidth(width);
}
});
}
}
@Override
protected void initialiseUiModel() {
// Nothing for this test
}
@Override
protected boolean isHeaderHidden() {
return false;
}
@Override
public double getPadding() {
return padding;
}
};
}
Aggregations