Community
Participate
Working Groups
Three new snippets, with sketches of what is bound to what: * SnippetTableRidgetBindingSelectionWithoutIndirection: table selection -> label text * SnippetTableRidgetBindingSelection: table selection -> model -> label text * SnippetComboRidgetModelIndirection: combobox value/selection -> model -> label text IMPORTANT NOTE, concerning SnippetTableRidgetBindingSelection: The bindings do not seem to work. The model is updated correctly when something is selected in the table, but is not correctly reflected in the label text. In the attached file I re-bind the model to the label, which of course is bogus… (marked XXX in source)
Created attachment 155509 [details] SnippetTableRidgetBindingSelectionWithoutIndirection
Created attachment 155510 [details] SnippetTableRidgetBindingSelection Bogus but working snippet; points out the problem.
Created attachment 155511 [details] SnippetComboRidgetModelIndirection
Reg. SnippetTableRidgetBindingSelection: the rebind is necessary, because the instance of currentSelection changes. t1: currentSelection#instance1 t2: outputRidget.bindToModel(currentSelection); outputRidget.updateFromModel(); // shows instance1 t3: currentSelection#instance2; // ridget still bound to instance1 t4: outputRidget.bindToModel(currentSelection); outputRidget.updateFromModel(); // shows instance2
Hi Yang, thanks for the snippets. The short answer is that, for the table, you cannot bind to a subproperty of the current selection directly. What is missing is API like: tableRidget.bindSingleSelection("english", outputRidget, "text"); If you think we need this please open a separate bugzilla so we can keep track of this request. As a workaround you can use: tableRidget.addSelectionListener(new ISelectionListener() { public void ridgetSelected(SelectionEvent event) { List<Object> newSelection = event.getNewSelection(); if (!newSelection.isEmpty()) { MyNode node = (MyNode) newSelection.get(0); outputRidget.setText(node.getEnglish()); } } }); I'm attaching a patch with all snippets. Feel free to change as appropriate. A couple of quick comments: - I'm providing adding a snippet that shows an alternative way to achieve the results of SnippetComboRidgetModelIndirection. If there is need to store something one can also use a WritableValue instead of a field. - Please use SWT.NONE instead of 0 when creating new SWT controls, i.e. new Composite(shell, SWT.NONE) - I would prefer to use to UIControlsFactory to create new widgets, so that we can demonstrate this aspect of Riena as well. - The preferred naming convention for the Snippets is SnippetRidgetName123. We can add a longer description the the Riena Snippets on the wiki, after the snippets are committed -- http://wiki.eclipse.org/Riena_Snippets
Created attachment 155530 [details] Updated Snippets (patch)
Elias, thanks for all the helpful comments and snippet updates. Your work-around works, of course. But would you still call it "binding"?? (i.e. you aren't using bindSingleSelectionToModel(...) and instead set the values directly) Let's say I don't mind outputting the whole MyNode object (toString()) constituting the current selection, bypassing the requirement for binding to a subproperty of the current selection. So I believe I should be able to bind the table selection to the field 'MyNode currentSelection', and this same field to the output ridget, like this: tableRidget.bindSingleSelectionToModel(this, "currentSelection"); outputRidget.bindToModel(this, "currentSelection"); tableRidget.addSelectionListener(new ISelectionListener() { public void ridgetSelected(SelectionEvent event) { outputRidget.updateFromModel(); } }); However this doesn't work. The reason seems to be that - even though it's called *single* selection - the selection is of type List. I'm assuming there's a good reason for this; but what is it?
(In reply to comment #7) Hi Yang, (a) This: > tableRidget.bindSingleSelectionToModel(this, "currentSelection"); will bind the whole current selection from the tableRidget to setSetCurrentSelection(). If you want a (sub)property of the current selection, you would need something like: tableRidget.bindSingleSelection("english", outputRidget, "text"); which is not supported. (b) ISelectionListener is the same for Single and Multiple selection, in order to simplify the API. This is why single selection is considered as a special case of multiple selection - i.e. you always get a list in both cases. I hope this answers your questions?
Hi Elias, Thanks for your comments. I rebuilt my example from comment #7: strangely enough now it does work. I probably had had some leftover artifact somewhere :-/ Sorry for the trouble. At least I now understand better, and am writing it down for future reference (might be obvious, but initially wasn't for me): * tableRidget.bindSingleSelectionToModel(this, "currentSelection") binds the table's currently selected MyNode object (the row) to the property currentSelection of type MyNode. * If you use ISelectionListener to retrieve the current selection through selectionEvent. getNewSelection(), you will get a List<Object>, as shown in comment #5. I am attaching an improved version of SnippetTableRidgetBindingSelection that shows how to bind the label to a subproperty of the selected-row object. It's not pretty, but I think it's still better than the manual updating from comment #5.
Created attachment 155964 [details] Updated SnippetTableRidgetBindingSelection
Thanks Yang! I've commited the table snippets as SnippetTableRidget005 + 006. I've left out the Combo snippet because I thought it is very similar to other snippets: SnipppetComboRidget001/002, SnippetTableRidget005/006