Пример #1
0
  public void testSetColumnFormatter() {
    final TableRidget ridget = getRidget();
    final Table table = getWidget();
    final IColumnFormatter formatter =
        new ColumnFormatter() {
          @Override
          public String getText(final Object element) {
            final Person person = (Person) element;
            return person.getLastname().toUpperCase();
          }
        };
    final String lastName = person1.getLastname();
    final String lastNameUpperCase = lastName.toUpperCase();

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

    try {
      ridget.setColumnFormatter(99, formatter);
      fail();
    } catch (final RuntimeException rex) {
      ok();
    }

    ridget.setColumnFormatter(1, formatter);

    assertEquals(lastName, table.getItem(0).getText(1));

    ridget.updateFromModel();

    assertEquals(lastNameUpperCase, table.getItem(0).getText(1));

    ridget.setColumnFormatter(1, null);

    assertEquals(lastNameUpperCase, table.getItem(0).getText(1));

    ridget.updateFromModel();

    assertEquals(lastName, table.getItem(0).getText(1));
  }
Пример #2
0
  @Override
  public void testAddClickListener() {
    final TableRidget ridget = getRidget();
    ridget.updateFromModel();
    final Table control = getWidget();
    control.getColumn(0).setWidth(100);
    control.getColumn(1).setWidth(100);

    try {
      ridget.addClickListener(null);
      fail();
    } catch (final RuntimeException npe) {
      ok();
    }

    final FTClickListener listener1 = new FTClickListener();
    ridget.addClickListener(listener1);

    final FTClickListener listener2 = new FTClickListener();
    ridget.addClickListener(listener2);
    ridget.addClickListener(listener2);

    final Event mdEvent = new Event();
    mdEvent.widget = control;
    mdEvent.type = SWT.MouseDown;
    mdEvent.button = 2;
    final TableItem row2 = control.getItem(2);
    mdEvent.item = row2;
    mdEvent.x = row2.getBounds().x + 1;
    mdEvent.y = row2.getBounds().y + 1;
    control.notifyListeners(SWT.MouseDown, mdEvent);

    assertEquals(0, listener1.getCount());
    assertEquals(0, listener2.getCount());

    mdEvent.type = SWT.MouseUp;
    control.notifyListeners(SWT.MouseUp, mdEvent);

    assertEquals(1, listener1.getCount());
    assertEquals(1, listener2.getCount());

    final ClickEvent event = listener2.getEvent();
    assertEquals(ridget, event.getSource());
    assertEquals(2, event.getButton());
    assertEquals(0, event.getColumnIndex());
    assertEquals(row2.getData(), event.getRow());

    ridget.removeClickListener(listener1);

    mdEvent.type = SWT.MouseDown;
    control.notifyListeners(SWT.MouseDown, mdEvent);
    mdEvent.type = SWT.MouseUp;
    control.notifyListeners(SWT.MouseUp, mdEvent);

    assertEquals(1, listener1.getCount());
  }
Пример #3
0
  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());
  }