Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Retrieve ItemProvider from EObject
Retrieve ItemProvider from EObject [message #513118] Mon, 08 February 2010 22:31 Go to next message
Martin Tauber is currently offline Martin TauberFriend
Messages: 122
Registered: July 2009
Senior Member
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 #513119 is a reply to message #513118] Mon, 08 February 2010 22:43 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
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 #513313 is a reply to message #513119] Tue, 09 February 2010 17:59 Go to previous messageGo to next message
Martin Tauber is currently offline Martin TauberFriend
Messages: 122
Registered: July 2009
Senior Member
Hi Ed,

Hm - I checked ... TreeNodeItemProvider.getPropertyDescriptors(Object)
expects a TreeNode as an argument ...

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);

MibObject mibObject = (MibObject)object;
if (mibObject.getDefinition() != null) {
AdapterFactoryItemDelegator delegator = new
AdapterFactoryItemDelegator(((ComposeableAdapterFactory)adap terFactory).getRootAdapterFactory());

List<IItemPropertyDescriptor> definitionProperties =
delegator.getPropertyDescriptors(mibObject.getDefinition());
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() ...

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 #513314 is a reply to message #513313] Tue, 09 February 2010 18:02 Go to previous messageGo to next message
Martin Tauber is currently offline Martin TauberFriend
Messages: 122
Registered: July 2009
Senior Member
Oops, do I have to change the ItemProvider to a statefull itemProvider,
since it now carries the referenced Object?

Am 09.02.10 18:59, schrieb Martin Tauber:
> Hi Ed,
>
> Hm - I checked ... TreeNodeItemProvider.getPropertyDescriptors(Object)
> expects a TreeNode as an argument ...
>
> 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);
>
> MibObject mibObject = (MibObject)object;
> if (mibObject.getDefinition() != null) {
> AdapterFactoryItemDelegator delegator = new
> AdapterFactoryItemDelegator(((ComposeableAdapterFactory)adap terFactory).getRootAdapterFactory());
>
>
> List<IItemPropertyDescriptor> definitionProperties =
> delegator.getPropertyDescriptors(mibObject.getDefinition());
> 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() ...
>
> 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 #513324 is a reply to message #513314] Tue, 09 February 2010 13:42 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
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 Go to previous messageGo to next message
Martin Tauber is currently offline Martin TauberFriend
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 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
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 Go to previous messageGo to next message
Martin Tauber is currently offline Martin TauberFriend
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 #513360 is a reply to message #513118] Tue, 09 February 2010 20:44 Go to previous messageGo to next message
Al B is currently offline Al BFriend
Messages: 130
Registered: July 2009
Senior Member
You could also do this:

List<IItemPropertyDescriptor> pds = new ArrayList<IItemPropertyDescriptor>();
IItemPropertySource itemPropertySource = (IItemPropertySource) EcoreUtil.getRegisteredAdapter(eObject, IItemPropertySource.class);
if (itemPropertySource != null) {
pds.addAll(itemPropertySource.getPropertyDescriptors(eObject ));
}
Re: Retrieve ItemProvider from EObject [message #513367 is a reply to message #513360] Tue, 09 February 2010 16:04 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
AJ,

This assumes the adapter is already created on the target, which isn't
necessarily a good assumption. It's also important to use decorators if
the descriptors are actually for a different object; remember we
followed a reference from the starting object to a different one.

AJ wrote:
> You could also do this:
>
> List<IItemPropertyDescriptor> pds = new
> ArrayList<IItemPropertyDescriptor>();
> IItemPropertySource itemPropertySource = (IItemPropertySource)
> EcoreUtil.getRegisteredAdapter(eObject, IItemPropertySource.class);
> if (itemPropertySource != null) {
> pds.addAll(itemPropertySource.getPropertyDescriptors(eObject ));
> }


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Retrieve ItemProvider from EObject [message #513371 is a reply to message #513118] Tue, 09 February 2010 21:22 Go to previous messageGo to next message
Al B is currently offline Al BFriend
Messages: 130
Registered: July 2009
Senior Member
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);
itemPropertySource = (IItemPropertySource) adapterFactory.adapt(object, IItemPropertySource.class);
}

I am not sure I follow the part about the decorators though.
Re: Retrieve ItemProvider from EObject [message #513374 is a reply to message #513371] Tue, 09 February 2010 21:43 Go to previous message
Ed Merks is currently offline Ed MerksFriend
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/
Previous Topic:Converting output XMI file to XML
Next Topic:Problem with binary resource format with enabled zipping
Goto Forum:
  


Current Time: Thu Apr 25 11:28:39 GMT 2024

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

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

Back to the top