[DataBinding] Binding a TableViewer [message #464045] |
Thu, 22 February 2007 14:13 |
Eclipse User |
|
|
|
Hi all!
I playing around with binding a TableViewer. I use the code snippet
Snippet009TableViewer from org.eclipse.jface.examples.databinding.snippets
One thing that I found at was that the BindingContext isn't actually used
when binding TableViewers. The following code (from the snippet shows this)
public void run() {
DataBindingContext bindingContext = new DataBindingContext();
bindGUI(bindingContext);
}
protected void bindGUI(DataBindingContext bindingContext) {
// Since we're using a JFace Viewer, we do first wrap our Table...
TableViewer peopleViewer = new TableViewer(committers);
// Create a standard content provider
ObservableListContentProvider peopleViewerContentProvider =
new ObservableListContentProvider();
peopleViewer.setContentProvider(peopleViewerContentProvider) ;
// And a standard label provider that maps columns
IObservableMap[] attributeMaps = BeansObservables.observeMaps(
peopleViewerContentProvider.getKnownElements(), Person.class,
new String[] { "name" });
peopleViewer.setLabelProvider(new
ObservableMapLabelProvider(attributeMaps));
// Now set the Viewer's input
peopleViewer.setInput(new WritableList(viewModel.getPeople(),
Person.class));
}
My question is now why is it like this?
The problem I have is that I have a FormPage which has a main TableViewer.
When a row is selected in that table, two other TableViewers shall be
updated as well as several other components. As soon as the user selects
something from the main table, I rebind the components. In order for that
to work I had to use bindingContext.dispose() and the create a new
instance of the of the BindingContext. This only works for the other
components (that are using the BindingContext) and not for the table
viewers since they are not any BindingContext.
I use the following code to bind the tableviewers:
ObservableListContentProvider obslist = new
ObservableListContentProvider();
refTable.setContentProvider(obslist);
IObservableMap[] attrMap =
BeansObservables.observeMaps(obslist.getKnownElements(),
ProjectRow.class, new String[] { "projectName", "totalCost2",
"difference" });
refTable.setLabelProvider(new ObservableMapLabelProvider(attrMap));
refTable.setInput(new WritableList(selectedRow.getReferenceObjects(),
ProjectRow.class));
Another issue I have is that when I put this code after the snippet above,
the binding doesn't work for that component.
projectRowDBC.bindValue(SWTObservables.observeText(comment, SWT.Modify),
BeansObservables.observeValue(selectedRow, "comment"), null);
So it seems that the code for binding a table viewer messes up the code
that comes after. Am I using the databinding correctly or is something
essential that I have missed?
// Marcus
|
|
|
Powered by
FUDForum. Page generated in 0.04918 seconds