Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Question about ItemPropertyDescriptor#getId(Object)
Question about ItemPropertyDescriptor#getId(Object) [message #417914] Fri, 28 March 2008 15:07 Go to next message
Stefan Baramov is currently offline Stefan BaramovFriend
Messages: 33
Registered: July 2009
Member
The implementation of the ItemPropertyDescriptor#getId(Object) is like
that :

public String getId(Object object)
{
// System.out.println("getName " + feature.eClass().getEID());
// return feature.eClass().getEID().toString();

return displayName;
}

Essentially, the property ID is the displayName. The displayName is
externalized in a resource bundle and it will be translated in different
languages. Hence the property ID will differ depending on the current
local. For example the property ID of an attribute 'name' will be 'Name'
in en_US local, 'Nom' in fr_FR local. How is one suppose to locate a
property descriptor by its identifier and keep the logic consistent
across language translation?

Is not feature.getName() a better implementation. After all a feature
name represents a field name and should be unique in the context of a
particular class.


Thanks
Stefan
Re: Question about ItemPropertyDescriptor#getId(Object) [message #417915 is a reply to message #417914] Fri, 28 March 2008 15:39 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33141
Registered: July 2009
Senior Member
Stefan,

There isn't necessarily always a feature (there's also the
parentReferences array). So we don't have anything else that's unique.
ItemPropertyDescriptor does have a getFeature method, but I'm not sure
what exactly your use case is... Of course you could use
XyzEditPlugin.INSTANCE.get("_UI_<EClass-Name>_<EStructuralFeature_Name >_feature")
to get the translated string; the key itself would have been a better ID...


Stefan Baramov wrote:
> The implementation of the ItemPropertyDescriptor#getId(Object) is like
> that :
>
> public String getId(Object object)
> {
> // System.out.println("getName " + feature.eClass().getEID());
> // return feature.eClass().getEID().toString();
>
> return displayName;
> }
>
> Essentially, the property ID is the displayName. The displayName is
> externalized in a resource bundle and it will be translated in
> different languages. Hence the property ID will differ depending on
> the current local. For example the property ID of an attribute 'name'
> will be 'Name' in en_US local, 'Nom' in fr_FR local. How is one
> suppose to locate a property descriptor by its identifier and keep the
> logic consistent across language translation?
>
> Is not feature.getName() a better implementation. After all a feature
> name represents a field name and should be unique in the context of a
> particular class.
>
>
> Thanks
> Stefan


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Question about ItemPropertyDescriptor#getId(Object) [message #417918 is a reply to message #417915] Fri, 28 March 2008 17:21 Go to previous messageGo to next message
Stefan Baramov is currently offline Stefan BaramovFriend
Messages: 33
Registered: July 2009
Member
Ed,
Point taken, I do not use the parentReferences array so the simple
solution was okay. However, you are correct the feature could be null.
Unfortunately I do not have a clear understanding on how and for what
the patternReferences are used. So excuse my lame solution but here it is :

public String getId(Object object) {
if (feature != null) {
return feature.getName();

} else if (parentReferences != null && parentReferences.length > 0){
// concatenate all names with dot as a separator.
final StringBuilder compositeId = new StringBuilder();
for (int i = 0; i < parentReferences.length; ++i) {
if (i != 0) {
compositeId.append(".");
}
compositeId.append(parentReferences[i].getName());
}

return compositeId.toString();

} else {
return Integer.toHexString(hashCode());
}
}

the #2 case is the first that come to mind, as I have said, I do not
understand the use case for the patternReferences. For one, the
ItemProviderAdapter is not using it so it is safe for me to assume that
this is not use at all at least in my case.

The #3 case should never happen if the javadoc is correct. The case
where the feature == null and patternReferences is an empty array should
be an invalid state. If this is the case then may be throwing
IllegalStateException is more appropriate.


