/** * Tests that for multiple selection, the ridget selection state and the ui selection state cannot * be changed by the user when ridget is set to "output only". */ public void testOutputMultipleSelectionCannotBeChangedFromUI() { final ITableRidget ridget = getRidget(); final Grid control = getWidget(); ridget.setSelectionType(SelectionType.MULTI); assertEquals(0, ridget.getSelection().size()); assertEquals(0, control.getSelectionCount()); ridget.setOutputOnly(true); control.setFocus(); // move down and up to select row 0; space does not select in tables UITestHelper.sendKeyAction(control.getDisplay(), UITestHelper.KC_ARROW_DOWN); UITestHelper.sendKeyAction(control.getDisplay(), UITestHelper.KC_ARROW_UP); assertEquals(0, ridget.getSelection().size()); assertEquals(0, control.getSelectionCount()); ridget.setOutputOnly(false); control.setFocus(); // move down and up to select row 0; space does not select in tables UITestHelper.sendKeyAction(control.getDisplay(), UITestHelper.KC_ARROW_DOWN); UITestHelper.sendKeyAction(control.getDisplay(), UITestHelper.KC_ARROW_UP); assertEquals(1, ridget.getSelection().size()); assertEquals(1, control.getSelectionCount()); }
public void testAddSelectionListener() { final ITableRidget ridget = getRidget(); final Grid control = getWidget(); try { ridget.addSelectionListener(null); fail(); } catch (final RuntimeException npe) { ok(); } final TestSelectionListener selectionListener = new TestSelectionListener(); ridget.addSelectionListener(selectionListener); ridget.setSelection(person1); assertEquals(1, selectionListener.getCount()); ridget.removeSelectionListener(selectionListener); ridget.setSelection(person2); assertEquals(1, selectionListener.getCount()); ridget.clearSelection(); ridget.addSelectionListener(selectionListener); ridget.setSelectionType(SelectionType.SINGLE); assertEquals(0, ridget.getSelection().size()); assertEquals(0, control.getSelectionCount()); control.setFocus(); UITestHelper.sendKeyAction(control.getDisplay(), UITestHelper.KC_ARROW_DOWN); assertEquals(1, ridget.getSelection().size()); assertEquals(1, control.getSelectionCount()); assertEquals(2, selectionListener.getCount()); final SelectionEvent selectionEvent = selectionListener.getSelectionEvent(); assertEquals(ridget, selectionEvent.getSource()); assertTrue(selectionEvent.getOldSelection().isEmpty()); assertEquals(ridget.getSelection(), selectionEvent.getNewSelection()); // System.out.println("SelectionEvent: " + selectionListener.getSelectionEvent()); UITestHelper.sendKeyAction(control.getDisplay(), UITestHelper.KC_ARROW_DOWN); assertEquals(1, ridget.getSelection().size()); assertEquals(1, control.getSelectionCount()); assertEquals(3, selectionListener.getCount()); final SelectionEvent selectionEvent2 = selectionListener.getSelectionEvent(); assertEquals(ridget, selectionEvent.getSource()); assertEquals(selectionEvent.getNewSelection(), selectionEvent2.getOldSelection()); assertEquals(ridget.getSelection(), selectionEvent2.getNewSelection()); // System.out.println("SelectionEvent: " + selectionListener.getSelectionEvent()); ridget.removeSelectionListener(selectionListener); }
public void testSetSelectionType() { final ITableRidget ridget = getRidget(); final Grid control = getWidget(); assertEquals(SelectionType.SINGLE, ridget.getSelectionType()); assertTrue((control.getStyle() & SWT.MULTI) != 0); ridget.setSelection(new int[] {0, 1}); // single selection is enforced assertEquals(1, ridget.getSelectionIndices().length); assertEquals(1, control.getSelectionCount()); // multiple selection is now allowed ridget.setSelectionType(SelectionType.MULTI); ridget.setSelection(new int[] {0, 1}); assertEquals(2, ridget.getSelectionIndices().length); assertEquals(2, control.getSelectionCount()); }
@Override protected final int getUiSelectionCount() { final Grid control = getUIControl(); return control == null ? -1 : control.getSelectionCount(); }