Home » Modeling » EMF » Combo-Box
| Combo-Box [message #398519] |
Tue, 14 February 2006 04:00  |
Eclipse User |
|
|
|
Hi,
I was wondering about the correct way how to implement a combobox to
display an enumeration.
First I tried by populating the ComboBox with values from
IItemPropertyDescriptor.getChoiceOfValues(objectToDisplay), which really
worked fine. But the listener on the combobox only returned strings and
I didn't get the propertyDescriptor to accept the strings. I guess it
wants an AbstractEnumerator, the literal, right? But I don't see an easy
way how to get that literal.
Next I thought, as cool as EMF is I can certainly use a ComboViewer. ;-)
When I do:
comboViewer.setContentProvider(new
AdapterFactoryContentProvider(adapterFactory))
I think Eclipse already makes the comboBox the right size (width as well
as height), but the options in the comboBox are empty. I do know that I
need to comboViewer.setInput(object), to populate the comboBox, but what
argument do I pass? My intuitive approach of passing propertyDescriptor
as argument doesn't work.
If I think about the contentProvider I chose, I don't get rid of the
feeling, that it is too large or something. In fact the adapterFactory
describes the whole model and I only need the literals of the
enumeration property.
Do have any hints for me, perhaps a sample I didn't find?
Regards,
Oliver
|
|
|
| Re: Combo-Box [message #398522 is a reply to message #398519] |
Tue, 14 February 2006 05:04   |
Eclipse User |
|
|
|
Hi,
> I guess it wants an AbstractEnumerator, the literal, right?
I checked that one with the debugger and it's just the way I expected
it. The propertyDescriptor can't set the property to a string value,
because for this property it needs an EEnum. For an example model I
tried getting the literal from the according category class which worked
really fine. But how do I do this on a generic base. I mean, I have the
category or at least the propertyDescriptor knows about it's displayName
and it's description, so I guess I can get the category somehow. And I
have the string. If I could figure out how to get the category I should
be able to solve my problem.
Or am I going down the wrong road anyway?
Regards,
Oliver
Oliver Olesen wrote:
> Hi,
>
> I was wondering about the correct way how to implement a combobox to
> display an enumeration.
>
> First I tried by populating the ComboBox with values from
> IItemPropertyDescriptor.getChoiceOfValues(objectToDisplay), which really
> worked fine. But the listener on the combobox only returned strings and
> I didn't get the propertyDescriptor to accept the strings.
>
> Next I thought, as cool as EMF is I can certainly use a ComboViewer. ;-)
> When I do:
> comboViewer.setContentProvider(new
> AdapterFactoryContentProvider(adapterFactory))
> I think Eclipse already makes the comboBox the right size (width as well
> as height), but the options in the comboBox are empty. I do know that I
> need to comboViewer.setInput(object), to populate the comboBox, but what
> argument do I pass? My intuitive approach of passing propertyDescriptor
> as argument doesn't work.
>
> If I think about the contentProvider I chose, I don't get rid of the
> feeling, that it is too large or something. In fact the adapterFactory
> describes the whole model and I only need the literals of the
> enumeration property.
>
> Do have any hints for me, perhaps a sample I didn't find?
>
> Regards,
>
> Oliver
|
|
|
| Re: Combo-Box [message #398525 is a reply to message #398519] |
Tue, 14 February 2006 11:29   |
Eclipse User |
|
|
|
Hi Olivier,
JFace's combobox does return string. In the generated editors' creation
wizards, the returned string is compared one by one to find the selected
object. But you could either retrieve the index and, as the
getChoicesOfValues() computed collection is a list, use that index to
get the object.
Did not look at the ComboViewer, however if it is a standard viewer, you
might expect the contentProvider.getElements() is called with the combo
input object. I think the AdapterFactoryContentProvider implementation
of getElements(o) delegates the getChildren(o). So this might not be
adesuate for you use case.
Didier.
Oliver Olesen wrote:
> Hi,
>
> I was wondering about the correct way how to implement a combobox to
> display an enumeration.
>
> First I tried by populating the ComboBox with values from
> IItemPropertyDescriptor.getChoiceOfValues(objectToDisplay), which really
> worked fine. But the listener on the combobox only returned strings and
> I didn't get the propertyDescriptor to accept the strings. I guess it
> wants an AbstractEnumerator, the literal, right? But I don't see an easy
> way how to get that literal.
>
> Next I thought, as cool as EMF is I can certainly use a ComboViewer. ;-)
> When I do:
> comboViewer.setContentProvider(new
> AdapterFactoryContentProvider(adapterFactory))
> I think Eclipse already makes the comboBox the right size (width as well
> as height), but the options in the comboBox are empty. I do know that I
> need to comboViewer.setInput(object), to populate the comboBox, but what
> argument do I pass? My intuitive approach of passing propertyDescriptor
> as argument doesn't work.
>
> If I think about the contentProvider I chose, I don't get rid of the
> feeling, that it is too large or something. In fact the adapterFactory
> describes the whole model and I only need the literals of the
> enumeration property.
>
> Do have any hints for me, perhaps a sample I didn't find?
>
> Regards,
>
> Oliver
|
|
|
| Re: Combo-Box [message #398527 is a reply to message #398525] |
Tue, 14 February 2006 05:48   |
Eclipse User |
|
|
|
Hi Didier,
> But you could either retrieve the index and, as the
> getChoicesOfValues() computed collection is a list, use that index to
> get the object.
The solutions you provided works well. However it feels a bit unstable
counting from the choiceValues. For example, I want to be able to add
the "" to the options, because otherwise you cannot unset the comboBox
at the moment. And if I do that, the index shifts up +1. Subtracting 1
before comparing comboBox-Index to choiceValue-Arrayposition is a bit
nasty, isn't it? Like a bad smell coming through a broken window or
something ;-)
Thanks a lot for you solution! As long as I don't come up with something
better I'll do it that way.
Oliver
Ptitjes wrote:
> Hi Olivier,
>
> JFace's combobox does return string. In the generated editors' creation
> wizards, the returned string is compared one by one to find the selected
> object. But you could either retrieve the index and, as the
> getChoicesOfValues() computed collection is a list, use that index to
> get the object.
>
> Did not look at the ComboViewer, however if it is a standard viewer, you
> might expect the contentProvider.getElements() is called with the combo
> input object. I think the AdapterFactoryContentProvider implementation
> of getElements(o) delegates the getChildren(o). So this might not be
> adesuate for you use case.
>
> Didier.
>
> Oliver Olesen wrote:
>
>> Hi,
>>
>> I was wondering about the correct way how to implement a combobox to
>> display an enumeration.
>>
>> First I tried by populating the ComboBox with values from
>> IItemPropertyDescriptor.getChoiceOfValues(objectToDisplay), which
>> really worked fine. But the listener on the combobox only returned
>> strings and I didn't get the propertyDescriptor to accept the strings.
>> I guess it wants an AbstractEnumerator, the literal, right? But I
>> don't see an easy way how to get that literal.
>>
>> Next I thought, as cool as EMF is I can certainly use a ComboViewer.
>> ;-) When I do:
>> comboViewer.setContentProvider(new
>> AdapterFactoryContentProvider(adapterFactory))
>> I think Eclipse already makes the comboBox the right size (width as
>> well as height), but the options in the comboBox are empty. I do know
>> that I need to comboViewer.setInput(object), to populate the comboBox,
>> but what argument do I pass? My intuitive approach of passing
>> propertyDescriptor as argument doesn't work.
>>
>> If I think about the contentProvider I chose, I don't get rid of the
>> feeling, that it is too large or something. In fact the adapterFactory
>> describes the whole model and I only need the literals of the
>> enumeration property.
>>
>> Do have any hints for me, perhaps a sample I didn't find?
>>
>> Regards,
>>
>> Oliver
|
|
|
| Re: Combo-Box [message #398529 is a reply to message #398527] |
Tue, 14 February 2006 11:55  |
Eclipse User |
|
|
|
Olivier,
This is the way it is done in emf's ExtendedPropertySheet. When the
attribute/feature is nullable, null is added to the choices of values.
So this might be a hack, but the only way to do it. :)
Didier.
Oliver Olesen wrote:
> Hi Didier,
>
>> But you could either retrieve the index and, as the
>> getChoicesOfValues() computed collection is a list, use that index to
>> get the object.
>
>
> The solutions you provided works well. However it feels a bit unstable
> counting from the choiceValues. For example, I want to be able to add
> the "" to the options, because otherwise you cannot unset the comboBox
> at the moment. And if I do that, the index shifts up +1. Subtracting 1
> before comparing comboBox-Index to choiceValue-Arrayposition is a bit
> nasty, isn't it? Like a bad smell coming through a broken window or
> something ;-)
>
> Thanks a lot for you solution! As long as I don't come up with something
> better I'll do it that way.
>
> Oliver
|
|
|
Goto Forum:
Current Time: Wed Nov 05 13:54:23 EST 2025
Powered by FUDForum. Page generated in 0.03929 seconds
|