How to get ItemProviderAdapter for EStructuralFeature [message #526699] |
Mon, 12 April 2010 15:53 |
Eclipse User |
|
|
|
Originally posted by: Thomas.Kowatsch.ruag.com
Hi.
I want to get the ItemProviderAdapter (I need
ItemProviderAdapter#getFeatureText()) related to an EStructuralFeature.
Or get the translated feature name for an EStructuralFeature from edit
plugin.
In the method I have only access to the EStructuralFeature, no EObject
instance!
Cheers.
--Thomas
|
|
|
Re: How to get ItemProviderAdapter for EStructuralFeature [message #526705 is a reply to message #526699] |
Mon, 12 April 2010 16:18 |
Eclipse User |
|
|
|
Originally posted by: formatzeh.gmx.de
Hi Thomas,
what about this:
ComposedAdapterFactory adapterFactory = new
ComposedAdapterFactory(org.eclipse.emf.edit.provider.Compose dAdapterFactory.Descriptor.Registry.INSTANCE);
adapterFactory.addAdapterFactory(new ResourceItemProviderAdapterFactory());
adapterFactory.addAdapterFactory(new EcoreItemProviderAdapterFactory());
adapterFactory.addAdapterFactory(new
ReflectiveItemProviderAdapterFactory());
labelProvider = new AdapterFactoryLabelProvider(adapterFactory);
String featureText = labelProvider.getText(yourStructuralFeature);
Image featureImage = labelProvider.getImage(yourStructuralFeature);
best regards,
Gilbert
> Hi.
> I want to get the ItemProviderAdapter (I need
> ItemProviderAdapter#getFeatureText()) related to an EStructuralFeature.
> Or get the translated feature name for an EStructuralFeature from edit
> plugin.
> In the method I have only access to the EStructuralFeature, no EObject
> instance!
> Cheers.
> --Thomas
|
|
|
Re: How to get ItemProviderAdapter for EStructuralFeature [message #526711 is a reply to message #526705] |
Mon, 12 April 2010 16:54 |
Eclipse User |
|
|
|
Originally posted by: Thomas.Kowatsch.ruag.com
Hi Gilbert.
Thanx for you reply.
Unfortunately "labelProvider.getText(yourStructuralFeature)" return a
String "featureName: EString" which is not exactly what I want, as I
need only the tranlated feature name.
Another thing is that AdapterFactoryLabelProvider is in the
org.eclipse.emf.edit.ui plugin which I do not have and cannot include in
the dependencies of the plugin where this should be used.
The ItemProviderAdapter class has a getFeatureText(Object) method which
I would like to use. But what I don't know or find is how I can get the
ItemProviderAdapter related to the feature (the feature belongs to an
EClass which has to have an ItemProvider, right?)
Cheers.
--Thomas
Gilbert Mirenque schrieb:
> Hi Thomas,
> what about this:
>
> ComposedAdapterFactory adapterFactory = new
> ComposedAdapterFactory(org.eclipse.emf.edit.provider.Compose dAdapterFactory.Descriptor.Registry.INSTANCE);
> adapterFactory.addAdapterFactory(new ResourceItemProviderAdapterFactory());
> adapterFactory.addAdapterFactory(new EcoreItemProviderAdapterFactory());
> adapterFactory.addAdapterFactory(new
> ReflectiveItemProviderAdapterFactory());
> labelProvider = new AdapterFactoryLabelProvider(adapterFactory);
> String featureText = labelProvider.getText(yourStructuralFeature);
> Image featureImage = labelProvider.getImage(yourStructuralFeature);
>
> best regards,
> Gilbert
>
>
>> Hi.
>> I want to get the ItemProviderAdapter (I need
>> ItemProviderAdapter#getFeatureText()) related to an EStructuralFeature.
>> Or get the translated feature name for an EStructuralFeature from edit
>> plugin.
>> In the method I have only access to the EStructuralFeature, no EObject
>> instance!
>> Cheers.
>> --Thomas
>
|
|
|
Re: How to get ItemProviderAdapter for EStructuralFeature [message #526734 is a reply to message #526711] |
Mon, 12 April 2010 18:28 |
Ed Merks Messages: 33137 Registered: July 2009 |
Senior Member |
|
|
This is a multi-part message in MIME format.
--------------050007070109060603040809
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit
Thomas,
There was a long thread about this recently:
http://www.eclipse.org/forums/index.php?t=msg&goto=51945 0&
< http://www.eclipse.org/forums/index.php?t=msg&goto=51945 0&>
The idea near the end is to get an IItemLabelProvider from and instance
of an object that has such a feature, and use that as an
IResourceLocator to find the key for the feature in the plugin.properties.
Thomas Kowatsch wrote:
> Hi Gilbert.
> Thanx for you reply.
> Unfortunately "labelProvider.getText(yourStructuralFeature)" return a
> String "featureName: EString" which is not exactly what I want, as I
> need only the tranlated feature name.
> Another thing is that AdapterFactoryLabelProvider is in the
> org.eclipse.emf.edit.ui plugin which I do not have and cannot include
> in the dependencies of the plugin where this should be used.
> The ItemProviderAdapter class has a getFeatureText(Object) method
> which I would like to use. But what I don't know or find is how I can
> get the ItemProviderAdapter related to the feature (the feature
> belongs to an EClass which has to have an ItemProvider, right?)
> Cheers.
> --Thomas
>
> Gilbert Mirenque schrieb:
>> Hi Thomas,
>> what about this:
>>
>> ComposedAdapterFactory adapterFactory = new
>> ComposedAdapterFactory(org.eclipse.emf.edit.provider.Compose dAdapterFactory.Descriptor.Registry.INSTANCE);
>>
>> adapterFactory.addAdapterFactory(new
>> ResourceItemProviderAdapterFactory());
>> adapterFactory.addAdapterFactory(new EcoreItemProviderAdapterFactory());
>> adapterFactory.addAdapterFactory(new
>> ReflectiveItemProviderAdapterFactory());
>> labelProvider = new AdapterFactoryLabelProvider(adapterFactory);
>> String featureText = labelProvider.getText(yourStructuralFeature);
>> Image featureImage = labelProvider.getImage(yourStructuralFeature);
>>
>> best regards,
>> Gilbert
>>
>>
>>> Hi.
>>> I want to get the ItemProviderAdapter (I need
>>> ItemProviderAdapter#getFeatureText()) related to an EStructuralFeature.
>>> Or get the translated feature name for an EStructuralFeature from edit
>>> plugin.
>>> In the method I have only access to the EStructuralFeature, no EObject
>>> instance!
>>> Cheers.
>>> --Thomas
>>
--------------050007070109060603040809
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">
Thomas,<br>
<br>
There was a long thread about this recently:<br>
<blockquote><a
href="http://www.eclipse.org/forums/index.php?t=msg&goto=519450&">http://www.eclipse.org/forums/index.php?t=msg&goto=519450&</a><br>
</blockquote>
The idea near the end is to get an IItemLabelProvider from and instance
of an object that has such a feature, and use that as an
IResourceLocator to find the key for the feature in the
plugin.properties.<br>
<br>
<br>
Thomas Kowatsch wrote:
<blockquote cite="mid:hpvj7p$3l5$1@build.eclipse.org" type="cite">Hi
Gilbert.
<br>
Thanx for you reply.
<br>
Unfortunately "labelProvider.getText(yourStructuralFeature)" return a
String "featureName: EString" which is not exactly what I want, as I
need only the tranlated feature name.
<br>
Another thing is that AdapterFactoryLabelProvider is in the
org.eclipse.emf.edit.ui plugin which I do not have and cannot include
in the dependencies of the plugin where this should be used.
<br>
The ItemProviderAdapter class has a getFeatureText(Object) method which
I would like to use. But what I don't know or find is how I can get the
ItemProviderAdapter related to the feature (the feature belongs to an
EClass which has to have an ItemProvider, right?)
<br>
Cheers.
<br>
--Thomas
<br>
<br>
Gilbert Mirenque schrieb:
<br>
<blockquote type="cite">Hi Thomas,
<br>
what about this:
<br>
<br>
ComposedAdapterFactory adapterFactory = new
<br>
ComposedAdapterFactory(org.eclipse.emf.edit.provider.Compose dAdapterFactory.Descriptor.Registry.INSTANCE);
<br>
adapterFactory.addAdapterFactory(new
ResourceItemProviderAdapterFactory());
<br>
adapterFactory.addAdapterFactory(new
EcoreItemProviderAdapterFactory());
<br>
adapterFactory.addAdapterFactory(new
<br>
ReflectiveItemProviderAdapterFactory());
<br>
labelProvider = new AdapterFactoryLabelProvider(adapterFactory);
<br>
String featureText = labelProvider.getText(yourStructuralFeature);
<br>
Image featureImage = labelProvider.getImage(yourStructuralFeature);
<br>
<br>
best regards,
<br>
Gilbert
<br>
<br>
<br>
<blockquote type="cite">Hi.
<br>
I want to get the ItemProviderAdapter (I need
<br>
ItemProviderAdapter#getFeatureText()) related to an EStructuralFeature.
<br>
Or get the translated feature name for an EStructuralFeature from edit
<br>
plugin.
<br>
In the method I have only access to the EStructuralFeature, no EObject
<br>
instance!
<br>
Cheers.
<br>
--Thomas
<br>
</blockquote>
<br>
</blockquote>
</blockquote>
</body>
</html>
--------------050007070109060603040809--
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Re: How to get ItemProviderAdapter for EStructuralFeature [message #526764 is a reply to message #526734] |
Mon, 12 April 2010 20:20 |
Eclipse User |
|
|
|
Originally posted by: Thomas.Kowatsch.ruag.com
Hi Ed.
Unfortunately, I have no instance of any object with such a feature
available. I only have the feature and an AdapterFactory (a
ComposedAdapterFactory).
Maybe I have to explain a bit further. I have a custom Diagnostician
that overrides the getObjectLabel(EObject) and the
getFeatureLabel(EStructuralFeature) methods. This is needed to customize
the ValidationStatus messages to use translated object and feature
labels. It is absolutely no problem to get the object label in
getObjectLabel(EObject):
public String getObjectLabel (EObject eObject) {
if (_adapterFactory != null && !eObject.eIsProxy()) {
IItemLabelProvider itemLabelProvider=
(IItemLabelProvider) _adapterFactory.adapt(eObject,
IItemLabelProvider.class);
if (itemLabelProvider != null) {
return itemLabelProvider.getText(eObject);
}
}
return super.getObjectLabel(eObject);
}
But what to do in the getFeatureLabel(EStructuralFeature) method???
As I mentioned before, the Diagnostician only has an instance of a
ComposedAdapterFactory....
Cheers.
--Thomas
Ed Merks schrieb:
> Thomas,
>
> There was a long thread about this recently:
>
> http://www.eclipse.org/forums/index.php?t=msg&goto=51945 0&
> < http://www.eclipse.org/forums/index.php?t=msg&goto=51945 0&>
>
> The idea near the end is to get an IItemLabelProvider from and instance
> of an object that has such a feature, and use that as an
> IResourceLocator to find the key for the feature in the plugin.properties.
>
>
> Thomas Kowatsch wrote:
>> Hi Gilbert.
>> Thanx for you reply.
>> Unfortunately "labelProvider.getText(yourStructuralFeature)" return a
>> String "featureName: EString" which is not exactly what I want, as I
>> need only the tranlated feature name.
>> Another thing is that AdapterFactoryLabelProvider is in the
>> org.eclipse.emf.edit.ui plugin which I do not have and cannot include
>> in the dependencies of the plugin where this should be used.
>> The ItemProviderAdapter class has a getFeatureText(Object) method
>> which I would like to use. But what I don't know or find is how I can
>> get the ItemProviderAdapter related to the feature (the feature
>> belongs to an EClass which has to have an ItemProvider, right?)
>> Cheers.
>> --Thomas
>>
>> Gilbert Mirenque schrieb:
>>> Hi Thomas,
>>> what about this:
>>>
>>> ComposedAdapterFactory adapterFactory = new
>>> ComposedAdapterFactory(org.eclipse.emf.edit.provider.Compose dAdapterFactory.Descriptor.Registry.INSTANCE);
>>>
>>> adapterFactory.addAdapterFactory(new
>>> ResourceItemProviderAdapterFactory());
>>> adapterFactory.addAdapterFactory(new EcoreItemProviderAdapterFactory());
>>> adapterFactory.addAdapterFactory(new
>>> ReflectiveItemProviderAdapterFactory());
>>> labelProvider = new AdapterFactoryLabelProvider(adapterFactory);
>>> String featureText = labelProvider.getText(yourStructuralFeature);
>>> Image featureImage = labelProvider.getImage(yourStructuralFeature);
>>>
>>> best regards,
>>> Gilbert
>>>
>>>
>>>> Hi.
>>>> I want to get the ItemProviderAdapter (I need
>>>> ItemProviderAdapter#getFeatureText()) related to an EStructuralFeature.
>>>> Or get the translated feature name for an EStructuralFeature from edit
>>>> plugin.
>>>> In the method I have only access to the EStructuralFeature, no EObject
>>>> instance!
>>>> Cheers.
>>>> --Thomas
>>>
|
|
|
Re: How to get ItemProviderAdapter for EStructuralFeature [message #526949 is a reply to message #526764] |
Tue, 13 April 2010 14:43 |
Ed Merks Messages: 33137 Registered: July 2009 |
Senior Member |
|
|
Thomas,
I see. I just don't have a great answer. Certainly the generated
*.edit project has such things but how to get at that... Such a bundle
does contribute an item provider adapter factory so we could use that to
determine the identity of the bundle and perhaps from that we could find
the bundle activator which implements IResourceLocator which could be
used to look up the translatable keys. If you open a bugzilla
enhancement request I might be able to find some time to implement a
general purpose utility.
Thomas Kowatsch wrote:
> Hi Ed.
>
> Unfortunately, I have no instance of any object with such a feature
> available. I only have the feature and an AdapterFactory (a
> ComposedAdapterFactory).
>
> Maybe I have to explain a bit further. I have a custom Diagnostician
> that overrides the getObjectLabel(EObject) and the
> getFeatureLabel(EStructuralFeature) methods. This is needed to
> customize the ValidationStatus messages to use translated object and
> feature labels. It is absolutely no problem to get the object label in
> getObjectLabel(EObject):
>
> public String getObjectLabel (EObject eObject) {
> if (_adapterFactory != null && !eObject.eIsProxy()) {
> IItemLabelProvider itemLabelProvider=
> (IItemLabelProvider) _adapterFactory.adapt(eObject,
> IItemLabelProvider.class);
> if (itemLabelProvider != null) {
> return itemLabelProvider.getText(eObject);
> }
> }
> return super.getObjectLabel(eObject);
> }
>
> But what to do in the getFeatureLabel(EStructuralFeature) method???
> As I mentioned before, the Diagnostician only has an instance of a
> ComposedAdapterFactory....
>
> Cheers.
> --Thomas
>
> Ed Merks schrieb:
>> Thomas,
>>
>> There was a long thread about this recently:
>>
>> http://www.eclipse.org/forums/index.php?t=msg&goto=51945 0&
>> < http://www.eclipse.org/forums/index.php?t=msg&goto=51945 0&>
>>
>> The idea near the end is to get an IItemLabelProvider from and
>> instance of an object that has such a feature, and use that as an
>> IResourceLocator to find the key for the feature in the
>> plugin.properties.
>>
>>
>> Thomas Kowatsch wrote:
>>> Hi Gilbert.
>>> Thanx for you reply.
>>> Unfortunately "labelProvider.getText(yourStructuralFeature)" return
>>> a String "featureName: EString" which is not exactly what I want, as
>>> I need only the tranlated feature name.
>>> Another thing is that AdapterFactoryLabelProvider is in the
>>> org.eclipse.emf.edit.ui plugin which I do not have and cannot
>>> include in the dependencies of the plugin where this should be used.
>>> The ItemProviderAdapter class has a getFeatureText(Object) method
>>> which I would like to use. But what I don't know or find is how I
>>> can get the ItemProviderAdapter related to the feature (the feature
>>> belongs to an EClass which has to have an ItemProvider, right?)
>>> Cheers.
>>> --Thomas
>>>
>>> Gilbert Mirenque schrieb:
>>>> Hi Thomas,
>>>> what about this:
>>>>
>>>> ComposedAdapterFactory adapterFactory = new
>>>> ComposedAdapterFactory(org.eclipse.emf.edit.provider.Compose dAdapterFactory.Descriptor.Registry.INSTANCE);
>>>>
>>>> adapterFactory.addAdapterFactory(new
>>>> ResourceItemProviderAdapterFactory());
>>>> adapterFactory.addAdapterFactory(new
>>>> EcoreItemProviderAdapterFactory());
>>>> adapterFactory.addAdapterFactory(new
>>>> ReflectiveItemProviderAdapterFactory());
>>>> labelProvider = new AdapterFactoryLabelProvider(adapterFactory);
>>>> String featureText = labelProvider.getText(yourStructuralFeature);
>>>> Image featureImage = labelProvider.getImage(yourStructuralFeature);
>>>>
>>>> best regards,
>>>> Gilbert
>>>>
>>>>
>>>>> Hi.
>>>>> I want to get the ItemProviderAdapter (I need
>>>>> ItemProviderAdapter#getFeatureText()) related to an
>>>>> EStructuralFeature.
>>>>> Or get the translated feature name for an EStructuralFeature from
>>>>> edit
>>>>> plugin.
>>>>> In the method I have only access to the EStructuralFeature, no
>>>>> EObject
>>>>> instance!
>>>>> Cheers.
>>>>> --Thomas
>>>>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Re: How to get ItemProviderAdapter for EStructuralFeature [message #527006 is a reply to message #526949] |
Tue, 13 April 2010 16:01 |
Eclipse User |
|
|
|
Originally posted by: Thomas.Kowatsch.ruag.com
Ed,
I have found a suitable solution for me, as we have only one edit plugin
at the moment. So I use:
MyEditPlugin.INSTANCE.getString("_UI_"
+ eStructuralFeature.getEContainingClass().getName() + "_"
+ eStructuralFeature.getName() + "_feature");
But anyway, I openend a bugzilla:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=309019
Cheers.
--Thomas
Ed Merks schrieb:
> Thomas,
>
> I see. I just don't have a great answer. Certainly the generated
> *.edit project has such things but how to get at that... Such a bundle
> does contribute an item provider adapter factory so we could use that to
> determine the identity of the bundle and perhaps from that we could find
> the bundle activator which implements IResourceLocator which could be
> used to look up the translatable keys. If you open a bugzilla
> enhancement request I might be able to find some time to implement a
> general purpose utility.
>
>
> Thomas Kowatsch wrote:
>> Hi Ed.
>>
>> Unfortunately, I have no instance of any object with such a feature
>> available. I only have the feature and an AdapterFactory (a
>> ComposedAdapterFactory).
>>
>> Maybe I have to explain a bit further. I have a custom Diagnostician
>> that overrides the getObjectLabel(EObject) and the
>> getFeatureLabel(EStructuralFeature) methods. This is needed to
>> customize the ValidationStatus messages to use translated object and
>> feature labels. It is absolutely no problem to get the object label in
>> getObjectLabel(EObject):
>>
>> public String getObjectLabel (EObject eObject) {
>> if (_adapterFactory != null && !eObject.eIsProxy()) {
>> IItemLabelProvider itemLabelProvider=
>> (IItemLabelProvider) _adapterFactory.adapt(eObject,
>> IItemLabelProvider.class);
>> if (itemLabelProvider != null) {
>> return itemLabelProvider.getText(eObject);
>> }
>> }
>> return super.getObjectLabel(eObject);
>> }
>>
>> But what to do in the getFeatureLabel(EStructuralFeature) method???
>> As I mentioned before, the Diagnostician only has an instance of a
>> ComposedAdapterFactory....
>>
>> Cheers.
>> --Thomas
>>
>> Ed Merks schrieb:
>>> Thomas,
>>>
>>> There was a long thread about this recently:
>>>
>>> http://www.eclipse.org/forums/index.php?t=msg&goto=51945 0&
>>> < http://www.eclipse.org/forums/index.php?t=msg&goto=51945 0&>
>>>
>>> The idea near the end is to get an IItemLabelProvider from and
>>> instance of an object that has such a feature, and use that as an
>>> IResourceLocator to find the key for the feature in the
>>> plugin.properties.
>>>
>>>
>>> Thomas Kowatsch wrote:
>>>> Hi Gilbert.
>>>> Thanx for you reply.
>>>> Unfortunately "labelProvider.getText(yourStructuralFeature)" return
>>>> a String "featureName: EString" which is not exactly what I want, as
>>>> I need only the tranlated feature name.
>>>> Another thing is that AdapterFactoryLabelProvider is in the
>>>> org.eclipse.emf.edit.ui plugin which I do not have and cannot
>>>> include in the dependencies of the plugin where this should be used.
>>>> The ItemProviderAdapter class has a getFeatureText(Object) method
>>>> which I would like to use. But what I don't know or find is how I
>>>> can get the ItemProviderAdapter related to the feature (the feature
>>>> belongs to an EClass which has to have an ItemProvider, right?)
>>>> Cheers.
>>>> --Thomas
>>>>
>>>> Gilbert Mirenque schrieb:
>>>>> Hi Thomas,
>>>>> what about this:
>>>>>
>>>>> ComposedAdapterFactory adapterFactory = new
>>>>> ComposedAdapterFactory(org.eclipse.emf.edit.provider.Compose dAdapterFactory.Descriptor.Registry.INSTANCE);
>>>>>
>>>>> adapterFactory.addAdapterFactory(new
>>>>> ResourceItemProviderAdapterFactory());
>>>>> adapterFactory.addAdapterFactory(new
>>>>> EcoreItemProviderAdapterFactory());
>>>>> adapterFactory.addAdapterFactory(new
>>>>> ReflectiveItemProviderAdapterFactory());
>>>>> labelProvider = new AdapterFactoryLabelProvider(adapterFactory);
>>>>> String featureText = labelProvider.getText(yourStructuralFeature);
>>>>> Image featureImage = labelProvider.getImage(yourStructuralFeature);
>>>>>
>>>>> best regards,
>>>>> Gilbert
>>>>>
>>>>>
>>>>>> Hi.
>>>>>> I want to get the ItemProviderAdapter (I need
>>>>>> ItemProviderAdapter#getFeatureText()) related to an
>>>>>> EStructuralFeature.
>>>>>> Or get the translated feature name for an EStructuralFeature from
>>>>>> edit
>>>>>> plugin.
>>>>>> In the method I have only access to the EStructuralFeature, no
>>>>>> EObject
>>>>>> instance!
>>>>>> Cheers.
>>>>>> --Thomas
>>>>>
|
|
|
Powered by
FUDForum. Page generated in 0.03505 seconds