Example usage for org.eclipse.jface.databinding.viewers ViewerSupport bind

List of usage examples for org.eclipse.jface.databinding.viewers ViewerSupport bind

Introduction

In this page you can find the example usage for org.eclipse.jface.databinding.viewers ViewerSupport bind.

Prototype

@SafeVarargs
public static <E> void bind(AbstractTreeViewer viewer, E input,
        ISetProperty<? super E, ? extends E> childrenProperty,
        IValueProperty<? super E, ?>... labelProperties) 

Source Link

Document

Binds the viewer to the specified input, using the specified children property to generate child nodes, and the specified label properties to generate labels.

Usage

From source file:cz.robotron.examples.parts._005_TreeWithViewerSupport.java

License:Open Source License

@PostConstruct
public void createComposite(Composite parent) {
    try {//from ww  w .  ja v a 2  s. c  om

        GridLayout gl_parent = new GridLayout();
        parent.setLayout(gl_parent);

        FilteredTree filteredTree = new FilteredTree(parent, SWT.BORDER | SWT.FULL_SELECTION,
                new MyPatternFilter(), true);
        _treeViewer = filteredTree.getViewer();
        Tree tree = _treeViewer.getTree();
        tree.setHeaderVisible(true);
        tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));

        String[] propertyNames = new String[] { "name", "lastName", "firstName", "address.street",
                "address.city" };
        createTreeColumns(_treeViewer, propertyNames);

        final Object input = TestData.getRoot();

        ObservableListTreeContentProvider contentProvider = new ObservableListTreeContentProvider(
                new IObservableFactory() {

                    @Override
                    public IObservable createObservable(Object target) {
                        return (IObservable) target;
                    }
                }, null);

        _treeViewer.setContentProvider(contentProvider);

        IListProperty childrenProp = new DelegatingListProperty() {
            IListProperty root = BeanProperties.list(PersonGroup.class, "lists");
            IListProperty personGroupChildren = BeanProperties.list(PersonList.class, "persons");

            @Override
            protected IListProperty doGetDelegate(Object source) {
                if (source instanceof PersonList)
                    return personGroupChildren;

                else if (source instanceof PersonGroup)
                    return root;

                return null;

            }
        };

        IValueProperty[] valueProperties = BeanProperties.values(propertyNames);

        ViewerSupport.bind(_treeViewer, input, childrenProp, valueProperties);

    } catch (Exception e) {
        Utils.showException("Cannot create ViewerSupport for a Table", e);
    }

}

From source file:org.eclipse.e4.xwt.tests.snipppets.Snippet019TreeViewerWithListFactory.java

License:Open Source License

private void initExtraBindings(DataBindingContext dbc) {
    final IObservableValue beanViewerSelection = ViewersObservables.observeSingleSelection(beanViewer);
    IObservableValue beanSelected = new ComputedValue(Boolean.TYPE) {
        protected Object calculate() {
            return Boolean.valueOf(beanViewerSelection.getValue() != null);
        }//from   w ww. j  a v a2s  .c o  m
    };
    dbc.bindValue(SWTObservables.observeEnabled(addChildBeanButton), beanSelected);
    dbc.bindValue(SWTObservables.observeEnabled(removeBeanButton), beanSelected);

    clipboard = new WritableValue();
    dbc.bindValue(SWTObservables.observeEnabled(copyButton), beanSelected);
    dbc.bindValue(SWTObservables.observeEnabled(pasteButton), new ComputedValue(Boolean.TYPE) {
        protected Object calculate() {
            return Boolean.valueOf(clipboard.getValue() != null);
        }
    });

    ViewerSupport.bind(beanViewer, input, BeanProperties.list("list", Bean.class),
            BeanProperties.value(Bean.class, "text"));
}

From source file:org.eclipse.e4.xwt.tests.snipppets.Snippet020TreeViewerWithSetFactory.java

License:Open Source License

private void initExtraBindings(DataBindingContext dbc) {
    final IObservableValue beanViewerSelection = ViewersObservables.observeSingleSelection(beanViewer);
    IObservableValue beanSelected = new ComputedValue(Boolean.TYPE) {
        protected Object calculate() {
            return Boolean.valueOf(beanViewerSelection.getValue() != null);
        }// w  w  w.  j a v a2  s .c  o m
    };
    dbc.bindValue(SWTObservables.observeEnabled(addChildBeanButton), beanSelected);
    dbc.bindValue(SWTObservables.observeEnabled(removeBeanButton), beanSelected);

    clipboard = new WritableValue();
    dbc.bindValue(SWTObservables.observeEnabled(copyButton), beanSelected);
    dbc.bindValue(SWTObservables.observeEnabled(pasteButton), new ComputedValue(Boolean.TYPE) {
        protected Object calculate() {
            return Boolean.valueOf(clipboard.getValue() != null);
        }
    });

    ViewerSupport.bind(beanViewer, input, BeanProperties.set("set", Bean.class),
            BeanProperties.value(Bean.class, "text"));
}

