예제 #1
0
  public void testSetColumnSortabilityFiresEvents() {
    final TableRidget ridget = getRidget();

    expectNoPropertyChangeEvent();

    ridget.setColumnSortable(0, true);

    verifyPropertyChangeEvents();
    expectPropertyChangeEvents(
        new PropertyChangeEvent(
            ridget, ISortableByColumn.PROPERTY_COLUMN_SORTABILITY, null, Integer.valueOf(0)));

    ridget.setColumnSortable(0, false);

    verifyPropertyChangeEvents();
    expectNoPropertyChangeEvent();

    ridget.setColumnSortable(0, false);

    verifyPropertyChangeEvents();
    expectPropertyChangeEvents(
        new PropertyChangeEvent(
            ridget, ISortableByColumn.PROPERTY_COLUMN_SORTABILITY, null, Integer.valueOf(0)));

    ridget.setColumnSortable(0, true);

    verifyPropertyChangeEvents();
    expectNoPropertyChangeEvent();

    ridget.setColumnSortable(0, true);

    verifyPropertyChangeEvents();
  }
예제 #2
0
  public void testIsColumnSortable() {
    final TableRidget ridget = getRidget();

    try {
      assertFalse(ridget.isColumnSortable(-1));
      fail();
    } catch (final RuntimeException rex) {
      ok();
    }

    try {
      assertFalse(ridget.isColumnSortable(2));
      fail();
    } catch (final RuntimeException rex) {
      ok();
    }

    for (int i = 0; i < 2; i++) {
      assertFalse(ridget.isColumnSortable(i));

      // columns are sortable by default, when they have a comparator
      ridget.setComparator(i, new TypedComparator<String>());

      assertTrue(ridget.isColumnSortable(i));

      ridget.setColumnSortable(i, false);

      assertFalse(ridget.isColumnSortable(i));

      ridget.setColumnSortable(i, true);

      assertTrue(ridget.isColumnSortable(i));

      // columns are not sortable without a comparator
      ridget.setComparator(i, null);

      assertFalse(ridget.isColumnSortable(i));
    }
  }
예제 #3
0
  public void testColumnHeaderChangesSortability() {
    final TableRidget ridget = getRidget();
    final Table table = getWidget();

    ridget.setColumnSortable(0, true);
    ridget.setComparator(0, new TypedComparator<String>());
    ridget.setColumnSortable(1, true);
    ridget.setComparator(1, new TypedComparator<String>());

    ridget.setSortedColumn(-1);

    assertEquals(-1, ridget.getSortedColumn());
    assertFalse(ridget.isSortedAscending());

    final Event e = new Event();
    e.type = SWT.Selection;
    e.widget = table.getColumn(0);
    e.widget.notifyListeners(SWT.Selection, e);

    assertEquals(0, ridget.getSortedColumn());
    assertTrue(ridget.isSortedAscending());

    e.widget.notifyListeners(SWT.Selection, e);

    assertEquals(0, ridget.getSortedColumn());
    assertFalse(ridget.isSortedAscending());

    e.widget.notifyListeners(SWT.Selection, e);

    assertEquals(-1, ridget.getSortedColumn());
    assertFalse(ridget.isSortedAscending());

    e.widget.notifyListeners(SWT.Selection, e);

    assertEquals(0, ridget.getSortedColumn());
    assertTrue(ridget.isSortedAscending());
  }