public void testAddSelectionListener() { final TableRidget ridget = getRidget(); final Table 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); }
/** Tests that toggling output state on/off does not change the selection. */ public void testTogglingOutputDoesNotChangeSelection() { final TableRidget ridget = getRidget(); ridget.setSelection(0); assertEquals(0, ridget.getSelectionIndex()); ridget.setOutputOnly(true); assertEquals(0, ridget.getSelectionIndex()); ridget.setSelection((Object) null); assertEquals(-1, ridget.getSelectionIndex()); ridget.setOutputOnly(false); assertEquals(-1, ridget.getSelectionIndex()); }