From source file:org.eclipse.e4.xwt.tests.snipppets.Snippet026AnonymousBeanProperties.java

License:Open Source License

private void bindUI() {
    ISetProperty treeChildrenProperty = new DelegatingSetProperty() {
        ISetProperty modelGroups = BeanProperties.set(ApplicationModel.class, "groups");
        ISetProperty groupContacts = BeanProperties.set(ContactGroup.class, "contacts");

        protected ISetProperty doGetDelegate(Object source) {
            if (source instanceof ApplicationModel)
                return modelGroups;
            if (source instanceof ContactGroup)
                return groupContacts;
            return null;
        }//  w  w  w .j a v a 2  s.  c  om
    };

    ViewerSupport.bind(contactViewer, model, treeChildrenProperty,
            BeanProperties.values(new String[] { "name", "status" }));

    contactViewer.expandAll();

    final IObservableValue selection = ViewerProperties.singleSelection().observe(contactViewer);

    DataBindingContext dbc = new DataBindingContext();

    dbc.bindValue(WidgetProperties.text(SWT.Modify).observe(nameText),
            BeanProperties.value("name").observeDetail(selection));

    statusViewer.setContentProvider(new ArrayContentProvider());
    statusViewer.setInput(statuses);

    dbc.bindValue(ViewerProperties.singleSelection().observe(statusViewer),
            BeanProperties.value("status").observeDetail(selection));

    dbc.bindValue(WidgetProperties.enabled().observe(statusViewer.getControl()), new ComputedValue() {
        protected Object calculate() {
            return Boolean.valueOf(selection.getValue() instanceof Contact);
        }
    });
}

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   ww w .  j  a  v  a2  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.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);/*from w  ww.j a va 2 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.Snippet026AnonymousBeanProperties.java

License:Open Source License

private void bindUI() {
    ISetProperty<Object, Object> treeChildrenProperty = new DelegatingSetProperty<Object, Object>() {
        ISetProperty<ApplicationModel, ContactGroup> modelGroups = BeanProperties.set(ApplicationModel.class,
                "groups", ContactGroup.class);
        ISetProperty<ContactGroup, Contact> groupContacts = BeanProperties.set(ContactGroup.class, "contacts",
                Contact.class);

        @SuppressWarnings("unchecked")
        @Override/*  w  w  w.j  a  v a2s  . co  m*/
        protected ISetProperty<Object, Object> doGetDelegate(Object source) {
            if (source instanceof ApplicationModel)
                return (ISetProperty<Object, Object>) (Object) modelGroups;
            if (source instanceof ContactGroup)
                return (ISetProperty<Object, Object>) (Object) groupContacts;
            return null;
        }
    };

    ViewerSupport.bind(contactViewer, model, treeChildrenProperty, BeanProperties.values("name", "status"));

    contactViewer.expandAll();

    final IObservableValue<Object> selection = ViewerProperties.singleSelection().observe(contactViewer);

    DataBindingContext dbc = new DataBindingContext();

    dbc.bindValue(WidgetProperties.text(SWT.Modify).observe(nameText),
            BeanProperties.value("name").observeDetail(selection));

    statusViewer.setContentProvider(new ArrayContentProvider());
    statusViewer.setInput(statuses);

    dbc.bindValue(ViewerProperties.singleSelection().observe(statusViewer),
            BeanProperties.value("status").observeDetail(selection));

    dbc.bindValue(WidgetProperties.enabled().observe(statusViewer.getControl()),
            ComputedValue.create(() -> selection.getValue() instanceof Contact));
}

From source file:org.salever.swtjface.demo.binding.TreeViewerWithListFactory.java

License:Open Source License

private void initExtraBindings(DataBindingContext dbc) {
    final IObservableValue beanViewerSelection = ViewersObservables.observeSingleSelection(beanViewer);
    IObservableValue beanSelected = new ComputedValue(Boolean.TYPE) {
        protected Object calculate() {
            return Boolean.valueOf(beanViewerSelection.getValue() != null);
        }/*  w  ww.j  a  v  a 2  s  .com*/
    };
    dbc.bindValue(SWTObservables.observeEnabled(addChildBeanButton), beanSelected);
    dbc.bindValue(SWTObservables.observeEnabled(removeBeanButton), beanSelected);

    clipboard = new WritableValue();
    dbc.bindValue(SWTObservables.observeEnabled(copyButton), beanSelected);
    dbc.bindValue(SWTObservables.observeEnabled(pasteButton), new ComputedValue(Boolean.TYPE) {
        protected Object calculate() {
            return Boolean.valueOf(clipboard.getValue() != null);
        }
    });

    ViewerSupport.bind(beanViewer, input, BeanProperties.list("list", BeanItem.class),
            BeanProperties.value(Bean.class, "text"));
}