Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » [DataBinding] Binding elements in different views
[DataBinding] Binding elements in different views [message #645091] Wed, 15 December 2010 14:58 Go to next message
Gabriele  is currently offline Gabriele Friend
Messages: 19
Registered: November 2010
Junior Member
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 #645962 is a reply to message #645091] Tue, 21 December 2010 10:47 Go to previous messageGo to next message
Gabriele  is currently offline Gabriele Friend
Messages: 19
Registered: November 2010
Junior Member
Maybe this isn't a common use case, or I haven't exposed so well my problem.
I make a brief summary: I want to do a master-detail scenario in different views.

I resolved my problem using the "Selection service" framework:

// Made my tableviewer as selection provider
getSite().setSelectionProvider(tableviewer);

....
// Add a selection listener in the "detail" view 
getSite().getWorkbenchWindow().getSelectionService().addSelectionListener(...). 

...

// Management of the selection
private ISelectionListener mylistener = new ISelectionListener() {
       public void selectionChanged(IWorkbenchPart sourcepart, ISelection selection) {
       if (sourcepart != MyView.this &&
           selection instanceof IStructuredSelection) {
           doSomething(((IStructuredSelection) selection).toList());
           }
       }
   };


When I select an element from my tableviewer, I have a selection object which is a Person object (in mycase); so I have the model observable object in the binding process.
So I can use the previous code where the "selectedPerson" is the selection object

/* "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();


Then it is possible to bind each UI element of the detail view with the model represented by the selected object.
Re: [DataBinding] Binding elements in different views [message #646279 is a reply to message #645962] Thu, 23 December 2010 03:56 Go to previous messageGo to next message
Matthew Hall is currently offline Matthew HallFriend
Messages: 368
Registered: July 2009
Senior Member
On 12/21/2010 03:47 AM, Gabriele wrote:
> Maybe this isn't a common use case, or I haven't exposed so well my
> problem. I make a brief summary: I want to do a master-detail scenario
> in different views.

I think you want WorkbenchProperties.singleSelection():

http://help.eclipse.org/helios/index.jsp?topic=/org.eclipse. platform.doc.isv/reference/api/org/eclipse/ui/databinding/Wo rkbenchProperties.html

I'm not positive, but I think WorkbenchProperties is in the
org.eclipse.ui.workbench bundle.

Hope this helps,

Matthew
Re: [DataBinding] Binding elements in different views [message #646294 is a reply to message #646279] Thu, 23 December 2010 08:30 Go to previous message
Gabriele  is currently offline Gabriele Friend
Messages: 19
Registered: November 2010
Junior Member
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
Previous Topic:How to set a initial value of the line height when you creae a tableviewer
Next Topic:Add coolbar to the status line
Goto Forum:
  


Current Time: Fri Mar 29 10:33:39 GMT 2024

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

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

Back to the top