FYI: My case is quite simple. I have a graphic editor for a specialized
XML file. The editor utilizes the TabbedPropertySheetPage provided by
the platform. The tabs are PropertySection's and contains fields to
render particular properties. These property sections utilize the
corresponding property descriptors to read and write the property value.
The property descriptor is looked up by its ID. Hence the ID is vital
for me.

At the end, in my humble opinion, the getId() method needs a better
implementation.

Thanks,
Stefan

Ed Merks wrote:
> Stefan,
>
> There isn't necessarily always a feature (there's also the
> parentReferences array). So we don't have anything else that's unique.
> ItemPropertyDescriptor does have a getFeature method, but I'm not sure
> what exactly your use case is... Of course you could use
> XyzEditPlugin.INSTANCE.get("_UI_<EClass-Name>_<EStructuralFeature_Name >_feature")
> to get the translated string; the key itself would have been a better ID...
>
>
Re: Question about ItemPropertyDescriptor#getId(Object) [message #417921 is a reply to message #417918] Fri, 28 March 2008 17:54 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33141
Registered: July 2009
Senior Member
Stefan,

Comments below.


Stefan Baramov wrote:
> Ed,
> Point taken, I do not use the parentReferences array so the simple
> solution was okay. However, you are correct the feature could be null.
> Unfortunately I do not have a clear understanding on how and for what
> the patternReferences are used.
They're not much used!
> So excuse my lame solution but here it is :
>
> public String getId(Object object) {
> if (feature != null) {
> return feature.getName();
>
> } else if (parentReferences != null && parentReferences.length > 0){
> // concatenate all names with dot as a separator.
> final StringBuilder compositeId = new StringBuilder();
> for (int i = 0; i < parentReferences.length; ++i) {
> if (i != 0) {
> compositeId.append(".");
> }
> compositeId.append(parentReferences[i].getName());
> }
>
> return compositeId.toString();
>
> } else {
> return Integer.toHexString(hashCode());
> }
> }
Given that something like hash code is completely arbitrary, I'm not
sure how it could ever be used for lookup unless you used this method to
find the ID in the first place.
>
> the #2 case is the first that come to mind, as I have said, I do not
> understand the use case for the patternReferences. For one, the
> ItemProviderAdapter is not using it so it is safe for me to assume
> that this is not use at all at least in my case.
>
> The #3 case should never happen if the javadoc is correct. The case
> where the feature == null and patternReferences is an empty array
> should be an invalid state. If this is the case then may be throwing
> IllegalStateException is more appropriate.
True, but folks could override these things to do all manner of things I
might not anticipate.
>
>
> FYI: My case is quite simple. I have a graphic editor for a
> specialized XML file. The editor utilizes the TabbedPropertySheetPage
> provided by the platform. The tabs are PropertySection's and contains
> fields to render particular properties. These property sections
> utilize the corresponding property descriptors to read and write the
> property value. The property descriptor is looked up by its ID. Hence
> the ID is vital for me.
>
> At the end, in my humble opinion, the getId() method needs a better
> implementation.
I think I need to understand the use case better. I know that many
people uses the properties view include the tabbed property sheet page,
yet no one has been concerned about looking up a property by ID. The ID
is mostly just used internal to the property sheet implementations.
Given that it's been working in this kind of crummy way for a long time,
I can't be sure that folks aren't relying on the current behavior. So
while not ideal, you definitely can get the string used as the ID by
fetching it from the plugin...
>
> Thanks,
> Stefan
>
> Ed Merks wrote:
>> Stefan,
>>
>> There isn't necessarily always a feature (there's also the
>> parentReferences array). So we don't have anything else that's
>> unique. ItemPropertyDescriptor does have a getFeature method, but
>> I'm not sure what exactly your use case is... Of course you could
>> use
>> XyzEditPlugin.INSTANCE.get("_UI_<EClass-Name>_<EStructuralFeature_Name >_feature")
>> to get the translated string; the key itself would have been a better
>> ID...
>>
>>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Question about ItemPropertyDescriptor#getId(Object) [message #417924 is a reply to message #417921] Fri, 28 March 2008 19:31 Go to previous messageGo to next message
Stefan Baramov is currently offline Stefan BaramovFriend
Messages: 33
Registered: July 2009
Member
>>
>> At the end, in my humble opinion, the getId() method needs a better
>> implementation.
> I think I need to understand the use case better. I know that many
> people uses the properties view include the tabbed property sheet page,
> yet no one has been concerned about looking up a property by ID. The ID
> is mostly just used internal to the property sheet implementations.
> Given that it's been working in this kind of crummy way for a long time,
> I can't be sure that folks aren't relying on the current behavior. So
> while not ideal, you definitely can get the string used as the ID by
> fetching it from the plugin...

