Attaching properties from one Model Element to another [message #1661465] |
Mon, 09 March 2015 16:46 |
|
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 |
Ed Merks Messages: 33141 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
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Powered by
FUDForum. Page generated in 0.03305 seconds