Beispiel #1
0
  public void testSetSortedColumnFiresEvents() {
    final ITableRidget ridget = getRidget();

    assertEquals(-1, ridget.getSortedColumn());

    expectPropertyChangeEvents(
        new PropertyChangeEvent(
            ridget,
            ISortableByColumn.PROPERTY_SORTED_COLUMN,
            Integer.valueOf(-1),
            Integer.valueOf(0)));

    ridget.setSortedColumn(0);

    verifyPropertyChangeEvents();
    expectNoPropertyChangeEvent();

    ridget.setSortedColumn(0);

    verifyPropertyChangeEvents();
    expectPropertyChangeEvents(
        new PropertyChangeEvent(
            ridget,
            ISortableByColumn.PROPERTY_SORTED_COLUMN,
            Integer.valueOf(0),
            Integer.valueOf(1)));

    ridget.setSortedColumn(1);

    verifyPropertyChangeEvents();
  }
Beispiel #2
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$
  }
  @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$
  }
Beispiel #4
0
  public void testAddDoubleClickListener() {
    final ITableRidget ridget = getRidget();
    final Grid control = getWidget();

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

    final FTActionListener listener1 = new FTActionListener();
    ridget.addDoubleClickListener(listener1);

    final FTActionListener listener2 = new FTActionListener();
    ridget.addDoubleClickListener(listener2);
    ridget.addDoubleClickListener(listener2);

    final Event doubleClick = new Event();
    doubleClick.widget = control;
    doubleClick.type = SWT.MouseDoubleClick;
    control.notifyListeners(SWT.MouseDoubleClick, doubleClick);

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

    ridget.removeDoubleClickListener(listener1);

    control.notifyListeners(SWT.MouseDoubleClick, doubleClick);

    assertEquals(1, listener1.getCount());
  }
Beispiel #5
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$
  }
Beispiel #6
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$
  }
Beispiel #7
0
  public void testUpdateFromModelRemovesSelection() {
    final ITableRidget ridget = getRidget();

    ridget.setSelection(person2);

    assertSame(person2, ridget.getSelection().get(0));

    manager.getPersons().remove(person2);
    ridget.updateFromModel();

    assertTrue(ridget.getSelection().isEmpty());
  }
Beispiel #8
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());
  }
Beispiel #9
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$
  }
Beispiel #10
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);
  }
Beispiel #11
0
  /**
   * Tests that for multiple selection, the ridget selection state and the ui selection state cannot
   * be changed by the user when ridget is set to "output only".
   */
  public void testOutputMultipleSelectionCannotBeChangedFromUI() {
    final ITableRidget ridget = getRidget();
    final Grid control = getWidget();

    ridget.setSelectionType(SelectionType.MULTI);

    assertEquals(0, ridget.getSelection().size());
    assertEquals(0, control.getSelectionCount());

    ridget.setOutputOnly(true);
    control.setFocus();
    // move down and up to select row 0; space does not select in tables
    UITestHelper.sendKeyAction(control.getDisplay(), UITestHelper.KC_ARROW_DOWN);
    UITestHelper.sendKeyAction(control.getDisplay(), UITestHelper.KC_ARROW_UP);

    assertEquals(0, ridget.getSelection().size());
    assertEquals(0, control.getSelectionCount());

    ridget.setOutputOnly(false);
    control.setFocus();
    // move down and up to select row 0; space does not select in tables
    UITestHelper.sendKeyAction(control.getDisplay(), UITestHelper.KC_ARROW_DOWN);
    UITestHelper.sendKeyAction(control.getDisplay(), UITestHelper.KC_ARROW_UP);

    assertEquals(1, ridget.getSelection().size());
    assertEquals(1, control.getSelectionCount());
  }
Beispiel #12
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());
  }
Beispiel #13
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);
  }
Beispiel #14
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);
  }
