List of usage examples for org.eclipse.jface.internal.databinding.provisional.swt CompositeUpdater CompositeUpdater
public CompositeUpdater(Composite toUpdate, IObservableList<? extends E> model)
From source file:org.eclipse.jface.examples.databinding.snippets.Snippet012CompositeUpdater.java
License:Open Source License
public static void main(String[] args) { final Display display = new Display(); Realm.runWithDefault(DisplayRealm.getRealm(display), () -> { Shell shell = new Shell(display); final WritableList<Counter> list = new WritableList<>(); Button button = new Button(shell, SWT.PUSH); button.setText("add"); button.addSelectionListener(new SelectionAdapter() { @Override//from ww w .j av a 2 s.c o m public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) { list.add(0, new Counter()); } }); final Composite composite = new Composite(shell, SWT.None); // TODO: This class is marked as "NON-API", why is it used in a snippet? new CompositeUpdater<Counter>(composite, list) { @Override protected Widget createWidget(int index) { Label label = new Label(composite, SWT.BORDER); // requestLayout(label); return label; } @Override protected void updateWidget(Widget widget, Counter element) { ((Label) widget).setText(element.getValue() + ""); requestLayout((Label) widget); } }; GridLayoutFactory.fillDefaults().numColumns(10).generateLayout(composite); GridDataFactory.fillDefaults().grab(true, true).applyTo(composite); GridLayoutFactory.fillDefaults().generateLayout(shell); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } }); display.dispose(); }