Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » [Resolved] EMF / JFace howto do a 'double' databinding
[Resolved] EMF / JFace howto do a 'double' databinding [message #759493] Mon, 28 November 2011 19:44 Go to next message
Bernard Sarter is currently offline Bernard SarterFriend
Messages: 88
Registered: August 2011
Location: Paris, France
Member
Hello,

I would like to do a "double" databinding between an EMF model and a JFace TableViewer:
A) one EAttribute of an EOBject shall provide the text of a Cell,
* and *
B) one other EAttribute of an other EObject shall provide the background colour of the same Cell.

I know how to do A) (see snippet below), but I don't have the beginning of an idea about how to do B), ie how to add a second binding and a second LabelProvider to the same column.

    @Override
    public void createPartControl(Composite parent) {

        fViewer = new TableViewer(parent, SWT.FULL_SELECTION | SWT.BORDER | SWT.MULTI);

        final Table table = fViewer.getTable();
        table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 0, 0));

        ObservableListContentProvider cp = new ObservableListContentProvider();
        fViewer.setContentProvider(cp);

        IObservableSet set = cp.getKnownElements();

        {
            IValueProperty property = EMFProperties.value(SysmodPackage.Literals.MODEL_ELEMENT__NAME);
            final TableViewerColumn column = new TableViewerColumn(fViewer, SWT.LEAD);
            column.getColumn().setText("title");
            column.setLabelProvider(new ObservableMapCellLabelProvider(property.observeDetail(set)) {
                @Override
                public void update(ViewerCell cell) {
                    String s = (String) attributeMaps[0].get(cell.getElement());
                    cell.setText(s);
                }
            });
        }

        final IObservableList data = EMFProperties.list(SysmodPackage.Literals.MODEL__FOO).observeDetail(master);
        fViewer.setInput(data);


Any suggestions or comments welcome!

NB: I also posted the same message on the 'EMF' forum, sorry for that, but since my problem is somewhere in between ...

Best regards,
Bernard.

[Updated on: Tue, 29 November 2011 20:23]

Report message to a moderator

Re: EMF / JFace howto do a 'double' databinding [message #759526 is a reply to message #759493] Tue, 29 November 2011 00:02 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
So why not calling observing the property like you do it for the text
and call cell.setBackground()?

Tom

Am 28.11.11 20:44, schrieb Bernard SARTER:
> Hello,
>
> I would like to do a "double" databinding between an EMF model and a
> JFace TableViewer:
> A) one EAttribute of an EOBject shall provide the text of a Cell,
> * and *
> B) one other EAttribute of an other EObject shall provide the background
> colour of the same Cell.
>
> I know how to do A) (see snippet below), but I don't have the beginning
> of an idea about how to do B), ie how to add a second binding and a
> second LabelProvider to the same column.
>
>
> @Override
> public void createPartControl(Composite parent) {
>
> fViewer = new TableViewer(parent, SWT.FULL_SELECTION | SWT.BORDER
> | SWT.MULTI);
>
> final Table table = fViewer.getTable();
> table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true,
> 0, 0));
>
> ObservableListContentProvider cp = new
> ObservableListContentProvider();
> fViewer.setContentProvider(cp);
>
> IObservableSet set = cp.getKnownElements();
>
> {
> IValueProperty property =
> EMFProperties.value(SysmodPackage.Literals.MODEL_ELEMENT__NAME);
> final TableViewerColumn column = new
> TableViewerColumn(fViewer, SWT.LEAD);
> column.getColumn().setText("title");
> column.setLabelProvider(new
> ObservableMapCellLabelProvider(property.observeDetail(set)) {
> @Override
> public void update(ViewerCell cell) {
> String s = (String)
> attributeMaps[0].get(cell.getElement());
> cell.setText(s);
> }
> });
> }
>
> final IObservableList data =
> EMFProperties.list(SysmodPackage.Literals.MODEL__FOO).observeDetail(master);
>
> fViewer.setInput(data);
>
>
> Any suggestions or comments welcome!
>
> NB: I also posted the same message on the 'EMF' forum, sorry for that,
> but since my problem is somewhere in between ...
>
> Best regards,
> Bernard.
[Resolved] EMF / JFace howto do a 'double' databinding [message #759750 is a reply to message #759526] Tue, 29 November 2011 20:22 Go to previous message
Bernard Sarter is currently offline Bernard SarterFriend
Messages: 88
Registered: August 2011
Location: Paris, France
Member
Ok, I missed the other constructor of the ObservableMapCellLabelProvider ...

Thanks,
Bernard
Previous Topic:DialogCellEditor databinding
Next Topic:[Databinding] Can a bound bean be null?
Goto Forum:
  


Current Time: Tue Apr 23 17:19:20 GMT 2024

Powered by FUDForum. Page generated in 0.03296 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top