It is quite surprising to me that no one has reported this problem
before. Essentially I am using the
org.eclipse.emf.edit.ui.provider.PropertySource class to read and write
properties value. Therefore I need a reliable property ID.

Anyway, I have solved my problem by overriding the ItemProviderAdapter
and ItemProviderDescriptor to have a better ID. However, I still believe
that this should be filed as a bug and fixed in a future version. Of
course in the case where I am the only one with that believe then never
mind me.

Thanks
Stefan
Re: Question about ItemPropertyDescriptor#getId(Object) [message #417925 is a reply to message #417924] Fri, 28 March 2008 19:52 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33141
Registered: July 2009
Senior Member
Stefan,

I agree it doesn't seem ideal, but I'm also not inclined to change
something when the change is just as likely to break existing users as
it is to make someone else happy. Since your the first to ever complain
about it, I'm not so sure. But if others complain in the future, I'll
remember. In general, I think the IItemPropertySource and IItem
PropertyDescriptor APIs are more flexible; i.e., the later would allow
you to find the matching feature with the feature object itself...


Stefan Baramov wrote:
> >>
> >> At the end, in my humble opinion, the getId() method needs a better
> >> implementation.
> > I think I need to understand the use case better. I know that many
> > people uses the properties view include the tabbed property sheet page,
> > yet no one has been concerned about looking up a property by ID.
> The ID
> > is mostly just used internal to the property sheet implementations.
> > Given that it's been working in this kind of crummy way for a long
> time,
> > I can't be sure that folks aren't relying on the current behavior. So
> > while not ideal, you definitely can get the string used as the ID by
> > fetching it from the plugin...
>
> It is quite surprising to me that no one has reported this problem
> before. Essentially I am using the
> org.eclipse.emf.edit.ui.provider.PropertySource class to read and
> write properties value. Therefore I need a reliable property ID.
>
> Anyway, I have solved my problem by overriding the ItemProviderAdapter
> and ItemProviderDescriptor to have a better ID. However, I still
> believe that this should be filed as a bug and fixed in a future
> version. Of course in the case where I am the only one with that
> believe then never mind me.
>
> Thanks
> Stefan


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Question about ItemPropertyDescriptor#getId(Object) [message #417953 is a reply to message #417924] Mon, 31 March 2008 12:59 Go to previous messageGo to next message
Sébastien  Gandon is currently offline Sébastien GandonFriend
Messages: 184
Registered: July 2009
Senior Member
I too had the same problem and found the same solution.
My use case was to build a generic text editor to include in a Form using
databinding (see the class below).

The class is instanciated with a IItemPropertyDescriptor in order to get
the label and the feature.
in order to get the IItemPropertyDescriptor of one of my model feature I
use the folowing which uses the feature name as the ID:
IItemPropertyDescriptor propertyDescriptor =
**AdapterFactoryItemDelegator**.getPropertyDescriptor(Middle waresFactory.eINSTANCE.createMiddleware(),
MiddlewaresPackage.Literals.MIDDLEWARE__NAME.getName());


