示例#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
  /** 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);
  }
示例#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
  /** 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);
  }
示例#7
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);
  }
示例#8
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);
    }
  }