| Home » Eclipse Projects » Eclipse Platform » Requesting JFace ComboViewer data binding help
 Goto Forum:| 
| Requesting JFace ComboViewer data binding help [message #329491] | Thu, 26 June 2008 03:19  |  | 
| Eclipse User  |  |  |  |  | Hello, 
 Apologies in advance for the uncertainty here, but I'm relatively sure
 this is the correct forum to post to.  I've spent days combing through
 examples, snippets, and earlier messages, and although pretty sure that
 the answers are out there in the previous messages, I'm not yet able to
 "connect the dots" for a relatively straightforward data binding task.
 Disclaimers ahoy!
 
 I'm writing a database authoring RCP application that has all of its keys
 represented as UUIDs.  Building up GUI options is done by reading from the
 database and creating these dynamic lists.  I'm using Apache Cayenne to do
 the database access, and building up tables of appropriate domains by
 using an extended HashMap object, which has some support for
 application-specific requirements.  Thus, the statuses that a concept can
 take on might be:
 
 "aa854fbb-f9f4-43af-8077-729ee40f3daa" = "ACTIVE"
 "0f9c73c7-5ac9-462c-85c2-fc896abd2882" = "RETIRED"
 
 ...etc. The UUID is the key, and the status label is the value in that
 hash map, which the application loads up once.
 
 Now, the issue that I'm having is that I need to bind the key/values to
 the JFace ComboViewer, but bind the selection UUID to the concept's model
 object. And, of course, only want the user to see the label.  No issue
 there: I do this:
 
 conceptTypeComboViewer.setContentProvider(new ArrayContentProvider());
 conceptTypeComboViewer.setLabelProvider(new GlobalLabelProvider());
 conceptTypeComboViewer.setInput(DaedalusGlobals.getInstance( ).typeGlobalMap.toArray());
 
 Now, I want to bind the selection in the ComboViewer so that when a
 database record is selected, it displays the label for the UUID that's set
 in the concept's model.  For example, if a concept is active, it will have
 a "conceptStatusID" which is exposed as a bean property
 (getConceptStatusID), and have a value of
 "aa854fbb-f9f4-43af-8077-729ee40f3daa". When a model is selected in
 another tableviewer, which I have set up already, I want both the current
 value to reflect the model, and the model to respond to any change in the
 JFace ComboViewer.  I have this type of paradigm working just fine with
 the table and any text fields in the concept model:
 ===============
 IObservableValue descriptionTextTextObserveWidget =
 SWTObservables.observeText(descriptionText, SWT.Modify);
 IObservableValue conceptTableViewerDescriptionObserveDetailValue =
 BeansObservables.observeDetailValue(Realm.getDefault(),
 conceptTableViewerSelectionObserveSelection, "description",
 java.lang.String.class);
 bindingContext.bindValue(conceptTableViewerDescriptionObserv eDetailValue,
 descriptionTextTextObserveWidget, null, null);
 ===============
 And everything works great.  But I cannot do the same with the
 ComboViewer.  When I attempt to connect them as such:
 ===============
 IObservableValue conceptTableViewerSingleSelection =
 ViewersObservables.observeSingleSelection(conceptTableViewer );
 
 IObservableValue conceptTableViewerConceptTypeIdObserveDetailValue =
 BeansObservables.observeDetailValue(Realm.getDefault(),
 conceptTableViewerSingleSelection, "conceptTypeId",
 java.lang.String.class);
 
 ObservableListContentProvider conceptTableViewerContentProviderList = new
 ObservableListContentProvider();
 conceptTableViewer.setContentProvider(conceptTableViewerCont entProviderList);
 IObservableMap[] conceptTableViewerLabelProviderMaps =
 BeansObservables.observeMaps(conceptTableViewerContentProvid erList.getKnownElements(),
 Concept.class, new String[]{"description", "ecid", "statusId",
 "conceptTypeId"});
 IObservableList cptListConceptsObserveList =
 BeansObservables.observeList(Realm.getDefault(), cptList, "concepts");
 bindingContext.bindValue(comboSelectionObserveWidget,
 conceptTableViewerConceptTypeIdObserveDetailValue, null, null);
 ===============
 This does bind the concept model's Concept Type ID to the ComboViewer, but
 it displays as the ECID, and not the dereferenced value ("Active").  Also,
 selections made in the ComboViewer are sent to the setConceptTypeID as
 their value, and not the underlying key (UUID).
 
 I know that there is something very basic here that I'm doing wrong, and I
 just can't find it.  The ArrayContentProvider is populated with GlobalPair
 objects, which have both the key and value exposed, and the label provider
 works with it just fine (get/setGlobalID, get/setGlobalDisp).  Can any
 direct me to an example or see where I've gone wrong here.  I'm way past
 being eternally grateful.  I'm also wondering it my answer may lie in
 having my extended HashMap implement IObservableMap, but I'm trying to
 work within the framework as it's intended to be used.
 
 Thanks in advance,
 
 Lawrence
 |  |  |  |  | 
| Re: Requesting JFace ComboViewer data binding help [message #329495 is a reply to message #329491] | Thu, 26 June 2008 03:41   |  | 
| Eclipse User  |  |  |  |  | Hi, 
 Let's see if I understand your model appropiately.
 
 Concept {
 String description; // Concept 1
 String statusId;  // "aa854fbb-f9f4-43af-8077-729ee40f3daa"
 }
 
 
 Status {
 String uuid; // "aa854fbb-f9f4-43af-8077-729ee40f3daa"
 String label; // "ACTIVE"
 }
 
 Is the above correct?
 
 Tom
 
 Lawrence schrieb:
 > Hello,
 >
 > Apologies in advance for the uncertainty here, but I'm relatively sure
 > this is the correct forum to post to.  I've spent days combing through
 > examples, snippets, and earlier messages, and although pretty sure that
 > the answers are out there in the previous messages, I'm not yet able to
 > "connect the dots" for a relatively straightforward data binding task.
 > Disclaimers ahoy!
 >
 > I'm writing a database authoring RCP application that has all of its
 > keys represented as UUIDs.  Building up GUI options is done by reading
 > from the database and creating these dynamic lists.  I'm using Apache
 > Cayenne to do the database access, and building up tables of appropriate
 > domains by using an extended HashMap object, which has some support for
 > application-specific requirements.  Thus, the statuses that a concept
 > can take on might be:
 >
 >     "aa854fbb-f9f4-43af-8077-729ee40f3daa" = "ACTIVE"
 >     "0f9c73c7-5ac9-462c-85c2-fc896abd2882" = "RETIRED"
 >
 > ..etc. The UUID is the key, and the status label is the value in that
 > hash map, which the application loads up once.
 >
 > Now, the issue that I'm having is that I need to bind the key/values to
 > the JFace ComboViewer, but bind the selection UUID to the concept's
 > model object. And, of course, only want the user to see the label.  No
 > issue there: I do this:
 >
 >         conceptTypeComboViewer.setContentProvider(new
 > ArrayContentProvider());
 >         conceptTypeComboViewer.setLabelProvider(new GlobalLabelProvider());
 >
 >  conceptTypeComboViewer.setInput(DaedalusGlobals.getInstance( ).typeGlobalMap.toArray());
 >
 >
 > Now, I want to bind the selection in the ComboViewer so that when a
 > database record is selected, it displays the label for the UUID that's
 > set in the concept's model.  For example, if a concept is active, it
 > will have a "conceptStatusID" which is exposed as a bean property
 > (getConceptStatusID), and have a value of
 > "aa854fbb-f9f4-43af-8077-729ee40f3daa". When a model is selected in
 > another tableviewer, which I have set up already, I want both the
 > current value to reflect the model, and the model to respond to any
 > change in the JFace ComboViewer.  I have this type of paradigm working
 > just fine with the table and any text fields in the concept model:
 > ===============
 > IObservableValue descriptionTextTextObserveWidget =
 > SWTObservables.observeText(descriptionText, SWT.Modify);
 > IObservableValue conceptTableViewerDescriptionObserveDetailValue =
 > BeansObservables.observeDetailValue(Realm.getDefault(),
 > conceptTableViewerSelectionObserveSelection, "description",
 > java.lang.String.class);
 >  bindingContext.bindValue(conceptTableViewerDescriptionObserv eDetailValue,
 > descriptionTextTextObserveWidget, null, null);
 > ===============
 > And everything works great.  But I cannot do the same with the
 > ComboViewer.  When I attempt to connect them as such:
 > ===============
 > IObservableValue conceptTableViewerSingleSelection =
 >  ViewersObservables.observeSingleSelection(conceptTableViewer );
 >
 > IObservableValue conceptTableViewerConceptTypeIdObserveDetailValue =
 > BeansObservables.observeDetailValue(Realm.getDefault(),
 > conceptTableViewerSingleSelection, "conceptTypeId",
 > java.lang.String.class);
 >
 > ObservableListContentProvider conceptTableViewerContentProviderList =
 > new ObservableListContentProvider();
 >  conceptTableViewer.setContentProvider(conceptTableViewerCont entProviderList);
 >
 > IObservableMap[] conceptTableViewerLabelProviderMaps =
 >  BeansObservables.observeMaps(conceptTableViewerContentProvid erList.getKnownElements(),
 > Concept.class, new String[]{"description", "ecid", "statusId",
 > "conceptTypeId"});
 > IObservableList cptListConceptsObserveList =
 > BeansObservables.observeList(Realm.getDefault(), cptList, "concepts");
 > bindingContext.bindValue(comboSelectionObserveWidget,
 > conceptTableViewerConceptTypeIdObserveDetailValue, null, null);
 > ===============
 > This does bind the concept model's Concept Type ID to the ComboViewer,
 > but it displays as the ECID, and not the dereferenced value ("Active").
 > Also, selections made in the ComboViewer are sent to the
 > setConceptTypeID as their value, and not the underlying key (UUID).
 >
 > I know that there is something very basic here that I'm doing wrong, and
 > I just can't find it.  The ArrayContentProvider is populated with
 > GlobalPair objects, which have both the key and value exposed, and the
 > label provider works with it just fine (get/setGlobalID,
 > get/setGlobalDisp).  Can any direct me to an example or see where I've
 > gone wrong here.  I'm way past being eternally grateful.  I'm also
 > wondering it my answer may lie in having my extended HashMap implement
 > IObservableMap, but I'm trying to work within the framework as it's
 > intended to be used.
 >
 > Thanks in advance,
 >
 > Lawrence
 >
 >
 
 
 --
 B e s t S o l u t i o n . at
 ------------------------------------------------------------ --------
 Tom Schindl                                          JFace-Committer
 ------------------------------------------------------------ --------
 |  |  |  |  |  |  |  |  |  |  | 
| Re: Requesting JFace ComboViewer data binding help [message #329515 is a reply to message #329514] | Thu, 26 June 2008 12:56  |  | 
| Eclipse User  |  |  |  |  | That's not a problem for JFace-Viewers because you can set an element comparer on it :-)
 
 Tom
 
 Lawrence schrieb:
 > Thanks again for the insights.  Your assumption about B) is correct--it
 > is database-centric, and really should be from my current
 > point-of-view.  I think that this means that I'll take approach A),
 > which purely allows me to observe the UUIDs and update the model, and
 > use the HashMap to power the label provider.
 >
 > My follow-up then is this: Could I be going at this all wrong? Are you
 > aware of any posted scenarios that illustrate using a ListViewer or
 > ComboViewer which displays information from a coded table ('US' =
 > "United States," "DE" = Germany, etc.), where then codes are bound to
 > the model but the list of values comes from a different model?
 >
 
 
 --
 B e s t S o l u t i o n . at
 ------------------------------------------------------------ --------
 Tom Schindl                                          JFace-Committer
 ------------------------------------------------------------ --------
 |  |  |  | 
 
 
 Current Time: Fri Oct 31 18:09:18 EDT 2025 
 Powered by FUDForum . Page generated in 0.45131 seconds |