use of org.kie.workbench.common.dmn.client.widgets.grid.BaseGrid in project kie-wb-common by kiegroup.
the class ExpressionEditorColumnTest method mockEditor.
@SuppressWarnings("unchecked")
private BaseExpressionGrid<? extends Expression, ? extends GridData, ? extends BaseUIModelMapper> 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);
when(gridWidget.getExpression()).thenReturn(Optional::empty);
final GridCellTuple parent = new GridCellTuple(0, 0, null);
final Optional<HasName> hasName = Optional.of(mock(HasName.class));
return new BaseExpressionGrid(parent, Optional.empty(), HasExpression.NOP, hasName, gridPanel, gridLayer, new DMNGridData(), renderer, definitionUtils, sessionManager, sessionCommandManager, canvasCommandFactory, editorSelectedEvent, refreshFormPropertiesEvent, domainObjectSelectionEvent, cellEditorControls, listSelector, translationService, false, 0, readOnlyProvider) {
@Override
protected BaseUIModelMapper makeUiModelMapper() {
return null;
}
@Override
public void initialiseUiColumns() {
for (double width : widthOfCells) {
model.appendColumn(new DMNGridColumn<BaseGrid<Expression>, Object>(headerMetaData, gridColumnRenderer, width, gridWidget) {
{
setMinimumWidth(width);
setWidth(width);
}
});
}
}
@Override
public void initialiseUiRows() {
// Nothing for this test
}
@Override
public void initialiseUiCells() {
// Nothing for this test
}
@Override
public double getPadding() {
return padding;
}
};
}
use of org.kie.workbench.common.dmn.client.widgets.grid.BaseGrid in project kie-wb-common by kiegroup.
the class DMNGridPanelContextMenuHandlerTest method onContextMenu_WithGridWidget_EventOutsideGridBounds.
@Test
public void onContextMenu_WithGridWidget_EventOutsideGridBounds() {
when(nativeEvent.getClientX()).thenReturn((int) (COLUMN0_WIDTH + COLUMN1_WIDTH + 50));
when(nativeEvent.getClientY()).thenReturn((int) ROW_HEIGHT + 50);
final BaseGrid gridWidget = mockGridWidget();
when(gridLayer.getGridWidgets()).thenReturn(Collections.singleton(gridWidget));
handler.onContextMenu(event);
verify(cellEditorControls, never()).show(any(HasCellEditorControls.Editor.class), anyInt(), anyInt());
}
use of org.kie.workbench.common.dmn.client.widgets.grid.BaseGrid in project kie-wb-common by kiegroup.
the class DMNGridPanelContextMenuHandlerTest method onContextMenu_WithMultipleOverlappingGridWidgets.
@Test
@SuppressWarnings("unchecked")
public void onContextMenu_WithMultipleOverlappingGridWidgets() {
final int EVENT_X = (int) (COLUMN0_WIDTH / 2);
final int EVENT_Y = (int) (HEADER_HEIGHT + ROW_HEIGHT + ROW_HEIGHT / 2);
when(nativeEvent.getClientX()).thenReturn(EVENT_X);
when(nativeEvent.getClientY()).thenReturn(EVENT_Y);
final BaseGrid gridWidget1 = mockGridWidget();
final BaseGrid gridWidget2 = mockGridWidget();
// Without stubbing mocks to death this requires some knowledge of the internals of
// DefaultGridLayer that maintains a LinkedHashSet of GridWidgets added to the Layer.
// LinkedHashSet returns items in the order in which they were added.
final Set<GridWidget> gridWidgets = new LinkedHashSet<>();
gridWidgets.add(gridWidget1);
gridWidgets.add(gridWidget2);
when(gridLayer.getGridWidgets()).thenReturn(gridWidgets);
final MockCell cell1 = mock(MockCell.class);
gridWidget1.getModel().setCell(1, 0, () -> cell1);
when(cell1.getEditor()).thenReturn(Optional.of(editor));
final MockCell cell2 = mock(MockCell.class);
gridWidget2.getModel().setCell(1, 0, () -> cell2);
when(cell2.getEditor()).thenReturn(Optional.of(editor));
handler.onContextMenu(event);
// gridWidget2 was added second and is therefore considered "on top of" gridWidget1
verify(editor).bind(eq(gridWidget2), eq(1), eq(0));
verify(cellEditorControls).show(eq(editor), eq(EVENT_X), eq(EVENT_Y));
}
use of org.kie.workbench.common.dmn.client.widgets.grid.BaseGrid in project kie-wb-common by kiegroup.
the class DMNGridPanelContextMenuHandlerTest method onContextMenu_WithGridWidget_WithCellValue_WithOnlyVisualChangeAllowed.
@Test
public void onContextMenu_WithGridWidget_WithCellValue_WithOnlyVisualChangeAllowed() {
final int EVENT_X = (int) (COLUMN0_WIDTH / 2);
final int EVENT_Y = (int) (ROW_HEIGHT + ROW_HEIGHT / 2);
when(nativeEvent.getClientX()).thenReturn(EVENT_X);
when(nativeEvent.getClientY()).thenReturn(EVENT_Y);
final BaseGrid gridWidget = mockGridWidget();
doReturn(true).when(gridWidget).isOnlyVisualChangeAllowed();
when(gridLayer.getGridWidgets()).thenReturn(Collections.singleton(gridWidget));
handler.onContextMenu(event);
verify(cellEditorControls, never()).show(any(HasCellEditorControls.Editor.class), anyInt(), anyInt());
}
use of org.kie.workbench.common.dmn.client.widgets.grid.BaseGrid in project kie-wb-common by kiegroup.
the class DMNGridPanelContextMenuHandlerTest method onContextMenu_WithGridWidget_WithCellSelectionStrategy_CellNotSelected.
@Test
public void onContextMenu_WithGridWidget_WithCellSelectionStrategy_CellNotSelected() {
when(nativeEvent.getClientX()).thenReturn((int) (COLUMN0_WIDTH / 2));
when(nativeEvent.getClientY()).thenReturn((int) (HEADER_HEIGHT + ROW_HEIGHT + ROW_HEIGHT / 2));
final BaseGrid gridWidget = mockGridWidget();
when(gridLayer.getGridWidgets()).thenReturn(Collections.singleton(gridWidget));
final MockCell cell = mock(MockCell.class);
final CellSelectionStrategy selectionStrategy = mock(CellSelectionStrategy.class);
gridWidget.getModel().setCell(1, 0, () -> cell);
when(cell.getEditor()).thenReturn(Optional.of(editor));
when(cell.getSelectionStrategy()).thenReturn(selectionStrategy);
handler.onContextMenu(event);
verify(cellSelectionHandler).selectCellIfRequired(eq(1), eq(0), eq(gridWidget), eq(false), eq(false));
}
Aggregations