예제 #1
0
  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);
  }
예제 #2
0
  /** Tests that toggling output state on/off does not change the selection. */
  public void testTogglingOutputDoesNotChangeSelection() {
    final ITableRidget 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());
  }
예제 #3
0
  public void testSetSelectionType() {
    final ITableRidget ridget = getRidget();
    final Table 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());
  }
예제 #4
0
  public void testUpdateFromModelRemovesSelection() {
    final ITableRidget ridget = getRidget();

    ridget.setSelection(person2);

    assertSame(person2, ridget.getSelection().get(0));

    manager.getPersons().remove(person2);
    ridget.updateFromModel();

    assertTrue(ridget.getSelection().isEmpty());
  }
예제 #5
0
  public void testSetSelectionWithSorting() {
    final ITableRidget ridget = getRidget();

    assertEquals(-1, ridget.getSelectionIndex());
    assertTrue(ridget.getSelection().isEmpty());

    ridget.setSelection(0);

    assertEquals(0, ridget.getSelectionIndex());
    assertEquals(person1, ridget.getSelection().get(0));

    ridget.setComparator(1, new StringComparator());
    ridget.setSortedColumn(1); // sort by last name
    ridget.setSortedAscending(false);

    final int last = ridget.getOptionCount() - 1;
    assertEquals(last, ridget.getSelectionIndex());
    assertEquals(person1, ridget.getSelection().get(0));

    ridget.setSortedAscending(true);

    assertEquals(0, ridget.getSelectionIndex());
    assertEquals(person1, ridget.getSelection().get(0));
  }