Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » Requesting JFace ComboViewer data binding help
Requesting JFace ComboViewer data binding help [message #329491] Thu, 26 June 2008 03:19 Go to next message
Eclipse UserFriend
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 Go to previous messageGo to next message
Eclipse UserFriend
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 #329512 is a reply to message #329495] Thu, 26 June 2008 12:21 Go to previous messageGo to next message
Eclipse UserFriend
Thanks for the response. Conceptually, you have the model correct, except
that the Statuses are represented as a HashTable, while the concepts are
individual model objects.
Re: Requesting JFace ComboViewer data binding help [message #329513 is a reply to message #329512] Thu, 26 June 2008 12:32 Go to previous messageGo to next message
Eclipse UserFriend
Concept {
String description; // Concept 1
String statusId; // "aa854fbb-f9f4-43af-8077-729ee40f3daa"
}


Status {
String uuid; // "aa854fbb-f9f4-43af-8077-729ee40f3daa"
String label; // "ACTIVE"
}

Ok so your problem is that the ComboViewer hold values of Type Status
and you want to restore them in a field (statusId) which only can
restore objects of type string.

The are now 3 possibilities:
a) the input to your ComboViewer are the uuid and the LabelProvider
translates the uuid using some look up mechanism
b) You change your statusId type in Concept to Status I think your model
is to database centric because uuid is the foreign key in your
database model (only a guess)
c) you add a converter for both directions which converts the Status to
a String when you go from ui-to-model and converts the String to a
Status when you go from model-to-ui.

From object oriented point of view b is the appropiate way to go and
your ORM solution translate your Object-Relation to a Database-Releation.

Tom


Lawrence schrieb:
> Thanks for the response. Conceptually, you have the model correct,
> except that the Statuses are represented as a HashTable, while the
> concepts are individual model objects.
>


--
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 #329514 is a reply to message #329513] Thu, 26 June 2008 12:48 Go to previous messageGo to next message
Eclipse UserFriend
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?
Re: Requesting JFace ComboViewer data binding help [message #329515 is a reply to message #329514] Thu, 26 June 2008 12:56 Go to previous message
Eclipse UserFriend
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
------------------------------------------------------------ --------
Previous Topic:Activating a plug-in
Next Topic:Show next page after finish button was clicked
Goto Forum:
  


Current Time: Thu Mar 13 14:04:58 EDT 2025

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

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

Back to the top