示例#1
0
  /** Bug 301682 */
  public void testSetColumnWidthsRelative() {
    final ITableRidget ridget = createRidget();
    final Table table = createWidget(getShell());
    ridget.setUIControl(table);

    final String[] columns3 = {
      Person.PROPERTY_FIRSTNAME, Person.PROPERTY_LASTNAME, Person.PROPERTY_BIRTHDAY
    };
    ridget.bindToModel(manager, "persons", Person.class, columns3, null); // $NON-NLS-1$
    ridget.updateFromModel();

    ridget.setColumnWidths(
        new Object[] {
          new ColumnWeightData(1, 1, true),
          new ColumnWeightData(2, 1, true),
          new ColumnWeightData(3, 1, true)
        });

    assertTrue(
        "column 0 should be smaller than column 1",
        table.getColumn(0).getWidth() < table.getColumn(1).getWidth()); // $NON-NLS-1$
    assertTrue(
        "column 1 should be smaller than column 2",
        table.getColumn(1).getWidth() < table.getColumn(2).getWidth()); // $NON-NLS-1$
  }
示例#2
0
  /** As per bug 301182 */
  public void testRefresh() {
    final ITableRidget ridget = createRidget();
    final Table control = createWidget(getShell());
    ridget.setUIControl(control);

    final StringPojo word1 = new StringPojo("eclipse"); // $NON-NLS-1$
    final StringPojo word2 = new StringPojo("riena"); // $NON-NLS-1$
    final WritableList values = new WritableList(Arrays.asList(word1, word2), StringPojo.class);
    final String[] columns = {"value"}; // $NON-NLS-1$
    ridget.bindToModel(values, StringPojo.class, columns, null);
    ridget.updateFromModel();

    assertEquals("eclipse", control.getItem(0).getText()); // $NON-NLS-1$
    assertEquals("riena", control.getItem(1).getText()); // $NON-NLS-1$

    word1.setValue("alpha"); // $NON-NLS-1$
    word2.setValue("beta"); // $NON-NLS-1$

    assertEquals("eclipse", control.getItem(0).getText()); // $NON-NLS-1$
    assertEquals("riena", control.getItem(1).getText()); // $NON-NLS-1$

    ridget.refresh(word1);

    assertEquals("alpha", control.getItem(0).getText()); // $NON-NLS-1$
    assertEquals("riena", control.getItem(1).getText()); // $NON-NLS-1$
  }
示例#3
0
  /** As per Bug 295305 */
  public void testSetColumnWidths() {
    final ITableRidget ridget = createRidget();
    final Table control = new Table(getShell(), SWT.FULL_SELECTION | SWT.SINGLE);
    ridget.setUIControl(control);

    try {
      ridget.setColumnWidths(new Object[] {null});
      fail();
    } catch (final RuntimeException rex) {
      assertTrue(rex.getMessage().contains("null")); // $NON-NLS-1$
    }

    try {
      ridget.setColumnWidths(new Object[] {new Object()});
      fail();
    } catch (final RuntimeException rex) {
      assertTrue(rex.getMessage().contains("Object")); // $NON-NLS-1$
    }

    ridget.setColumnWidths(
        new Object[] {new ColumnPixelData(20), new ColumnPixelData(40), new ColumnPixelData(60)});
    final String[] columns3 = {
      Person.PROPERTY_FIRSTNAME, Person.PROPERTY_LASTNAME, Person.PROPERTY_BIRTHDAY
    };
    ridget.bindToModel(manager, "persons", Person.class, columns3, null); // $NON-NLS-1$

    final int[] expected = {20, 40, 60};
    for (int i = 0; i < 3; i++) {
      final int actual = control.getColumn(i).getWidth();
      final String msg =
          String.format("col #%d, exp:%d, act:%d", i, expected[i], actual); // $NON-NLS-1$
      assertEquals(msg, expected[i], actual);
    }
  }
