List of usage examples for org.eclipse.jface.databinding.viewers.typed ViewerProperties singleSelection
public static <S extends ISelectionProvider, T> IViewerValueProperty<S, T> singleSelection( Class<T> elementType)
From source file:org.eclipse.jface.examples.databinding.snippets.Snippet010MasterDetail.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); shell.setLayout(new GridLayout()); Person[] persons = new Person[] { new Person("Me"), new Person("Myself"), new Person("I") }; ListViewer viewer = new ListViewer(shell); viewer.setContentProvider(new ArrayContentProvider()); viewer.setInput(persons);/*from w w w . j a va 2 s .co m*/ Text name = new Text(shell, SWT.BORDER | SWT.READ_ONLY); // 1. Observe changes in selection. IObservableValue<Person> selection = ViewerProperties.singleSelection(Person.class).observe(viewer); // 2. Observe the name property of the current selection. IObservableValue<String> detailObservable = BeanProperties.value(Person.class, "name", String.class) .observeDetail(selection); // 3. Bind the Text widget to the name detail (selection's // name). new DataBindingContext().bindValue(WidgetProperties.text(SWT.NONE).observe(name), detailObservable, new UpdateValueStrategy<>(false, UpdateValueStrategy.POLICY_NEVER), null); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } }); display.dispose(); }
From source file:org.eclipse.jface.examples.databinding.snippets.Snippet019TreeViewerWithListFactory.java
License:Open Source License
protected DataBindingContext initDataBindings() { IObservableValue<Bean> treeViewerSelectionObserveSelection = ViewerProperties.singleSelection(Bean.class) .observe(beanViewer);//from ww w. j a va 2 s .co m IObservableValue<String> textTextObserveWidget = WidgetProperties.text(SWT.Modify).observe(beanText); IObservableValue<String> treeViewerValueObserveDetailValue = BeanProperties .value(Bean.class, "text", String.class).observeDetail(treeViewerSelectionObserveSelection); DataBindingContext bindingContext = new DataBindingContext(); bindingContext.bindValue(textTextObserveWidget, treeViewerValueObserveDetailValue); return bindingContext; }
From source file:org.eclipse.jface.examples.databinding.snippets.Snippet019TreeViewerWithListFactory.java
License:Open Source License
private void initExtraBindings(DataBindingContext dbc) { final IObservableValue<Bean> beanViewerSelection = ViewerProperties.singleSelection(Bean.class) .observe(beanViewer);/*from w w w .j a v a 2s . c om*/ IObservableValue<Boolean> beanSelected = ComputedValue.create(() -> beanViewerSelection.getValue() != null); dbc.bindValue(WidgetProperties.enabled().observe(addChildBeanButton), beanSelected); dbc.bindValue(WidgetProperties.enabled().observe(removeBeanButton), beanSelected); clipboard = new WritableValue<>(); dbc.bindValue(WidgetProperties.enabled().observe(copyButton), beanSelected); dbc.bindValue(WidgetProperties.enabled().observe(pasteButton), ComputedValue.create(() -> clipboard.getValue() != null)); ViewerSupport.bind(beanViewer, input, BeanProperties.list("list", Bean.class), BeanProperties.value(Bean.class, "text")); }
From source file:org.eclipse.jface.examples.databinding.snippets.Snippet020TreeViewerWithSetFactory.java
License:Open Source License
private void initExtraBindings(DataBindingContext dbc) { final IObservableValue<Bean> beanViewerSelection = ViewerProperties.singleSelection(Bean.class) .observe(beanViewer);//w ww . j ava2 s.c o m IObservableValue<Boolean> beanSelected = ComputedValue.create(() -> beanViewerSelection.getValue() != null); dbc.bindValue(WidgetProperties.enabled().observe(addChildBeanButton), beanSelected); dbc.bindValue(WidgetProperties.enabled().observe(removeBeanButton), beanSelected); clipboard = new WritableValue<>(); dbc.bindValue(WidgetProperties.enabled().observe(copyButton), beanSelected); dbc.bindValue(WidgetProperties.enabled().observe(pasteButton), ComputedValue.create(() -> clipboard.getValue() != null)); ViewerSupport.bind(beanViewer, input, BeanProperties.set("set", Bean.class), BeanProperties.value(Bean.class, "text")); }
From source file:org.eclipse.jface.examples.databinding.snippets.Snippet024SelectObservableValue.java
License:Open Source License
protected void createContents() { shell = new Shell(); shell.setSize(400, 300);//w w w.j a v a 2s . co m shell.setLayout(new GridLayout(2, true)); shell.setText("Snippet024SelectObservableValue"); final ListViewer listViewer = new ListViewer(shell, SWT.BORDER); listViewer.setContentProvider(new ArrayContentProvider()); listViewer.getList().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); final Group group = new Group(shell, SWT.NONE); group.setText("Radio Group"); group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); group.setLayout(new GridLayout()); // Data Binding Color[] colors = Color.values(); listViewer.setInput(colors); IObservableValue<Color> listViewerSelection = ViewerProperties.singleSelection(Color.class) .observe(listViewer); SelectObservableValue<Color> radioGroup = new SelectObservableValue<>(); for (Color color : colors) { Button button = new Button(group, SWT.RADIO); button.setText(color.toString()); radioGroup.addOption(color, WidgetProperties.buttonSelection().observe(button)); } DataBindingContext dbc = new DataBindingContext(); dbc.bindValue(radioGroup, listViewerSelection); }
From source file:org.eclipse.jface.examples.databinding.snippets.Snippet035PostSelectionProvider.java
License:Open Source License
private void createFieldSection(Composite parent) { final Group section = createSectionGroup(parent, 2); // normal selection Label selectionLabel = createLabelField(section, "Selection:"); IViewerObservableValue<String> selectionObservable = ViewerProperties.singleSelection(String.class) .observe(listViewer);/* ww w .j a v a 2 s. c o m*/ dbc.bindValue(WidgetProperties.text().observe(selectionLabel), selectionObservable); // post selection Label postSelectionLabel = createLabelField(section, "Post selection:"); IViewerObservableValue<String> postSelectionObservable = ViewerProperties.singlePostSelection(String.class) .observe(listViewer); dbc.bindValue(WidgetProperties.text().observe(postSelectionLabel), postSelectionObservable); }