Example #1
0
  /**
   * 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 TableRidget ridget = getRidget();
    final Table 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());
  }
Example #2
0
  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);
  }