Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Programmatically populated dropdown for string attribute?
Programmatically populated dropdown for string attribute? [message #508450] Mon, 18 January 2010 22:03 Go to next message
Christoph Wienands is currently offline Christoph WienandsFriend
Messages: 55
Registered: July 2009
Member
Hello all,

I am trying to figure out how make a dropdown available for string attributes of an ecore class (similar to enum values), where the values for the dropdown have been provided programmatically.

I can't use an enum because the values are dynamically derived from existing model content (a reference to an existing model object does not work either).

Just to make sure, I am talking about the Properties window/editor that is generated from an EMF model.

I looked at the configurable EMF properties and at the generated code but I couldn't find anything obvious. Any idea?

Thanks a lot, Christoph
Re: Programmatically populated dropdown for string attribute? [message #508603 is a reply to message #508450] Tue, 19 January 2010 15:30 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Christoph,

You can override the getChoiceOfValues method of the property
descriptor; it's been explained a few times already so no doubt a quick
search will find the references.


Christoph Wienands wrote:
> Hello all,
>
> I am trying to figure out how make a dropdown available for string
> attributes of an ecore class (similar to enum values), where the
> values for the dropdown have been provided programmatically.
>
> I can't use an enum because the values are dynamically derived from
> existing model content (a reference to an existing model object does
> not work either).
>
> Just to make sure, I am talking about the Properties window/editor
> that is generated from an EMF model.
>
> I looked at the configurable EMF properties and at the generated code
> but I couldn't find anything obvious. Any idea?
>
> Thanks a lot, Christoph


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Programmatically populated dropdown for string attribute? [message #508686 is a reply to message #508603] Tue, 19 January 2010 20:33 Go to previous message
Christoph Wienands is currently offline Christoph WienandsFriend
Messages: 55
Registered: July 2009
Member
Hey Ed,

this was exactly the hint I needed. I couldn't really find any other good description of how to do this but some debugging and library digging did the trick.

In case someone else is trying to solve the same problem, here is how I did it:

1) In the .edit project of your language, identify the item provider that corresponds with the model class which contains the EAttribute you want to dropdownize.

2) In that class, the method 'getPropertyDescriptors' adds property descriptors for each attribute and reference. Find the method that adds the descriptor for the attribute that will get the dropdown.

3) In that method, replace the call to createItemPropertyDescriptor with the instantiation of a custom item property descriptor. Don't forget to mark that method with '@generated NOT'. Otherwise you'll lose those changes after the next EMF regeneration.

4) Create this custom item property descriptor by deriving it from ItemPropertyDescriptor. Now you only have to override the getChoiceOfValues method and programmatically determine and return the values for the combo box.

Have fun, Christoph

[Updated on: Tue, 19 January 2010 20:34]

Report message to a moderator

Previous Topic:Problem with performance when loading big models
Next Topic:EMF Databinding with jface tableviewer and celleditors
Goto Forum:
  


Current Time: Sat Apr 20 02:42:42 GMT 2024

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

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

Back to the top