Пример #1
0
  public void testUpdateFromModel() {
    final ITableRidget ridget = getRidget();
    final Grid control = getWidget();
    final List<ChangeEvent> changeEvents = new ArrayList<ChangeEvent>();
    final IChangeListener listener =
        new IChangeListener() {
          public void handleChange(final ChangeEvent event) {
            changeEvents.add(event);
          }
        };
    ridget.getObservableList().addChangeListener(listener);

    final int oldCount = manager.getPersons().size();

    assertEquals(oldCount, ridget.getObservableList().size());
    assertEquals(oldCount, control.getItemCount());

    manager.getPersons().remove(person1);

    final int newCount = oldCount - 1;

    assertEquals(newCount, manager.getPersons().size());
    assertEquals(oldCount, ridget.getObservableList().size());
    assertEquals(oldCount, control.getItemCount());
    assertEquals(0, changeEvents.size());

    ridget.updateFromModel();

    assertEquals(newCount, manager.getPersons().size());
    assertEquals(newCount, ridget.getObservableList().size());
    assertEquals(newCount, control.getItemCount());
    // TODO [ev] discuss with team
    //		assertEquals(1, changeEvents.size());
    assertEquals(0, changeEvents.size());
  }
Пример #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$
  }
Пример #3
0
  public void testBindToModel() {
    final Grid control = getWidget();

    assertEquals(manager.getPersons().size(), control.getItemCount());
    assertEquals(person1.getFirstname(), control.getItem(0).getText(0));
    assertEquals(person2.getFirstname(), control.getItem(1).getText(0));
    assertEquals(person3.getFirstname(), control.getItem(2).getText(0));

    assertEquals(person1.getLastname(), control.getItem(0).getText(1));
    assertEquals(person2.getLastname(), control.getItem(1).getText(1));
    assertEquals(person3.getLastname(), control.getItem(2).getText(1));
  }
Пример #4
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());
  }