示例#1
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$
  }
示例#2
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));
  }
  @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();
          }
        });
  }