here is the class :
public class EmfFormTextRow {
// Required to allow space for field decorations
public static final int CONTROL_HORIZONTAL_INDENT = 3;
private EditingDomain editingDomain;
private ISWTObservableValue textObservable;
private Binding textBinding;
private DataBindingContext bindingContext;
private IItemPropertyDescriptor propertyDesc;

/**
* create the adapter class to the EMF feature
*/
public EmfFormTextRow(EditingDomain editingDomain,
IItemPropertyDescriptor propertyDescriptor, DataBindingContext
bindingContext) {
this.editingDomain = editingDomain;
this.propertyDesc = propertyDescriptor;
this.bindingContext = bindingContext;
}


public void createContents(Composite parent, FormToolkit toolkit, int
span) {
createLabel(parent, toolkit);
Text text = toolkit.createText(parent, "", SWT.SINGLE); //$NON-NLS-1$
text.setLayoutData(createGridData(span));
textObservable = SWTObservables.observeText(text, SWT.Modify);
}

/**
* @param parent
* @param toolkit
*/
private void createLabel(Composite parent, FormToolkit toolkit) {
Label label = toolkit.createLabel(parent,
propertyDesc.getDisplayName(null), SWT.NONE);
// Label label = toolkit.createLabel(parent, feature.getName(), SWT.NONE);
label.setForeground(toolkit.getColors().getColor(IFormColors .TITLE));
}

protected GridData createGridData(int span) {
GridData gd = new GridData(span == 2 ? GridData.FILL_HORIZONTAL :
GridData.HORIZONTAL_ALIGN_FILL);
gd.widthHint = 20;
gd.horizontalSpan = span - 1;
gd.horizontalIndent = CONTROL_HORIZONTAL_INDENT;
return gd;
}

public void modelChanged(EObject emfObject) {
if (textBinding != null) {
textBinding.dispose();
}
IObservableValue source = EMFEditObservables.observeValue(editingDomain,
emfObject, (EStructuralFeature) propertyDesc.getFeature(emfObject));
textBinding = bindingContext.bindValue(textObservable, source, new
UpdateValueStrategy(UpdateValueStrategy.POLICY_UPDATE), new
UpdateValueStrategy(UpdateValueStrategy.POLICY_UPDATE));
}

/**
* remove the binding between text control and the emf object
*/
public void dispose() {
if (textBinding != null) {
textBinding.dispose();
}
}

/**
* set the focus to the text control
*/
public void setFocus() {
if (textObservable != null) {
((Text) textObservable.getWidget()).setFocus();
}
}
}
Re: Question about ItemPropertyDescriptor#getId(Object) [message #417954 is a reply to message #417953] Mon, 31 March 2008 13:20 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33141
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------050602030605000807090804
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

Comments below.

