[DataBinding] Binding elements in different views [message #645091] |
Wed, 15 December 2010 09:58  |
Eclipse User |
|
|
|
Hi all!!
I'm developing a RAP application in which I need a master-detail scenario between a table or list and a form (of Control elements).
I have yet used the examples in the snippets page (http://wiki.eclipse.org/JFace_Data_Binding/Snippets) or the RAP project from Eclipse CVS repository org.eclipse.rap.demo.databinding.
I can create a master-detail which reside in a single view:
// Creating table viewer and relativa columns
viewer = new TableViewer(parent, SWT.MULTI | SWT.FULL_SELECTION | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
createColumns(viewer);
// Setting content provider
ObservableListContentProvider viewerContent = new ObservableListContentProvider();
viewer.setContentProvider(viewerContent);
// Setting label provider
String[] attrPerson = new String[] { "name", "address", "city" };
IObservableMap[] attributeMaps = BeansObservables.observeMaps( viewerContent.getKnownElements(), Person.class, attrPerson);
omlProvider = new ObservableMapLabelProvider(attributeMaps);
viewer.setLabelProvider(omlProvider);
// In "list" I have my list of data to populate the table
input = new WritableList(list, Person.class);
viewer.setInput(input);
// Let's binding
// Making the table observable
IObservableValue selectedPerson = ViewersObservables.observeSingleSelection(viewer);
Realm realm = SWTObservables.getRealm(parent.getDisplay());
DataBindingContext bindingContext = new DataBindingContext(realm);
// Binding the form elements with the selected element of the table
// 1st element; other one are set in a similar way
IObservableValue modelObservableValue = BeansObservables.observeDetailValue(selectedPerson, "name", String.class);
ISWTObservableValue targetObservableValue = SWTObservables.observeText(name, SWT.Modify);
Binding binding = bindingContext.bindValue(targetObservableValue, modelObservableValue);
This code works because I have all the needed elements in the same view. If, for example, I have the table in a view and the form in another one, how can I make the data of the selection from the table available to the form view?
My problem is in the step of the creation of the "selectedPerson" object on which the UI elements of the form are based. The method ViewersObservables#observeSingleSelection works woth teh viewer object which in my case is in a different view.
Thank you in advanced who can help.
Gabriele
|
|
|
|
|
Re: [DataBinding] Binding elements in different views [message #646294 is a reply to message #646279] |
Thu, 23 December 2010 03:30  |
Eclipse User |
|
|
|
Thanks for your reply Matthew
To select an element from the table another way which I used is:
IWorkbench workbench = PlatformUI.getWorkbench();
final IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
final ISelectionService selectionService = window.getSelectionService();
selectionService.addSelectionListener(...)
I think that your suggestion make the same tasks as the part I wrote the previous time (i.e. obtain the first element of hte selection):
Quote: |
/* "selection" has generic type Object; casting it to IStructuredSelection, I can have the first element of the selction, i.e. the selected object
*/
IStructuredSelection sselection = (IStructuredSelection) selection;
/* After checking the type of the selected object, I can use it as model observable part of the following binding
*/
selectedPerson = (Person) sselction.getFirstElement();
|
I will try your solution, and I will let you know.
thanks again
Gabriele
|
|
|
Powered by
FUDForum. Page generated in 0.03284 seconds