Beispiel #15
0
  public void testSetSortedAscendingFiresEvents() {
    final ITableRidget ridget = getRidget();

    ridget.setSortedAscending(true);

    expectPropertyChangeEvents(
        new PropertyChangeEvent(
            ridget, ISortableByColumn.PROPERTY_SORT_ASCENDING, Boolean.TRUE, Boolean.FALSE));

    ridget.setSortedAscending(false);

    verifyPropertyChangeEvents();
    expectNoPropertyChangeEvent();

    ridget.setSortedAscending(false);

    verifyPropertyChangeEvents();
    expectPropertyChangeEvents(
        new PropertyChangeEvent(
            ridget, ISortableByColumn.PROPERTY_SORT_ASCENDING, Boolean.FALSE, Boolean.TRUE));

    ridget.setSortedAscending(true);

    verifyPropertyChangeEvents();
    expectNoPropertyChangeEvent();

    ridget.setSortedAscending(true);

    verifyPropertyChangeEvents();
  }
Beispiel #16
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);
    }
  }
Beispiel #17
0
  public void testSetColumnSortabilityFiresEvents() {
    final ITableRidget ridget = getRidget();

    expectNoPropertyChangeEvent();

    ridget.setColumnSortable(0, true);

    verifyPropertyChangeEvents();
    expectPropertyChangeEvents(
        new PropertyChangeEvent(
            ridget, ISortableByColumn.PROPERTY_COLUMN_SORTABILITY, null, Integer.valueOf(0)));

    ridget.setColumnSortable(0, false);

    verifyPropertyChangeEvents();
    expectNoPropertyChangeEvent();

    ridget.setColumnSortable(0, false);

    verifyPropertyChangeEvents();
    expectPropertyChangeEvents(
        new PropertyChangeEvent(
            ridget, ISortableByColumn.PROPERTY_COLUMN_SORTABILITY, null, Integer.valueOf(0)));

    ridget.setColumnSortable(0, true);

    verifyPropertyChangeEvents();
    expectNoPropertyChangeEvent();

    ridget.setColumnSortable(0, true);

    verifyPropertyChangeEvents();
  }
  @Override
  public void configureRidgets() {
    final Customer customer =
        (Customer) getNavigationNode().getParent().getContext("demo.customer"); // $NON-NLS-1$

    final ITextRidget firstName = getRidget(ITextRidget.class, "firstname"); // $NON-NLS-1$
    firstName.bindToModel(customer, "firstName"); // $NON-NLS-1$
    firstName.setMandatory(true);
    final ITextRidget lastName = getRidget(ITextRidget.class, "lastname"); // $NON-NLS-1$
    lastName.setMandatory(true);
    lastName.bindToModel(customer, "lastName"); // $NON-NLS-1$

    final IMasterDetailsRidget master =
        getRidget(IMasterDetailsRidget.class, "contracts"); // $NON-NLS-1$
    master.setDelegate(new ContractDelegate());
    final String[] properties =
        new String[] {
          "contractNo", "contractValue", "status"
        }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    final String[] headers =
        new String[] {
          "ContractNo", "Value in Euro", "Status"
        }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    master.bindToModel(
        new WritableList(customer.getContracts(), Contract.class),
        Contract.class,
        properties,
        headers);

    final ITableRidget table =
        master.getRidget(ITableRidget.class, MasterDetailsComposite.BIND_ID_TABLE);
    table.setColumnFormatter(
        1,
        new NumberColumnFormatter(Double.class, 2) {
          @Override
          protected Number getValue(final Object element) {
            return ((Contract) element).getContractValue();
          }
        });
  }
Beispiel #19
0
  public void testUpdateFromModel() {
    final ITableRidget ridget = getRidget();
    final Table 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());
  }