SeB.fr wrote:
> I too had the same problem and found the same solution.
> My use case was to build a generic text editor to include in a Form
> using databinding (see the class below).
>
> The class is instanciated with a IItemPropertyDescriptor in order to
> get the label and the feature.
> in order to get the IItemPropertyDescriptor of one of my model feature
> I use the folowing which uses the feature name as the ID:
> IItemPropertyDescriptor propertyDescriptor =
> **AdapterFactoryItemDelegator**.getPropertyDescriptor(Middle waresFactory.eINSTANCE.createMiddleware(),
> MiddlewaresPackage.Literals.MIDDLEWARE__NAME.getName());
IItemPropertyDescriptor has a getFeature method so you could match by
feature. It's annoying that we mistakenly made the ID be a string.
:-( Perhaps a good compromise at this point would to implement the
ID-matching methods to consider both the ID and the feature object so
that the feature object could be used as the ID in the lookup methods.

IItemPropertyDescriptor propertyDescriptor =
**AdapterFactoryItemDelegator**.getPropertyDescriptor(Middle waresFactory.eINSTANCE.createMiddleware(),
MiddlewaresPackage.Literals.*MIDDLEWARE__NAME*);

What do you think? It's easy enough do implement and I can't imagine
adding such support breaking anything...
>
>
> here is the class :
> public class EmfFormTextRow {
> // Required to allow space for field decorations
> public static final int CONTROL_HORIZONTAL_INDENT = 3;
> private EditingDomain editingDomain;
> private ISWTObservableValue textObservable;
> private Binding textBinding;
> private DataBindingContext bindingContext;
> private IItemPropertyDescriptor propertyDesc;
>
> /**
> * create the adapter class to the EMF feature
> */
> public EmfFormTextRow(EditingDomain editingDomain,
> IItemPropertyDescriptor propertyDescriptor, DataBindingContext
> bindingContext) {
> this.editingDomain = editingDomain;
> this.propertyDesc = propertyDescriptor;
> this.bindingContext = bindingContext;
> }
>
>
> public void createContents(Composite parent, FormToolkit toolkit,
> int span) {
> createLabel(parent, toolkit);
> Text text = toolkit.createText(parent, "", SWT.SINGLE);
> //$NON-NLS-1$
> text.setLayoutData(createGridData(span));
> textObservable = SWTObservables.observeText(text, SWT.Modify);
> }
>
> /**
> * @param parent
> * @param toolkit
> */
> private void createLabel(Composite parent, FormToolkit toolkit) {
> Label label = toolkit.createLabel(parent,
> propertyDesc.getDisplayName(null), SWT.NONE);
> // Label label = toolkit.createLabel(parent, feature.getName(),
> SWT.NONE);
>
> label.setForeground(toolkit.getColors().getColor(IFormColors .TITLE));
> }
>
> protected GridData createGridData(int span) {
> GridData gd = new GridData(span == 2 ?
> GridData.FILL_HORIZONTAL : GridData.HORIZONTAL_ALIGN_FILL);
> gd.widthHint = 20;
> gd.horizontalSpan = span - 1;
> gd.horizontalIndent = CONTROL_HORIZONTAL_INDENT;
> return gd;
> }
>
> public void modelChanged(EObject emfObject) {
> if (textBinding != null) {
> textBinding.dispose();
> }
> IObservableValue source =
> EMFEditObservables.observeValue(editingDomain, emfObject,
> (EStructuralFeature) propertyDesc.getFeature(emfObject));
> textBinding = bindingContext.bindValue(textObservable, source,
> new UpdateValueStrategy(UpdateValueStrategy.POLICY_UPDATE), new
> UpdateValueStrategy(UpdateValueStrategy.POLICY_UPDATE));
> }
>
> /**
> * remove the binding between text control and the emf object
> */
> public void dispose() {
> if (textBinding != null) {
> textBinding.dispose();
> }
> }
>
> /**
> * set the focus to the text control
> */
> public void setFocus() {
> if (textObservable != null) {
> ((Text) textObservable.getWidget()).setFocus();
> }
> }
> }
>
>


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

<!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">
Comments below.<br>
<br>
SeB.fr wrote:
<blockquote
cite="mid:d404a195704fbec2764749732e7363d1$1@www.eclipse.org"
type="cite">I too had the same problem and found the same solution.
<br>
My use case was to build a generic text editor to include in a Form
using databinding (see the class below).
<br>
<br>
The class is instanciated with a IItemPropertyDescriptor in order to
get the label and the feature.
<br>
in order to get the IItemPropertyDescriptor of one of my model feature
I use the folowing which uses the feature name as the ID:
<br>
IItemPropertyDescriptor propertyDescriptor =
**AdapterFactoryItemDelegator**.getPropertyDescriptor(Middle waresFactory.eINSTANCE.createMiddleware(),
MiddlewaresPackage.Literals.MIDDLEWARE__NAME.getName());
<br>
</blockquote>
IItemPropertyDescriptor has a getFeature method so you could match by
feature.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Question about ItemPropertyDescriptor#getId(Object) [message #418045 is a reply to message #417954] Thu, 03 April 2008 15:22 Go to previous message
Sébastien  Gandon is currently offline Sébastien GandonFriend
Messages: 184
Registered: July 2009
Senior Member
Yes this would be a great feature to add.

Thank you.

SeB.
Previous Topic:Code Generation - How to customize ?
Next Topic:Example for serialization to plain text file
Goto Forum:
  


Current Time: Fri Apr 26 05:31:41 GMT 2024

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

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

Back to the top