コード例 #1
0
ファイル: TableRidgetTest.java プロジェクト: jodoming/riena
  public void testSetSortedColumnFiresEvents() {
    final TableRidget ridget = getRidget();

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

    expectPropertyChangeEvents(
        new PropertyChangeEvent(
            ridget,
            ISortableByColumn.PROPERTY_SORTED_COLUMN,
            Integer.valueOf(-1),
            Integer.valueOf(0)));

    ridget.setSortedColumn(0);

    verifyPropertyChangeEvents();
    expectNoPropertyChangeEvent();

    ridget.setSortedColumn(0);

    verifyPropertyChangeEvents();
    expectPropertyChangeEvents(
        new PropertyChangeEvent(
            ridget,
            ISortableByColumn.PROPERTY_SORTED_COLUMN,
            Integer.valueOf(0),
            Integer.valueOf(1)));

    ridget.setSortedColumn(1);

    verifyPropertyChangeEvents();
  }
コード例 #2
0
ファイル: TableRidgetTest.java プロジェクト: jodoming/riena
  public void testSetComparator() {
    final TableRidget ridget = getRidget();
    final Table control = getWidget();

    // sorts from a to z
    final Comparator<Object> comparator = new TypedComparator<String>();

    try {
      ridget.setComparator(-1, comparator);
      fail();
    } catch (final RuntimeException rex) {
      ok();
    }

    try {
      ridget.setComparator(2, comparator);
      fail();
    } catch (final RuntimeException rex) {
      ok();
    }

    ridget.setSortedAscending(true);

    final int lastItemIndex = control.getItemCount() - 1;

    assertEquals("John", control.getItem(0).getText(0)); // $NON-NLS-1$
    assertEquals("Frank", control.getItem(lastItemIndex).getText(0)); // $NON-NLS-1$

    ridget.setComparator(0, comparator);

    assertEquals("John", control.getItem(0).getText(0)); // $NON-NLS-1$
    assertEquals("Frank", control.getItem(lastItemIndex).getText(0)); // $NON-NLS-1$

    ridget.setSortedColumn(0);

    assertEquals("Frank", control.getItem(0).getText(0)); // $NON-NLS-1$
    assertEquals("John", control.getItem(lastItemIndex).getText(0)); // $NON-NLS-1$

    ridget.setComparator(0, null);

    assertEquals("John", control.getItem(0).getText(0)); // $NON-NLS-1$
    assertEquals("Frank", control.getItem(lastItemIndex).getText(0)); // $NON-NLS-1$

    ridget.setComparator(1, comparator);
    ridget.setSortedColumn(1);

    assertEquals("Doe", control.getItem(0).getText(1)); // $NON-NLS-1$
    assertEquals("Zappa", control.getItem(lastItemIndex).getText(1)); // $NON-NLS-1$

    ridget.setSortedAscending(false);

    assertEquals("Zappa", control.getItem(0).getText(1)); // $NON-NLS-1$
    assertEquals("Doe", control.getItem(lastItemIndex).getText(1)); // $NON-NLS-1$
  }
コード例 #3
0
ファイル: TableRidgetTest.java プロジェクト: jodoming/riena
  public void testGetSortedColumn() {
    final TableRidget ridget = getRidget();

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

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

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

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

    ridget.setSortedColumn(0);

    assertEquals(0, ridget.getSortedColumn());

    ridget.setComparator(0, null);

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

    ridget.setComparator(1, new TypedComparator<String>());
    ridget.setSortedColumn(1);

    assertEquals(1, ridget.getSortedColumn());

    ridget.setSortedColumn(-1);

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

    // no comparator in column 0
    ridget.setSortedColumn(0);

    assertEquals(-1, ridget.getSortedColumn());
  }
コード例 #4
0
ファイル: TableRidgetTest.java プロジェクト: jodoming/riena
  public void testSetSortedAscending() {
    final Table control = getWidget();
    final TableRidget ridget = getRidget();

    ridget.bindToModel(
        manager,
        "persons",
        Person.class,
        new String[] {"lastname", "firstname"},
        null); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    ridget.updateFromModel();
    final int lastItemIndex = control.getItemCount() - 1;

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

    ridget.setComparator(0, new TypedComparator<String>());
    ridget.setSortedColumn(0);

    assertTrue(ridget.isSortedAscending());
    assertEquals("Doe", control.getItem(0).getText(0)); // $NON-NLS-1$
    assertEquals("Zappa", control.getItem(lastItemIndex).getText(0)); // $NON-NLS-1$

    ridget.setSortedAscending(false);

    assertFalse(ridget.isSortedAscending());
    assertEquals("Zappa", control.getItem(0).getText(0)); // $NON-NLS-1$
    assertEquals("Doe", control.getItem(lastItemIndex).getText(0)); // $NON-NLS-1$

    ridget.setSortedAscending(true);

    assertTrue(ridget.isSortedAscending());
    assertEquals("Doe", control.getItem(0).getText(0)); // $NON-NLS-1$
    assertEquals("Zappa", control.getItem(lastItemIndex).getText(0)); // $NON-NLS-1$

    ridget.setComparator(0, null);

    assertEquals(-1, ridget.getSortedColumn());
    assertFalse(ridget.isSortedAscending());
  }
コード例 #5
0
ファイル: TableRidgetTest.java プロジェクト: jodoming/riena
  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());
  }