/** * Checks if a {@link AbstractNodeMouseEvent} happened within a {@link GridCell}. If the * {@link AbstractNodeMouseEvent} is found to have happened within a cell, the {@link GridCell#getSupportedEditAction()} * is checked to {@link Object#equals(Object)} that for the {@link AbstractNodeMouseEvent}. If they equal then the * {@link GridCell} is put into "edit" mode via {@link GridWidget#startEditingCell(Point2D)}. */ @Override public boolean handleBodyCell(final GridWidget gridWidget, final Point2D relativeLocation, final int uiRowIndex, final int uiColumnIndex, final AbstractNodeMouseEvent event) { final GridData gridData = gridWidget.getModel(); if (gridData.getSelectedCells().size() == 1) { final GridCell<?> cell = gridData.getCell(uiRowIndex, uiColumnIndex); final GridCellEditAction cellEditAction = cell == null ? GridCell.DEFAULT_EDIT_ACTION : cell.getSupportedEditAction(); if (Objects.equals(cellEditAction, GridCellEditAction.getSupportedEditAction(event))) { return gridWidget.startEditingCell(relativeLocation); } } return false; } }
/** * Checks if a {@link AbstractNodeMouseEvent} happened within a {@link GridCell}. If the * {@link AbstractNodeMouseEvent} is found to have happened within a cell, the {@link GridCell#getSupportedEditAction()} * is checked to {@link Object#equals(Object)} that for the {@link AbstractNodeMouseEvent}. If they equal then the * {@link GridCell} is put into "edit" mode via {@link GridWidget#startEditingCell(Point2D)}. */ @Override public boolean handleBodyCell(final GridWidget gridWidget, final Point2D relativeLocation, final int uiRowIndex, final int uiColumnIndex, final AbstractNodeMouseEvent event) { final GridData gridData = gridWidget.getModel(); if (gridData.getSelectedCells().size() == 1) { final GridCell<?> cell = gridData.getCell(uiRowIndex, uiColumnIndex); final GridCellEditAction cellEditAction = cell == null ? GridCell.DEFAULT_EDIT_ACTION : cell.getSupportedEditAction(); if (Objects.equals(cellEditAction, GridCellEditAction.getSupportedEditAction(event))) { return gridWidget.startEditingCell(relativeLocation); } } return false; } }
@Test @SuppressWarnings("unchecked") public void testEditBodyCellWithASelectedCell() { when(uiModel.getSelectedCells()).thenReturn(Collections.singletonList(new GridData.SelectedCell(0, 1))); when(uiModel.getCell(eq(0), eq(1))).thenReturn(gridCell); when(gridCell.getSupportedEditAction()).thenReturn(GridCellEditAction.DOUBLE_CLICK); assertThat(handler.onNodeMouseEvent(gridWidget, relativeLocation, Optional.empty(), Optional.empty(), Optional.of(0), Optional.of(1), event)).isFalse(); verify(gridWidget, never()).startEditingCell(anyInt(), anyInt()); verify(gridWidget).startEditingCell(eq(relativeLocation)); }
@Test @SuppressWarnings("unchecked") public void testEditBodyCellWithASelectedCell() { when(uiModel.getSelectedCells()).thenReturn(Collections.singletonList(new GridData.SelectedCell(0, 1))); when(uiModel.getCell(eq(0), eq(1))).thenReturn(gridCell); when(gridCell.getSupportedEditAction()).thenReturn(GridCellEditAction.DOUBLE_CLICK); assertThat(handler.onNodeMouseEvent(gridWidget, relativeLocation, Optional.empty(), Optional.empty(), Optional.of(0), Optional.of(1), event)).isFalse(); verify(gridWidget, never()).startEditingCell(anyInt(), anyInt()); verify(gridWidget).startEditingCell(eq(relativeLocation)); }
private boolean delegatedHandleBodyCell(final GridWidget gridWidget, final Point2D relativeLocation, final int uiRowIndex, final int uiColumnIndex, final AbstractNodeMouseEvent event) { final GridCellTuple parent = parentSupplier.get(); final GridWidget parentGridWidget = parent.getGridWidget(); final GridData parentGridData = parentGridWidget.getModel(); if (parentGridData.getSelectedCells().size() == 1) { final GridData gridData = gridWidget.getModel(); final GridCell<?> cell = gridData.getCell(uiRowIndex, uiColumnIndex); final GridCellEditAction cellEditAction = cell == null ? GridCell.DEFAULT_EDIT_ACTION : cell.getSupportedEditAction(); if (isEventHandled(cellEditAction, event)) { return gridWidget.startEditingCell(relativeLocation); } } return false; }