[Resolved] EMF / JFace howto do a 'double' databinding [message #759493] |
Mon, 28 November 2011 19:44 |
Bernard Sarter 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 |
Thomas Schindl 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.
|
|
|
|
Powered by
FUDForum. Page generated in 0.01903 seconds