public static void main(final String[] args) { final Display display = Display.getDefault(); final Shell shell = new Shell(display); shell.setText(SnippetMasterDetailsRidget003.class.getSimpleName()); shell.setLayout(new FillLayout()); final PersonMasterDetails details = new PersonMasterDetails(shell, SWT.NONE); final IMasterDetailsRidget ridget = (IMasterDetailsRidget) SwtRidgetFactory.createRidget(details); ridget.setDelegate(new PersonDelegate()); final WritableList input = new WritableList(PersonFactory.createPersonList(), Person.class); final String[] properties = {Person.PROPERTY_LASTNAME, Person.PROPERTY_FIRSTNAME}; final String[] headers = {"Last Name", "First Name"}; // $NON-NLS-1$ //$NON-NLS-2$ ridget.bindToModel(input, Person.class, properties, headers); ridget.updateFromModel(); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
@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(); } }); }