示例#4
0
  @Override
  public void configureRidgets() {
    super.configureRidgets();
    final ITableRidget emails = getRidget(ITableRidget.class, "emailsTable"); // $NON-NLS-1$

    final String[] columnHeaders = {
      "From", "Subject", "Date"
    }; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
    final String[] columnPropertyNames = {
      "emailFrom", "emailSubject", "emailDate"
    }; //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
    emails.bindToModel(
        emailsResult, "emails", Email.class, columnPropertyNames, columnHeaders); // $NON-NLS-1$

    emails.setColumnFormatter(
        2,
        new DateColumnFormatter("dd.MMM. HH:mm") { // $NON-NLS-1$
          @Override
          protected Date getDate(final Object element) {
            return ((Email) element).getEmailDate();
          }
        });

    final List<Email> inboxEmailList = mailDemoService.showEmailsList("Inbox"); // $NON-NLS-1$

    emailsResult.setEmails(inboxEmailList);
    getRidget(ITableRidget.class, "emailsTable").updateFromModel(); // $NON-NLS-1$
  }
示例#5
0
  /** As per Bug 295305 */
  public void testAutoCreateTableColumns() {
    final ITableRidget ridget = createRidget();
    final Table control = new Table(getShell(), SWT.FULL_SELECTION | SWT.SINGLE);
    ridget.setUIControl(control);

    assertEquals(0, control.getColumnCount());

    final String[] columns3 = {
      Person.PROPERTY_FIRSTNAME, Person.PROPERTY_LASTNAME, Person.PROPERTY_BIRTHDAY
    };
    ridget.bindToModel(manager, "persons", Person.class, columns3, null); // $NON-NLS-1$

    assertEquals(3, control.getColumnCount());

    final String[] columns1 = {Person.PROPERTY_FIRSTNAME};
    ridget.bindToModel(manager, "persons", Person.class, columns1, null); // $NON-NLS-1$

    assertEquals(1, control.getColumnCount());
  }
示例#6
0
  public void testTableColumnsWithNullHeaderEntry() {
    final ITableRidget ridget = getRidget();
    final Table control = getWidget();

    control.getColumn(0).setText("foo"); // $NON-NLS-1$
    control.getColumn(1).setText("bar"); // $NON-NLS-1$

    final String[] properties1 =
        new String[] {"firstname", "lastname"}; // $NON-NLS-1$ //$NON-NLS-2$
    final String[] headers = new String[] {"First Name", null}; // $NON-NLS-1$
    ridget.bindToModel(manager, "persons", Person.class, properties1, headers); // $NON-NLS-1$

    assertEquals("First Name", control.getColumn(0).getText()); // $NON-NLS-1$
    assertEquals("", control.getColumn(1).getText()); // $NON-NLS-1$
  }
示例#7
0
  public void testTableColumnsWithNullHeader() {
    final ITableRidget ridget = getRidget();
    final Table control = getWidget();

    control.setHeaderVisible(true);
    control.getColumn(0).setText("foo"); // $NON-NLS-1$
    control.getColumn(1).setText("bar"); // $NON-NLS-1$

    final String[] properties1 =
        new String[] {"firstname", "lastname"}; // $NON-NLS-1$ //$NON-NLS-2$
    // null should hide the headers
    ridget.bindToModel(manager, "persons", Person.class, properties1, null); // $NON-NLS-1$

    assertFalse(control.getHeaderVisible());
  }
示例#8
0
  /** As per Bug 295305 */
  public void testAutoCreateColumnsWithNoLayout() {
    final ITableRidget ridget = createRidget();
    final Table control = new Table(getShell(), SWT.FULL_SELECTION | SWT.SINGLE);
    ridget.setUIControl(control);

    getShell().setLayout(null);
    control.setSize(300, 100);
    final String[] columns3 = {
      Person.PROPERTY_FIRSTNAME, Person.PROPERTY_LASTNAME, Person.PROPERTY_BIRTHDAY
    };
    ridget.bindToModel(manager, "persons", Person.class, columns3, null); // $NON-NLS-1$

    assertEquals(null, control.getParent().getLayout());
    assertEquals(null, control.getLayout());

    TestUtils.assertColumnWidths(control, 3);
  }