Beispiel #20
0
  /** Tests that toggling output state on/off does not change the selection. */
  public void testTogglingOutputDoesNotChangeSelection() {
    final ITableRidget ridget = getRidget();

    ridget.setSelection(0);

    assertEquals(0, ridget.getSelectionIndex());

    ridget.setOutputOnly(true);

    assertEquals(0, ridget.getSelectionIndex());

    ridget.setSelection((Object) null);

    assertEquals(-1, ridget.getSelectionIndex());

    ridget.setOutputOnly(false);

    assertEquals(-1, ridget.getSelectionIndex());
  }
Beispiel #21
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);
    }
  }
Beispiel #22
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));
  }
Beispiel #23
0
  public void testSetColumnFormatter() {
    final ITableRidget ridget = getRidget();
    final Grid 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));
  }
Beispiel #24
0
  public void testSetSelectionType() {
    final ITableRidget ridget = getRidget();
    final Table control = getWidget();

    assertEquals(SelectionType.SINGLE, ridget.getSelectionType());
    assertTrue((control.getStyle() & SWT.MULTI) != 0);

    ridget.setSelection(new int[] {0, 1});

    // single selection is enforced
    assertEquals(1, ridget.getSelectionIndices().length);
    assertEquals(1, control.getSelectionCount());

    // multiple selection is now allowed
    ridget.setSelectionType(SelectionType.MULTI);
    ridget.setSelection(new int[] {0, 1});

    assertEquals(2, ridget.getSelectionIndices().length);
    assertEquals(2, control.getSelectionCount());
  }
Beispiel #25
0
  public void testSetMoveableColumns() {
    final ITableRidget ridget = getRidget();
    final Grid table = getWidget();

    assertFalse(ridget.hasMoveableColumns());
    assertFalse(table.getColumn(0).getMoveable());
    assertFalse(table.getColumn(1).getMoveable());

    ridget.setMoveableColumns(true);

    assertTrue(ridget.hasMoveableColumns());
    assertTrue(table.getColumn(0).getMoveable());
    assertTrue(table.getColumn(1).getMoveable());

    ridget.setMoveableColumns(false);

    assertFalse(ridget.hasMoveableColumns());
    assertFalse(table.getColumn(0).getMoveable());
    assertFalse(table.getColumn(1).getMoveable());
  }
Beispiel #26
0
  public void testColumnHeaderChangesSortability() {
    final ITableRidget ridget = getRidget();
    final Grid table = getWidget();

    ridget.setColumnSortable(0, true);
    ridget.setComparator(0, new TypedComparator<String>());
    ridget.setColumnSortable(1, true);
    ridget.setComparator(1, new TypedComparator<String>());

    ridget.setSortedColumn(-1);

    assertEquals(-1, ridget.getSortedColumn());
    assertFalse(ridget.isSortedAscending());

    final Event e = new Event();
    e.type = SWT.Selection;
    e.widget = table.getColumn(0);
    e.widget.notifyListeners(SWT.Selection, e);

    assertEquals(0, ridget.getSortedColumn());
    assertTrue(ridget.isSortedAscending());

    e.widget.notifyListeners(SWT.Selection, e);

    assertEquals(0, ridget.getSortedColumn());
    assertFalse(ridget.isSortedAscending());

    e.widget.notifyListeners(SWT.Selection, e);

    assertEquals(-1, ridget.getSortedColumn());
    assertFalse(ridget.isSortedAscending());

    e.widget.notifyListeners(SWT.Selection, e);

    assertEquals(0, ridget.getSortedColumn());
    assertTrue(ridget.isSortedAscending());
  }
