Home » Modeling » EMF » Retrieve ItemProvider from EObject
| | | |
Re: Retrieve ItemProvider from EObject [message #513324 is a reply to message #513314] |
Tue, 09 February 2010 13:42 |
Ed Merks Messages: 33140 Registered: July 2009 |
Senior Member |
|
|
Comments below.
Martin Tauber wrote:
> Oops, do I have to change the ItemProvider to a statefull
> itemProvider, since it now carries the referenced Object?
Hmmm. I'm not sure. The example code creates new property descriptors
each time...
>
> Am 09.02.10 18:59, schrieb Martin Tauber:
>> Hi Ed,
>>
>> Hm - I checked ... TreeNodeItemProvider.getPropertyDescriptors(Object)
>> expects a TreeNode as an argument ...
Well yes, it's the item provider for TreeNode. You of course will have
a different type of object...
>>
>> Here is the source of TreeNodeItemProvider ...
>> /**
>> * This returns the property descriptors for the adapted class.
>> */
>> @Override
>> public List<IItemPropertyDescriptor> getPropertyDescriptors(Object
>> object)
>> {
>> TreeNode treeNode = (TreeNode)object; <===================
>> itemPropertyDescriptors = new ArrayList<IItemPropertyDescriptor>();
>>
>> -----
>>
>> So I searched a little bit and found AdapterFactoryDelagate and added
>> this sequence to my MibObjectItemProvider code
>>
>> @Override
>> public List<IItemPropertyDescriptor> getPropertyDescriptors(Object
>> object) {
>> if (itemPropertyDescriptors == null) {
>> super.getPropertyDescriptors(object);
So you're caching the descriptors unlike the TreeNode case. You'll need
to be stateful for sure in that case.
>>
>> MibObject mibObject = (MibObject)object;
>> if (mibObject.getDefinition() != null) {
>> AdapterFactoryItemDelegator delegator = new
>> AdapterFactoryItemDelegator(((ComposeableAdapterFactory)adap terFactory).getRootAdapterFactory());
>>
>>
>>
>> List<IItemPropertyDescriptor> definitionProperties =
>> delegator.getPropertyDescriptors(mibObject.getDefinition());
What happened to the decorators that are in the example I pointed you to?
>> itemPropertyDescriptors.addAll(definitionProperties);
>> }
>>
>> ....
>> }
>> return itemPropertyDescriptors;
>> }
>> -------
>>
>> Well this shows the property labels correctly in the property sheet, but
>> the values are empty. I have the impression that the origional object is
>> used to detect the values (mibObject) and not the referenced object
>> mibObject.getDefinition() ...
Well yes, that's why I pointed you at a working example.
>>
>> Any Ideas are welcome!
>>
>>
>> Am 08.02.10 23:43, schrieb Ed Merks:
>>> Martin,
>>>
>>> Have a look at TreeNodeItemProvider.getPropertyDescriptors exactly what
>>> you describe.
>>>
>>>
>>> Martin Tauber wrote:
>>>> Hello Everybody,
>>>>
>>>> I want to get an ItemProvider for a given EObject. How do I do that?
>>>> (The Background is that I have a EObject where one feature is a
>>>> reference to another EObject. Now I want to extend the ItemProvider
>>>> for the first EObject to add it's own PropertyDescriptors as well as
>>>> the PropertyDescriptors of the referenced EObject. So my Idea was to
>>>> do something like:
>>>>
>>>> getPropertyDescriptors(Object o) {
>>>> if (itemPropertyDescriptors == null) {
>>>> super.getPropertyDescriptors(object);
>>>>
>>>> List<IItemPropertyDescriptor> refPds =
>>>> getItemProvider(object.getReference).getPropertyDescriptors( o.getReference());
>>>>
>>>>
>>>>
>>>>
>>>> itemPropertyDescriptors.addAll(refPds);
>>>>
>>>> addNamePropertyDescriptor(o);
>>>> ....
>>>> }
>>>>
>>>> Regards
>>>> Martin
>>
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Re: Retrieve ItemProvider from EObject [message #513331 is a reply to message #513324] |
Tue, 09 February 2010 14:10 |
Martin Tauber Messages: 122 Registered: July 2009 |
Senior Member |
|
|
Hi Ed,
sorry, I don't see the example ... I thought
TreeNodeItemProvider.getPropertyDescriptors was the method I should call
are u saying the code in that method is the code I'm looking for?
Regards
Martin
Am 09.02.10 19:36, schrieb Ed Merks:
> Comments below.
>
> Martin Tauber wrote:
>> Oops, do I have to change the ItemProvider to a statefull
>> itemProvider, since it now carries the referenced Object?
> Hmmm. I'm not sure. The example code creates new property descriptors
> each time...
>>
>> Am 09.02.10 18:59, schrieb Martin Tauber:
>>> Hi Ed,
>>>
>>> Hm - I checked ... TreeNodeItemProvider.getPropertyDescriptors(Object)
>>> expects a TreeNode as an argument ...
> Well yes, it's the item provider for TreeNode. You of course will have a
> different type of object...
>>>
>>> Here is the source of TreeNodeItemProvider ...
>>> /**
>>> * This returns the property descriptors for the adapted class.
>>> */
>>> @Override
>>> public List<IItemPropertyDescriptor> getPropertyDescriptors(Object
>>> object)
>>> {
>>> TreeNode treeNode = (TreeNode)object; <===================
>>> itemPropertyDescriptors = new ArrayList<IItemPropertyDescriptor>();
>>>
>>> -----
>>>
>>> So I searched a little bit and found AdapterFactoryDelagate and added
>>> this sequence to my MibObjectItemProvider code
>>>
>>> @Override
>>> public List<IItemPropertyDescriptor> getPropertyDescriptors(Object
>>> object) {
>>> if (itemPropertyDescriptors == null) {
>>> super.getPropertyDescriptors(object);
> So you're caching the descriptors unlike the TreeNode case. You'll need
> to be stateful for sure in that case.
>>>
>>> MibObject mibObject = (MibObject)object;
>>> if (mibObject.getDefinition() != null) {
>>> AdapterFactoryItemDelegator delegator = new
>>> AdapterFactoryItemDelegator(((ComposeableAdapterFactory)adap terFactory).getRootAdapterFactory());
>>>
>>>
>>>
>>> List<IItemPropertyDescriptor> definitionProperties =
>>> delegator.getPropertyDescriptors(mibObject.getDefinition());
> What happened to the decorators that are in the example I pointed you to?
>>> itemPropertyDescriptors.addAll(definitionProperties);
>>> }
>>>
>>> ....
>>> }
>>> return itemPropertyDescriptors;
>>> }
>>> -------
>>>
>>> Well this shows the property labels correctly in the property sheet, but
>>> the values are empty. I have the impression that the origional object is
>>> used to detect the values (mibObject) and not the referenced object
>>> mibObject.getDefinition() ...
> Well yes, that's why I pointed you at a working example.
>>>
>>> Any Ideas are welcome!
>>>
>>>
>>> Am 08.02.10 23:43, schrieb Ed Merks:
>>>> Martin,
>>>>
>>>> Have a look at TreeNodeItemProvider.getPropertyDescriptors exactly what
>>>> you describe.
>>>>
>>>>
>>>> Martin Tauber wrote:
>>>>> Hello Everybody,
>>>>>
>>>>> I want to get an ItemProvider for a given EObject. How do I do that?
>>>>> (The Background is that I have a EObject where one feature is a
>>>>> reference to another EObject. Now I want to extend the ItemProvider
>>>>> for the first EObject to add it's own PropertyDescriptors as well as
>>>>> the PropertyDescriptors of the referenced EObject. So my Idea was to
>>>>> do something like:
>>>>>
>>>>> getPropertyDescriptors(Object o) {
>>>>> if (itemPropertyDescriptors == null) {
>>>>> super.getPropertyDescriptors(object);
>>>>>
>>>>> List<IItemPropertyDescriptor> refPds =
>>>>> getItemProvider(object.getReference).getPropertyDescriptors( o.getReference());
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> itemPropertyDescriptors.addAll(refPds);
>>>>>
>>>>> addNamePropertyDescriptor(o);
>>>>> ....
>>>>> }
>>>>>
>>>>> Regards
>>>>> Martin
>>>
>>
|
|
|
Re: Retrieve ItemProvider from EObject [message #513336 is a reply to message #513331] |
Tue, 09 February 2010 19:09 |
Ed Merks Messages: 33140 Registered: July 2009 |
Senior Member |
|
|
Martin,
Yes, that code is an example/sample/prototype/pattern to emulate.
Martin Tauber wrote:
> Hi Ed,
>
> sorry, I don't see the example ... I thought
> TreeNodeItemProvider.getPropertyDescriptors was the method I should
> call are u saying the code in that method is the code I'm looking for?
>
> Regards
> Martin
>
> Am 09.02.10 19:36, schrieb Ed Merks:
>> Comments below.
>>
>> Martin Tauber wrote:
>>> Oops, do I have to change the ItemProvider to a statefull
>>> itemProvider, since it now carries the referenced Object?
>> Hmmm. I'm not sure. The example code creates new property descriptors
>> each time...
>>>
>>> Am 09.02.10 18:59, schrieb Martin Tauber:
>>>> Hi Ed,
>>>>
>>>> Hm - I checked ... TreeNodeItemProvider.getPropertyDescriptors(Object)
>>>> expects a TreeNode as an argument ...
>> Well yes, it's the item provider for TreeNode. You of course will have a
>> different type of object...
>>>>
>>>> Here is the source of TreeNodeItemProvider ...
>>>> /**
>>>> * This returns the property descriptors for the adapted class.
>>>> */
>>>> @Override
>>>> public List<IItemPropertyDescriptor> getPropertyDescriptors(Object
>>>> object)
>>>> {
>>>> TreeNode treeNode = (TreeNode)object; <===================
>>>> itemPropertyDescriptors = new ArrayList<IItemPropertyDescriptor>();
>>>>
>>>> -----
>>>>
>>>> So I searched a little bit and found AdapterFactoryDelagate and added
>>>> this sequence to my MibObjectItemProvider code
>>>>
>>>> @Override
>>>> public List<IItemPropertyDescriptor> getPropertyDescriptors(Object
>>>> object) {
>>>> if (itemPropertyDescriptors == null) {
>>>> super.getPropertyDescriptors(object);
>> So you're caching the descriptors unlike the TreeNode case. You'll need
>> to be stateful for sure in that case.
>>>>
>>>> MibObject mibObject = (MibObject)object;
>>>> if (mibObject.getDefinition() != null) {
>>>> AdapterFactoryItemDelegator delegator = new
>>>> AdapterFactoryItemDelegator(((ComposeableAdapterFactory)adap terFactory).getRootAdapterFactory());
>>>>
>>>>
>>>>
>>>>
>>>> List<IItemPropertyDescriptor> definitionProperties =
>>>> delegator.getPropertyDescriptors(mibObject.getDefinition());
>> What happened to the decorators that are in the example I pointed you
>> to?
>>>> itemPropertyDescriptors.addAll(definitionProperties);
>>>> }
>>>>
>>>> ....
>>>> }
>>>> return itemPropertyDescriptors;
>>>> }
>>>> -------
>>>>
>>>> Well this shows the property labels correctly in the property
>>>> sheet, but
>>>> the values are empty. I have the impression that the origional
>>>> object is
>>>> used to detect the values (mibObject) and not the referenced object
>>>> mibObject.getDefinition() ...
>> Well yes, that's why I pointed you at a working example.
>>>>
>>>> Any Ideas are welcome!
>>>>
>>>>
>>>> Am 08.02.10 23:43, schrieb Ed Merks:
>>>>> Martin,
>>>>>
>>>>> Have a look at TreeNodeItemProvider.getPropertyDescriptors exactly
>>>>> what
>>>>> you describe.
>>>>>
>>>>>
>>>>> Martin Tauber wrote:
>>>>>> Hello Everybody,
>>>>>>
>>>>>> I want to get an ItemProvider for a given EObject. How do I do that?
>>>>>> (The Background is that I have a EObject where one feature is a
>>>>>> reference to another EObject. Now I want to extend the ItemProvider
>>>>>> for the first EObject to add it's own PropertyDescriptors as well as
>>>>>> the PropertyDescriptors of the referenced EObject. So my Idea was to
>>>>>> do something like:
>>>>>>
>>>>>> getPropertyDescriptors(Object o) {
>>>>>> if (itemPropertyDescriptors == null) {
>>>>>> super.getPropertyDescriptors(object);
>>>>>>
>>>>>> List<IItemPropertyDescriptor> refPds =
>>>>>> getItemProvider(object.getReference).getPropertyDescriptors( o.getReference());
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> itemPropertyDescriptors.addAll(refPds);
>>>>>>
>>>>>> addNamePropertyDescriptor(o);
>>>>>> ....
>>>>>> }
>>>>>>
>>>>>> Regards
>>>>>> Martin
>>>>
>>>
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Re: Retrieve ItemProvider from EObject [message #513338 is a reply to message #513331] |
Tue, 09 February 2010 19:15 |
Martin Tauber Messages: 122 Registered: July 2009 |
Senior Member |
|
|
ok, got it, copied the code and it works ... Now I have to think about
why it actually works ...
Here's the code for everybody interested ...
@Override
public List<IItemPropertyDescriptor> getPropertyDescriptors(Object object) {
List<IItemPropertyDescriptor> itemPropertyDescriptors = new
ArrayList<IItemPropertyDescriptor>();
MibObject mibObject = (MibObject)object;
if (mibObject.getDefinition() != null) {
AdapterFactoryItemDelegator delegator = new
AdapterFactoryItemDelegator(((ComposeableAdapterFactory)adap terFactory).getRootAdapterFactory());
for (IItemPropertyDescriptor itemPropertyDescriptor :
delegator.getPropertyDescriptors(mibObject.getDefinition()))
{
itemPropertyDescriptors.add(new
ItemPropertyDescriptorDecorator(mibObject.getDefinition(),
itemPropertyDescriptor));
}
}
return itemPropertyDescriptors;
}
Am 09.02.10 19:59, schrieb Martin Tauber:
> Hi Ed,
>
> sorry, I don't see the example ... I thought
> TreeNodeItemProvider.getPropertyDescriptors was the method I should call
> are u saying the code in that method is the code I'm looking for?
>
> Regards
> Martin
>
> Am 09.02.10 19:36, schrieb Ed Merks:
>> Comments below.
>>
>> Martin Tauber wrote:
>>> Oops, do I have to change the ItemProvider to a statefull
>>> itemProvider, since it now carries the referenced Object?
>> Hmmm. I'm not sure. The example code creates new property descriptors
>> each time...
>>>
>>> Am 09.02.10 18:59, schrieb Martin Tauber:
>>>> Hi Ed,
>>>>
>>>> Hm - I checked ... TreeNodeItemProvider.getPropertyDescriptors(Object)
>>>> expects a TreeNode as an argument ...
>> Well yes, it's the item provider for TreeNode. You of course will have a
>> different type of object...
>>>>
>>>> Here is the source of TreeNodeItemProvider ...
>>>> /**
>>>> * This returns the property descriptors for the adapted class.
>>>> */
>>>> @Override
>>>> public List<IItemPropertyDescriptor> getPropertyDescriptors(Object
>>>> object)
>>>> {
>>>> TreeNode treeNode = (TreeNode)object; <===================
>>>> itemPropertyDescriptors = new ArrayList<IItemPropertyDescriptor>();
>>>>
>>>> -----
>>>>
>>>> So I searched a little bit and found AdapterFactoryDelagate and added
>>>> this sequence to my MibObjectItemProvider code
>>>>
>>>> @Override
>>>> public List<IItemPropertyDescriptor> getPropertyDescriptors(Object
>>>> object) {
>>>> if (itemPropertyDescriptors == null) {
>>>> super.getPropertyDescriptors(object);
>> So you're caching the descriptors unlike the TreeNode case. You'll need
>> to be stateful for sure in that case.
>>>>
>>>> MibObject mibObject = (MibObject)object;
>>>> if (mibObject.getDefinition() != null) {
>>>> AdapterFactoryItemDelegator delegator = new
>>>> AdapterFactoryItemDelegator(((ComposeableAdapterFactory)adap terFactory).getRootAdapterFactory());
>>>>
>>>>
>>>>
>>>>
>>>> List<IItemPropertyDescriptor> definitionProperties =
>>>> delegator.getPropertyDescriptors(mibObject.getDefinition());
>> What happened to the decorators that are in the example I pointed you to?
>>>> itemPropertyDescriptors.addAll(definitionProperties);
>>>> }
>>>>
>>>> ....
>>>> }
>>>> return itemPropertyDescriptors;
>>>> }
>>>> -------
>>>>
>>>> Well this shows the property labels correctly in the property sheet,
>>>> but
>>>> the values are empty. I have the impression that the origional
>>>> object is
>>>> used to detect the values (mibObject) and not the referenced object
>>>> mibObject.getDefinition() ...
>> Well yes, that's why I pointed you at a working example.
>>>>
>>>> Any Ideas are welcome!
>>>>
>>>>
>>>> Am 08.02.10 23:43, schrieb Ed Merks:
>>>>> Martin,
>>>>>
>>>>> Have a look at TreeNodeItemProvider.getPropertyDescriptors exactly
>>>>> what
>>>>> you describe.
>>>>>
>>>>>
>>>>> Martin Tauber wrote:
>>>>>> Hello Everybody,
>>>>>>
>>>>>> I want to get an ItemProvider for a given EObject. How do I do that?
>>>>>> (The Background is that I have a EObject where one feature is a
>>>>>> reference to another EObject. Now I want to extend the ItemProvider
>>>>>> for the first EObject to add it's own PropertyDescriptors as well as
>>>>>> the PropertyDescriptors of the referenced EObject. So my Idea was to
>>>>>> do something like:
>>>>>>
>>>>>> getPropertyDescriptors(Object o) {
>>>>>> if (itemPropertyDescriptors == null) {
>>>>>> super.getPropertyDescriptors(object);
>>>>>>
>>>>>> List<IItemPropertyDescriptor> refPds =
>>>>>> getItemProvider(object.getReference).getPropertyDescriptors( o.getReference());
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> itemPropertyDescriptors.addAll(refPds);
>>>>>>
>>>>>> addNamePropertyDescriptor(o);
>>>>>> ....
>>>>>> }
>>>>>>
>>>>>> Regards
>>>>>> Martin
>>>>
>>>
>
|
|
| | | |
Re: Retrieve ItemProvider from EObject [message #513374 is a reply to message #513371] |
Tue, 09 February 2010 21:43 |
Ed Merks Messages: 33140 Registered: July 2009 |
Senior Member |
|
|
AJ,
Comments below.
AJ wrote:
> Ed,
>
> If the adapter is not already created on the target, then this should
> catch/fix that:
>
> if (itemPropertySource == null) {
> AdapterFactory adapterFactory = new
> ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Reg
> istry.INSTANCE);
The point is that the current adapter factory is already part of such a
composed adapter factory so best to reuse it to avoid creating yet more
new adapters.
>
> itemPropertySource = (IItemPropertySource)
> adapterFactory.adapt(object, IItemPropertySource.class);
> }
>
> I am not sure I follow the part about the decorators though.
The descriptors, like the item providers themselves,are always passed
the object upon which to act, so if you gather descriptors for some
other object to which you refer and don't decorate those descriptors,
they'll eventually be passed the original object not the referenced
object for whom they are really the descriptors.
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Goto Forum:
Current Time: Thu Apr 25 11:28:39 GMT 2024
Powered by FUDForum. Page generated in 0.05616 seconds
|