示例#9
0
  /** As per Bug 295305 */
  public void testAutoCreateColumnsWithTableColumnLayout() {
    final ITableRidget ridget = createRidget();
    for (final Control control : getShell().getChildren()) {
      control.dispose();
    }
    final Table control = new Table(getShell(), SWT.FULL_SELECTION | SWT.SINGLE);
    ridget.setUIControl(control);
    getShell().setLayout(new TableColumnLayout());

    final String[] columns3 = {
      Person.PROPERTY_FIRSTNAME, Person.PROPERTY_LASTNAME, Person.PROPERTY_BIRTHDAY
    };
    ridget.bindToModel(manager, "persons", Person.class, columns3, null); // $NON-NLS-1$

    assertTrue(control.getParent().getLayout() instanceof TableColumnLayout);
    assertEquals(null, control.getLayout());

    TestUtils.assertColumnWidths(control, 3);
  }
示例#10
0
  /** As per Bug 295305 */
  public void testAutoCreateColumnsWithTableLayout() {
    final ITableRidget ridget = createRidget();
    final Table control = new Table(getShell(), SWT.FULL_SELECTION | SWT.SINGLE);
    control.setLayout(new TableLayout());
    ridget.setUIControl(control);

    final String[] columns3 = {
      Person.PROPERTY_FIRSTNAME, Person.PROPERTY_LASTNAME, Person.PROPERTY_BIRTHDAY
    };
    ridget.bindToModel(manager, "persons", Person.class, columns3, null); // $NON-NLS-1$

    final Class<?> shellLayout = getShell().getLayout().getClass();
    assertSame(shellLayout, control.getParent().getLayout().getClass());
    assertTrue(control.getLayout() instanceof TableLayout);

    //		int totalWidthOfColumns = 0;
    //		for (int i = 0; i < 3; i++) {
    //			totalWidthOfColumns += control.getColumn(i).getWidth();
    //		}
    TestUtils.assertColumnWidths(control, 3);
  }
示例#11
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());
  }
示例#12
0
  public void testContainsOption() {
    final ITableRidget ridget = getRidget();

    assertTrue(ridget.containsOption(person1));
    assertTrue(ridget.containsOption(person2));
    assertTrue(ridget.containsOption(person3));

    assertFalse(ridget.containsOption(null));
    assertFalse(ridget.containsOption(new Person("", ""))); // $NON-NLS-1$ //$NON-NLS-2$

    final java.util.List<Person> persons = Arrays.asList(new Person[] {person3});
    final PersonManager manager = new PersonManager(persons);
    ridget.bindToModel(
        manager,
        "persons",
        Person.class,
        new String[] {"firstname", "lastname"},
        null); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    ridget.updateFromModel();

    assertFalse(ridget.containsOption(person1));
    assertTrue(ridget.containsOption(person3));
  }
示例#13
0
  /** As per Bug 295305 */
  public void testPreserveColumnWidths() {
    final int[] widths = {50, 100, 150};
    final ITableRidget ridget = createRidget();
    final Table control = new Table(getShell(), SWT.FULL_SELECTION | SWT.SINGLE);
    for (final int width : widths) {
      final TableColumn column = new TableColumn(control, SWT.NONE);
      column.setWidth(width);
    }
    ridget.setUIControl(control);

    final String[] columns3 = {
      Person.PROPERTY_FIRSTNAME, Person.PROPERTY_LASTNAME, Person.PROPERTY_BIRTHDAY
    };
    ridget.bindToModel(manager, "persons", Person.class, columns3, null); // $NON-NLS-1$
    ridget.updateFromModel();

    for (int i = 0; i < 3; i++) {
      final int actual = control.getColumn(i).getWidth();
      final String msg =
          String.format("col #%d, exp:%d, act:%d", i, widths[i], actual); // $NON-NLS-1$
      assertEquals(msg, widths[i], actual);
    }
  }