ScenarioInvokeContextMenuForSelectedCell extends KeyboardOperationInvokeContextMenuForSelectedCell { @Override public boolean perform(final GridWidget gridWidget, final boolean isShiftKeyDown, final boolean isControlKeyDown) { final GridData model = gridWidget.getModel(); if (!model.getSelectedHeaderCells().isEmpty() && !model.getSelectedCells().isEmpty()) { return false; } GridData.SelectedCell origin = null; boolean isHeader = false; if (!model.getSelectedHeaderCells().isEmpty()) { origin = model.getSelectedHeaderCells().get(0); isHeader = true; } else if (model.getSelectedCells().size() == 1) { origin = model.getSelectedCellsOrigin(); } if (origin == null) { return false; } final int uiRowIndex = origin.getRowIndex(); final int uiColumnIndex = ColumnIndexUtilities.findUiColumnIndex(model.getColumns(), origin.getColumnIndex()); final GridColumn<?> column = model.getColumns().get(uiColumnIndex); if (column instanceof ScenarioGridColumn) { final Point2D middleXYCell = this.getMiddleXYCell(gridWidget, column, isHeader, uiRowIndex, gridLayer); return scenarioContextMenuRegistry.manageRightClick((ScenarioGrid) gridWidget, (int) middleXYCell.getX(), (int) middleXYCell.getY(), uiRowIndex, uiColumnIndex, isHeader); } return false; } ScenarioInvokeContextMenuForSelectedCell(final GridLayer gridLayer, final ScenarioContextMenuRegistry
            scenarioContextMenuRegistry); @Override boolean isExecutable(final GridWidget gridWidget); @Override boolean perform(final GridWidget gridWidget, final boolean isShiftKeyDown, final boolean isControlKeyDown);  }
@Test public void perform_NoSelection() { when(scenarioGridModelMock.getSelectedCells()).thenReturn(Collections.emptyList()); when(scenarioGridModelMock.getSelectedHeaderCells()).thenReturn(Collections.emptyList()); assertFalse(handler.perform(scenarioGridMock, false, false)); verify(scenarioContextMenuRegistry, never()).manageRightClick(any(), anyInt(), anyInt(), anyInt(), anyInt(), anyBoolean()); }
@Test public void perform_CellSelected() { when(scenarioGridModelMock.getSelectedCells()).thenReturn(Arrays.asList(selectedCell)); when(scenarioGridModelMock.getSelectedHeaderCells()).thenReturn(Collections.emptyList()); when(scenarioGridModelMock.getSelectedCellsOrigin()).thenReturn(selectedCell); handler.perform(scenarioGridMock, false, false); verify(scenarioContextMenuRegistry, times(1)).manageRightClick(eq(scenarioGridMock), eq(0), eq(0), anyInt(), anyInt(), eq(false)); }
@Test public void perform_CellsSelected() { when(scenarioGridModelMock.getSelectedCells()).thenReturn(Arrays.asList(selectedCell, selectedCell2)); when(scenarioGridModelMock.getSelectedHeaderCells()).thenReturn(Collections.emptyList()); when(scenarioGridModelMock.getSelectedCellsOrigin()).thenReturn(selectedCell); assertFalse(handler.perform(scenarioGridMock, false, false)); verify(scenarioContextMenuRegistry, never()).manageRightClick(any(), anyInt(), anyInt(), anyInt(), anyInt(), anyBoolean()); }
@Test public void perform_HeaderCellSelected() { when(scenarioGridModelMock.getSelectedCells()).thenReturn(Collections.emptyList()); when(scenarioGridModelMock.getSelectedHeaderCells()).thenReturn(Arrays.asList(selectedCell)); handler.perform(scenarioGridMock, false, false); verify(scenarioContextMenuRegistry, times(1)).manageRightClick(eq(scenarioGridMock), eq(0), eq(0), anyInt(), anyInt(), eq(true)); }
@Test public void perform_HeaderCellsSelected() { when(scenarioGridModelMock.getSelectedCells()).thenReturn(Collections.emptyList()); when(scenarioGridModelMock.getSelectedHeaderCells()).thenReturn(Arrays.asList(selectedCell, selectedCell2)); handler.perform(scenarioGridMock, false, false); verify(scenarioContextMenuRegistry, times(1)).manageRightClick(eq(scenarioGridMock), eq(0), eq(0), anyInt(), anyInt(), eq(true)); }
@Test public void perform_CellAndHeaderCellsSelected() { when(scenarioGridModelMock.getSelectedCells()).thenReturn(Arrays.asList(selectedCell)); when(scenarioGridModelMock.getSelectedHeaderCells()).thenReturn(Arrays.asList(selectedCell2)); assertFalse(handler.perform(scenarioGridMock, false, false)); verify(scenarioContextMenuRegistry, never()).manageRightClick(any(), anyInt(), anyInt(), anyInt(), anyInt(), anyBoolean()); }