Ejemplo n.º 1
0
  /** Tests the method {@code clearColumnFormatters()}. */
  public void testClearColumnFormatters() {

    final TableRidget ridget = getRidget();
    final IColumnFormatter formatter =
        new ColumnFormatter() {
          @Override
          public String getText(final Object element) {
            return "dummy"; //$NON-NLS-1$
          }
        };

    ridget.setColumnFormatter(1, formatter);

    IColumnFormatter[] retFormatters =
        ReflectionUtils.invokeHidden(
            ridget, "getColumnFormatters", ridget.getColumnCount()); // $NON-NLS-1$
    assertNotNull(retFormatters);
    assertEquals(ridget.getColumnCount(), retFormatters.length);
    assertNull(retFormatters[0]);
    assertNotNull(retFormatters[1]);
    assertSame(formatter, retFormatters[1]);

    ridget.clearColumnFormatters();
    retFormatters =
        ReflectionUtils.invokeHidden(
            ridget, "getColumnFormatters", ridget.getColumnCount()); // $NON-NLS-1$
    assertNotNull(retFormatters);
    assertEquals(ridget.getColumnCount(), retFormatters.length);
    assertNull(retFormatters[0]);
    assertNull(retFormatters[1]);
  }
Ejemplo n.º 2
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));
  }