Beispiel #27
0
  public void testAddSelectionListener() {
    final ITableRidget ridget = getRidget();
    final Grid control = getWidget();

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

    final TestSelectionListener selectionListener = new TestSelectionListener();
    ridget.addSelectionListener(selectionListener);

    ridget.setSelection(person1);
    assertEquals(1, selectionListener.getCount());
    ridget.removeSelectionListener(selectionListener);
    ridget.setSelection(person2);
    assertEquals(1, selectionListener.getCount());
    ridget.clearSelection();

    ridget.addSelectionListener(selectionListener);
    ridget.setSelectionType(SelectionType.SINGLE);
    assertEquals(0, ridget.getSelection().size());
    assertEquals(0, control.getSelectionCount());

    control.setFocus();
    UITestHelper.sendKeyAction(control.getDisplay(), UITestHelper.KC_ARROW_DOWN);

    assertEquals(1, ridget.getSelection().size());
    assertEquals(1, control.getSelectionCount());
    assertEquals(2, selectionListener.getCount());
    final SelectionEvent selectionEvent = selectionListener.getSelectionEvent();
    assertEquals(ridget, selectionEvent.getSource());
    assertTrue(selectionEvent.getOldSelection().isEmpty());
    assertEquals(ridget.getSelection(), selectionEvent.getNewSelection());
    // System.out.println("SelectionEvent: " + selectionListener.getSelectionEvent());

    UITestHelper.sendKeyAction(control.getDisplay(), UITestHelper.KC_ARROW_DOWN);

    assertEquals(1, ridget.getSelection().size());
    assertEquals(1, control.getSelectionCount());
    assertEquals(3, selectionListener.getCount());
    final SelectionEvent selectionEvent2 = selectionListener.getSelectionEvent();
    assertEquals(ridget, selectionEvent.getSource());
    assertEquals(selectionEvent.getNewSelection(), selectionEvent2.getOldSelection());
    assertEquals(ridget.getSelection(), selectionEvent2.getNewSelection());
    // System.out.println("SelectionEvent: " + selectionListener.getSelectionEvent());

    ridget.removeSelectionListener(selectionListener);
  }
Beispiel #28
0
  public void testRowErrorMessageMarker() {
    final ITableRidget ridget = getRidget();
    final RowErrorMessageMarker marker1 = new RowErrorMessageMarker(null, person1);
    final RowErrorMessageMarker marker2 = new RowErrorMessageMarker(null, person2);

    assertFalse(ridget.isErrorMarked());

    ridget.addMarker(marker1);
    ridget.addMarker(marker1);

    assertTrue(ridget.isErrorMarked());

    ridget.removeMarker(marker1);

    assertFalse(ridget.isErrorMarked());

    ridget.addMarker(marker1);
    ridget.addMarker(marker2);
    ridget.removeMarker(marker1);

    assertTrue(ridget.isErrorMarked());

    ridget.removeMarker(marker2);

    assertFalse(ridget.isErrorMarked());
  }
Beispiel #29
0
  public void testSetSelectionWithSorting() {
    final ITableRidget ridget = getRidget();

    assertEquals(-1, ridget.getSelectionIndex());
    assertTrue(ridget.getSelection().isEmpty());

    ridget.setSelection(0);

    assertEquals(0, ridget.getSelectionIndex());
    assertEquals(person1, ridget.getSelection().get(0));

    ridget.setComparator(1, new StringComparator());
    ridget.setSortedColumn(1); // sort by last name
    ridget.setSortedAscending(false);

    final int last = ridget.getOptionCount() - 1;
    assertEquals(last, ridget.getSelectionIndex());
    assertEquals(person1, ridget.getSelection().get(0));

    ridget.setSortedAscending(true);

    assertEquals(0, ridget.getSelectionIndex());
    assertEquals(person1, ridget.getSelection().get(0));
  }
Beispiel #30
0
  public void testGetOptionWithSorting() {
    final ITableRidget ridget = getRidget();

    assertEquals(0, ridget.indexOfOption(person1));
    assertEquals(person1, ridget.getOption(0));

    ridget.setComparator(1, new StringComparator());
    ridget.setSortedColumn(1); // sort by last name
    ridget.setSortedAscending(false);

    final int last = ridget.getOptionCount() - 1;
    assertEquals(last, ridget.indexOfOption(person1));
    assertEquals(person1, ridget.getOption(last));

    ridget.setSortedAscending(true);

    assertEquals(0, ridget.indexOfOption(person1));
    assertEquals(person1, ridget.getOption(0));
  }