Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Attaching properties from one Model Element to another(How to correctly built the getPropertyDescriptors?)
Attaching properties from one Model Element to another [message #1661465] Mon, 09 March 2015 16:46 Go to next message
Michael Jastram is currently offline Michael JastramFriend
Messages: 233
Registered: April 2010
Location: Düsseldorf, Germany
Senior Member
Howdy,

In summary, I have some properties that I want to edit through its Parent. I suspect that I don't properly build the PropertyDescriptors. Help!

Here are the Details. I have the following parent-child relationship:

SpecHierarchy -> SpecObject

In other words, each SpecHierarchy references exactly one SpecObject. I would like to add the SpecObject's properties to the SpecHierarchy, so that they both appear in the properties view of the SpecHierarchy.

To complicate things, both have the same superclass. Therefore, they will have the same inherited attributes (and some more, of course). To accommodate this, I give them separate categories.

Here is the (slightly simplified) code, from the ItemProvider for the SpecHierarchies:

public List<IItemPropertyDescriptor> getPropertyDescriptors(Object specHierarchy) {
		super.getPropertyDescriptors(specHierarchy);  // populates itemPropertyDescriptors

		// We need to separate the SpecHierarchy's properties from the
		// SpecObject's properties. Therefore, we rename the Category.
		ArrayList<IItemPropertyDescriptor> newDescriptors = new ArrayList<IItemPropertyDescriptor>();
		for (IItemPropertyDescriptor descriptor : itemPropertyDescriptors) {
			newDescriptors.add(new ItemPropertyDescriptorDecorator(
					specHierarchy, descriptor) {
				public String getCategory(Object thisObject) {
					return getString("_UI_SpecHierarchyPropertyCategory");
				}
			});
		}

                // Replace the old descriptors
		itemPropertyDescriptors = newDescriptors;

		SpecObject specObject = ((SpecHierarchy) specHierarchy).getObject();
		if (specObject != null) {
                        // Add the SpecObject's property descriptors
			ItemProviderAdapter specObjectItemProvider = ProrUtil
					.getItemProvider(adapterFactory, specObject);
			itemPropertyDescriptors.addAll(specObjectItemProvider
					.getPropertyDescriptors(specObject));
		}
		return itemPropertyDescriptors;
	}


This code does not work: The property editor shows each property from the SpecObject twice, and upon selection changes, there are ArrayIndexOutOfBoundsExceptions.

Any ideas how I correctly add the SpecObject's property descriptors?

Thanks,

- Michael
Re: Attaching properties from one Model Element to another [message #1661542 is a reply to message #1661465] Mon, 09 March 2015 17:32 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 30467
Registered: July 2009
Senior Member
Michael,

I think you'll need to be more careful about recomputing the property
descriptors each time rather than the cached approach you'll get by
default. Or the item provider needs to be stateful to reflect the
different list for each instance. Start by setting a breakpoint and see
how often it's being called and how you're likely making the list bigger
and bigger each time...


On 09/03/2015 5:46 PM, Michael Jastram wrote:
> Howdy,
>
> In summary, I have some properties that I want to edit through its
> Parent. I suspect that I don't properly build the
> PropertyDescriptors. Help!
>
> Here are the Details. I have the following parent-child relationship:
>
> SpecHierarchy -> SpecObject
>
> In other words, each SpecHierarchy references exactly one SpecObject.
> I would like to add the SpecObject's properties to the SpecHierarchy,
> so that they both appear in the properties view of the SpecHierarchy.
> To complicate things, both have the same superclass. Therefore, they
> will have the same inherited attributes (and some more, of course).
> To accommodate this, I give them separate categories.
>
> Here is the (slightly simplified) code, from the ItemProvider for the
> SpecHierarchies:
>
> public List<IItemPropertyDescriptor> getPropertyDescriptors(Object
> specHierarchy) {
> super.getPropertyDescriptors(specHierarchy); // populates
> itemPropertyDescriptors
>
> // We need to separate the SpecHierarchy's properties from the
> // SpecObject's properties. Therefore, we rename the Category.
> ArrayList<IItemPropertyDescriptor> newDescriptors = new
> ArrayList<IItemPropertyDescriptor>();
> for (IItemPropertyDescriptor descriptor :
> itemPropertyDescriptors) {
> newDescriptors.add(new ItemPropertyDescriptorDecorator(
> specHierarchy, descriptor) {
> public String getCategory(Object thisObject) {
> return
> getString("_UI_SpecHierarchyPropertyCategory");
> }
> });
> }
>
> // Replace the old descriptors
> itemPropertyDescriptors = newDescriptors;
>
> SpecObject specObject = ((SpecHierarchy)
> specHierarchy).getObject();
> if (specObject != null) {
> // Add the SpecObject's property descriptors
> ItemProviderAdapter specObjectItemProvider = ProrUtil
> .getItemProvider(adapterFactory, specObject);
> itemPropertyDescriptors.addAll(specObjectItemProvider
> .getPropertyDescriptors(specObject));
> }
> return itemPropertyDescriptors;
> }
>
> This code does not work: The property editor shows each property from
> the SpecObject twice, and upon selection changes, there are
> ArrayIndexOutOfBoundsExceptions.
>
> Any ideas how I correctly add the SpecObject's property descriptors?
>
> Thanks,
>
> - Michael
>
Previous Topic:EMF with Maven
Next Topic:Custom resource with non XML persistence
Goto Forum:
  


Current Time: Mon Sep 23 14:07:44 GMT 2019

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

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

Back to the top