Ejemplo n.º 1
0
  public void testSetSortedColumnFiresEvents() {
    final ITableRidget 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();
  }
Ejemplo n.º 2
0
  public void testSetComparator() {
    final ITableRidget ridget = getRidget();
    final Grid 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$
  }
Ejemplo n.º 3
0
  public void testGetSortedColumn() {
    final ITableRidget 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());
  }
Ejemplo n.º 4
0
  public void testGetOptionWithSorting() {
    final ITableRidget ridget = getRidget();

    assertEquals(0, ridget.indexOfOption(person1));
    assertEquals(person1, ridget.getOption(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.indexOfOption(person1));
    assertEquals(person1, ridget.getOption(last));

    ridget.setSortedAscending(true);

    assertEquals(0, ridget.indexOfOption(person1));
    assertEquals(person1, ridget.getOption(0));
  }
Ejemplo n.º 5
0
  public void testSetSortedAscending() {
    final Grid control = getWidget();
    final ITableRidget 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());
  }
Ejemplo n.º 6
0
  public void testColumnHeaderChangesSortability() {
    final ITableRidget ridget = getRidget();
    final Grid 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());
  }
Ejemplo n.º 7
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));
  }