Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » generically get item provider for an EObject
generically get item provider for an EObject [message #523467] Fri, 26 March 2010 09:50 Go to next message
Eclipse UserFriend
Originally posted by: formatzeh.gmx.de

Hi NG,
I want to open a subclass of FilteredItemsSelectionDialog where I can
select one of the elements which are all EObjects. For better labels in
the dialog I want to display the text and image of the EObjects as it is
returned by its item provider. If such an item provider doesn't exist
then the default text and image should be displayed. Can you give me a
hint how to achieve this?

best regards,
Gilbert
Re: generically get item provider for an EObject [message #523479 is a reply to message #523467] Fri, 26 March 2010 15:11 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Gilbert,

It sounds like you'd want to use the same label provider
(AdapterFactoryLabelProvider) as you see being created and used in the
generated editor.


Gilbert Mirenque wrote:
> Hi NG,
> I want to open a subclass of FilteredItemsSelectionDialog where I can
> select one of the elements which are all EObjects. For better labels in
> the dialog I want to display the text and image of the EObjects as it is
> returned by its item provider. If such an item provider doesn't exist
> then the default text and image should be displayed. Can you give me a
> hint how to achieve this?
>
> best regards,
> Gilbert
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: generically get item provider for an EObject [message #523487 is a reply to message #523479] Fri, 26 March 2010 10:32 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: formatzeh.gmx.de

Hi Ed,
> It sounds like you'd want to use the same label provider
> (AdapterFactoryLabelProvider) as you see being created and used in the
> generated editor.
Yes, exactly that is what I want. I could solve it with the following
snippet:

EObject object = (EObject) element;
EcoreItemProviderAdapterFactory factory = new
EcoreItemProviderAdapterFactory();
if(factory.isFactoryForType(IItemLabelProvider.class)){
IItemLabelProvider labelProvider = (IItemLabelProvider)
factory.adapt(object, IItemLabelProvider.class);
if(labelProvider != null){
return labelProvider.getText(object);
}
}

Is this a convenient method to do this?
Re: generically get item provider for an EObject [message #523505 is a reply to message #523487] Fri, 26 March 2010 15:40 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------050504040206010100020800
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

Gilbert,

Wrap the item provider adapter factory with an AdapterFactoryLabelProvider.


Gilbert Mirenque wrote:
> Hi Ed,
>
>> It sounds like you'd want to use the same label provider
>> (AdapterFactoryLabelProvider) as you see being created and used in the
>> generated editor.
>>
> Yes, exactly that is what I want. I could solve it with the following
> snippet:
>
> EObject object = (EObject) element;
> EcoreItemProviderAdapterFactory factory = new
> EcoreItemProviderAdapterFactory();
> if(factory.isFactoryForType(IItemLabelProvider.class)){
> IItemLabelProvider labelProvider = (IItemLabelProvider)
> factory.adapt(object, IItemLabelProvider.class);
> if(labelProvider != null){
> return labelProvider.getText(object);
> }
> }
>
> Is this a convenient method to do this?
>

--------------050504040206010100020800
Content-Type: text/html; charset=ISO-8859-15
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-15"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Gilbert,<br>
<br>
Wrap the item provider adapter factory with an
AdapterFactoryLabelProvider.<br>
<br>
<br>
Gilbert Mirenque wrote:
<blockquote cite="mid:hoijmf$n0g$1@build.eclipse.org" type="cite">
<pre wrap="">Hi Ed,
</pre>
<blockquote type="cite">
<pre wrap="">It sounds like you'd want to use the same label provider
(AdapterFactoryLabelProvider) as you see being created and used in the
generated editor.
</pre>
</blockquote>
<pre wrap=""><!---->Yes, exactly that is what I want. I could solve it with the following
snippet:

EObject object = (EObject) element;
EcoreItemProviderAdapterFactory factory = new
EcoreItemProviderAdapterFactory();
if(factory.isFactoryForType(IItemLabelProvider.class)){
IItemLabelProvider labelProvider = (IItemLabelProvider)
factory.adapt(object, IItemLabelProvider.class);
if(labelProvider != null){
return labelProvider.getText(object);
}
}

Is this a convenient method to do this?
</pre>
</blockquote>
</body>
</html>

--------------050504040206010100020800--


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:EMF Codegen: versioned required plugins
Next Topic:why does the code generator include this in the editor?
Goto Forum:
  


Current Time: Sat Apr 27 04:42:33 GMT 2024

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

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

Back to the top