Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Implementing Dynamic Properties with list
Implementing Dynamic Properties with list [message #425137] Sat, 15 November 2008 16:14 Go to next message
Asha Ramegowda is currently offline Asha RamegowdaFriend
Messages: 77
Registered: July 2009
Member
Hi Ed,

Sorry for opening a new thread for the same old issue.
I have a Device class.
I have the Property class with name and value attribute inside it.
I have a list of Property inside my Device class.
This is a containment.

So,far I studied the TreeNodeItemProvider and tried to collect the
Property list's each of the property element's value attribute's property
descriptors inside my DeviceItemProvider.
To create these property descriptors I am creating a loop inside my the
DevicePropertyDescriptor.getPropertyDescriptor(Object object).
Then getting Property element at each index, say prop.
And creating a PropertyDescriptor on it.
I am passing prop.getName as the the display name and
<myPackage>.LITERALS.PROPERTY__VALUE as the featureid.

By doing this I am able to see the names of the Property list as the
properties of my device node but each of their value field displays my
entire Property object as string and is locked. Not editable.

Can somebody tell me what's going wrong here?
Do I need to do something with my notification?

If I override the ItemPropertyDescriptor and override the getProperty
value and setProperty value, I am not able to see anything for the Device
node.


Thank you,

Asha R.
Re: Implementing Dynamic Properties with list [message #425138 is a reply to message #425137] Sat, 15 November 2008 17:53 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30897
Registered: July 2009
Senior Member
Asha,

Comments below.

Asha R wrote:
> Hi Ed,
>
> Sorry for opening a new thread for the same old issue.
> I have a Device class.
> I have the Property class with name and value attribute inside it.
> I have a list of Property inside my Device class.
> This is a containment.
>
> So,far I studied the TreeNodeItemProvider and tried to collect the
> Property list's each of the property element's value attribute's
> property descriptors inside my DeviceItemProvider.
> To create these property descriptors I am creating a loop inside my
> the DevicePropertyDescriptor.getPropertyDescriptor(Object object).
> Then getting Property element at each index, say prop.
> And creating a PropertyDescriptor on it.
> I am passing prop.getName as the the display name and
> <myPackage>.LITERALS.PROPERTY__VALUE as the featureid.
>
> By doing this I am able to see the names of the Property list as the
> properties of my device node but each of their value field displays my
> entire Property object as string and is locked. Not editable.
Did you create a delegate like in the example?
>
> Can somebody tell me what's going wrong here?
Show what you've done.
> Do I need to do something with my notification?
Notifications won't need attention because executing a command will
update the properties view.
>
> If I override the ItemPropertyDescriptor and override the getProperty
> value and setProperty value, I am not able to see anything for the
> Device node.
Note that I'm traveling today, so answers will be slow to come...
>
>
> Thank you,
>
> Asha R.
>
Re: Implementing Dynamic Properties with list [message #425145 is a reply to message #425138] Mon, 17 November 2008 05:11 Go to previous messageGo to next message
Asha Ramegowda is currently offline Asha RamegowdaFriend
Messages: 77
Registered: July 2009
Member
Hi Ed,

Thank you very much for your kind reply.
Actually I am not really very much clear as what the delegateItemProvider
and itemDelegator are doing TreeNodeItemProvider?
I checked the implementation classes for those two and I found they looked
similar to ItemDescriptors. Of course they are not but am not able to get
exactly what they are how they work.
If you can throw more light on it, it will be great.

So, I tried to do just as the code in the following way...
------------------------------------------------------------ -----------------
*********** Code ******************
------------------------------------------------------------ -----------------
@Override
public List<IItemPropertyDescriptor> getPropertyDescriptors(Object
object) {
if (itemPropertyDescriptors == null) {
super.getPropertyDescriptors(object);

addLogicalNamePropertyDescriptor(object);
addDeviceEnumPropertyDescriptor(object);
}

//***This is the code I added*** It must be funny :-)!!!***

Device device = (Device) object;
//This below code did not work so I left this approach
/*PropAdapterFactory factory = (PropAdapterFactory) getAdapterFactory();
PropertyItemProvider propertyItemProvider = (PropertyItemProvider)
factory.createPropertyAdapter();

for(int i=0; i<device.getProperties().size(); i++){

Property property = device.getProperties().get(i);
propertyItemProvider.addValuePropertyDescriptor(property);
itemPropertyDescriptors.addAll(propertyItemProvider.getPrope rtyDescriptors(property));
}
*/

/** The below approach little bit works and prints each of the
(property.name)s
** as the properties of the parent device but the value field is locked!
** And displays entire Property object as string for all the properties
**/

for(int i=0; i<device.getProperties().size(); i++){

Property property = device.getProperties().get(i);

itemPropertyDescriptors.add
(createItemPropertyDescriptor
(((ComposeableAdapterFactory)adapterFactory).getRootAdapterF actory(),
getResourceLocator(),
property.getName(),
property.getName() + " Property",
PropPackage.Literals.PROPERTY__VALUE,
true,
false,
false,
ItemPropertyDescriptor.GENERIC_VALUE_IMAGE,
null,
null));
}
return itemPropertyDescriptors;
}

------------------------------------------------------------ -----------------

Please reply whenever you are free :-).

Thank you,

Asha R.


Ed Merks wrote:

> Asha,

> Comments below.

> Asha R wrote:
>> Hi Ed,
>>
>> Sorry for opening a new thread for the same old issue.
>> I have a Device class.
>> I have the Property class with name and value attribute inside it.
>> I have a list of Property inside my Device class.
>> This is a containment.
>>
>> So,far I studied the TreeNodeItemProvider and tried to collect the
>> Property list's each of the property element's value attribute's
>> property descriptors inside my DeviceItemProvider.
>> To create these property descriptors I am creating a loop inside my
>> the DevicePropertyDescriptor.getPropertyDescriptor(Object object).
>> Then getting Property element at each index, say prop.
>> And creating a PropertyDescriptor on it.
>> I am passing prop.getName as the the display name and
>> <myPackage>.LITERALS.PROPERTY__VALUE as the featureid.
>>
>> By doing this I am able to see the names of the Property list as the
>> properties of my device node but each of their value field displays my
>> entire Property object as string and is locked. Not editable.
> Did you create a delegate like in the example?
>>
>> Can somebody tell me what's going wrong here?
> Show what you've done.
>> Do I need to do something with my notification?
> Notifications won't need attention because executing a command will
> update the properties view.
>>
>> If I override the ItemPropertyDescriptor and override the getProperty
>> value and setProperty value, I am not able to see anything for the
>> Device node.
> Note that I'm traveling today, so answers will be slow to come...
>>
>>
>> Thank you,
>>
>> Asha R.
>>
Re: Implementing Dynamic Properties with list - Before Giving it up :-(!!! [message #425300 is a reply to message #425145] Sat, 22 November 2008 07:06 Go to previous messageGo to next message
Asha Ramegowda is currently offline Asha RamegowdaFriend
Messages: 77
Registered: July 2009
Member
Hi Ed,

I got what you were telling once I stopped working on this dynamic
properties :-).
So, I got it I have to just delegate to my current adapterFactory the
proper object as it know as to adopt to which itemProvider.
So, I came back I did the same.
I just tried to change only a name
It is working but there was a porblem.
If I have a list of Property it doesn't work but it works if I have only
one property in the list.
Even though it displays the names of the properties in some irregular
manner like sometimes twice sometimes once, finally it just displays only
once and the display names of the properties will be that of the most
recently generated property instance on the list but it always updates the
value fields of the first property instance on the list.
I can understand what the problem is here.
But still want to know is there any work around for it?

Please find my example model for what I implemented below:

-------------
<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0"
xmlns:xmi="http://www.omg.org/XMI"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="prop"
nsURI="http://www.example.org/prop" nsPrefix="prop">
<eClassifiers xsi:type="ecore:EClass" name="Device">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="logicalName"
eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="properties"
lowerBound="1"
upperBound="-1" eType="#//Property" containment="true"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Property">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="name"
eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="value"
eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="version"
eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EInt"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="deviceEnum"
eType="#//PROPENUM"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Board">
<eStructuralFeatures xsi:type="ecore:EReference" name="devices"
lowerBound="1"
upperBound="-1" eType="#//Device" containment="true"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EEnum" name="PROPENUM">
<eLiterals name="ONE"/>
<eLiterals name="TWO"/>
<eLiterals name="THREE"/>
<eLiterals name="FOUR"/>
</eClassifiers>
</ecore:EPackage>
----------------------

Then, this is the code I replaced in the DeviceItemProvider.java
------------------------
protected AdapterFactoryItemDelegator itemDelegator;

/**
* This constructs an instance from a factory and a notifier. <!--
* begin-user-doc --> <!-- end-user-doc -->
*
* @generated
*/
public DeviceItemProvider(AdapterFactory adapterFactory) {
super(adapterFactory);
itemDelegator = new
AdapterFactoryItemDelegator(((ComposeableAdapterFactory)adap terFactory).getRootAdapterFactory());
}

/**
* This returns the property descriptors for the adapted class. <!--
* begin-user-doc --> <!-- end-user-doc -->
*
* @generated
*/
@Override
public List<IItemPropertyDescriptor> getPropertyDescriptors(Object
object) {
if (itemPropertyDescriptors == null) {
super.getPropertyDescriptors(object);

addLogicalNamePropertyDescriptor(object);

Device device = (Device) object;
EList<Property> propList = device.getProperties();
if (propList.size() != 0) {
for (int i = 0; i < propList.size(); i++) {
Property prop = device.getProperties().get(i);
// addPropertyValueDescriptor(prop);

if (prop != null)

for (IItemPropertyDescriptor itemPropertyDescriptor : itemDelegator
.getPropertyDescriptors(prop)) {
String id = itemPropertyDescriptor.getId(prop);
//don't generate descriptors for the name
if (!(itemPropertyDescriptor.getDisplayName(prop)
.equals("Name")))
itemPropertyDescriptors
.add(new MyPropertyDescriptorDecorator(
prop, itemPropertyDescriptor));
}
}
}
}
return itemPropertyDescriptors;
}

-------------------
Then, this is the class that I have to override the display name:
--------------------
package prop.provider;

import org.eclipse.emf.edit.provider.IItemPropertyDescriptor;
import org.eclipse.emf.edit.provider.ItemPropertyDescriptorDecorato r;

import prop.Property;

public class MyPropertyDescriptorDecorator extends
ItemPropertyDescriptorDecorator {


String displayName;

public MyPropertyDescriptorDecorator(Object object,
IItemPropertyDescriptor itemPropertyDescriptor) {
super(object, itemPropertyDescriptor);
Property prop = (Property) object;
this.displayName = prop.getName();
}



@Override
public String getDisplayName(Object thisObject) {
// TODO Auto-generated method stub
String value = itemPropertyDescriptor.getDisplayName(object);
if(value.equals("Value"))
return this.displayName;
else
return value;
}

}
--------------------------------------------
Officially it's not part of my work now. :-).
But still I would like to know is there anything that am missing here?
Or only this much can be done?

Thank you,

Asha R.

PS:
I wish I could delete all the useless posts I have written, because now I
understand the problem well. :-).
Re: Implementing Dynamic Properties with list - Before Giving it up :-(!!! [message #425301 is a reply to message #425300] Sat, 22 November 2008 07:48 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30897
Registered: July 2009
Senior Member
Asha,

Comments below.

Asha R wrote:
> Hi Ed,
>
> I got what you were telling once I stopped working on this dynamic
> properties :-).
> So, I got it I have to just delegate to my current adapterFactory the
> proper object as it know as to adopt to which itemProvider.
> So, I came back I did the same.
> I just tried to change only a name
> It is working but there was a porblem.
> If I have a list of Property it doesn't work but it works if I have
> only one property in the list.
Each property descriptor has to have a unique ID or they will get merged.
> Even though it displays the names of the properties in some irregular
> manner like sometimes twice sometimes once, finally it just displays
> only once and the display names of the properties will be that of the
> most recently generated property instance on the list but it always
> updates the value fields of the first property instance on the list.
> I can understand what the problem is here.
> But still want to know is there any work around for it?
>
> Please find my example model for what I implemented below:
>
> -------------
> <?xml version="1.0" encoding="UTF-8"?>
> <ecore:EPackage xmi:version="2.0"
> xmlns:xmi="http://www.omg.org/XMI"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="prop"
> nsURI="http://www.example.org/prop" nsPrefix="prop">
> <eClassifiers xsi:type="ecore:EClass" name="Device">
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="logicalName"
> eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
> <eStructuralFeatures xsi:type="ecore:EReference" name="properties"
> lowerBound="1"
> upperBound="-1" eType="#//Property" containment="true"/>
> </eClassifiers>
> <eClassifiers xsi:type="ecore:EClass" name="Property">
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="name"
> eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="value"
> eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="version"
> eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EInt"/>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="deviceEnum"
> eType="#//PROPENUM"/>
> </eClassifiers>
> <eClassifiers xsi:type="ecore:EClass" name="Board">
> <eStructuralFeatures xsi:type="ecore:EReference" name="devices"
> lowerBound="1"
> upperBound="-1" eType="#//Device" containment="true"/>
> </eClassifiers>
> <eClassifiers xsi:type="ecore:EEnum" name="PROPENUM">
> <eLiterals name="ONE"/>
> <eLiterals name="TWO"/>
> <eLiterals name="THREE"/>
> <eLiterals name="FOUR"/>
> </eClassifiers>
> </ecore:EPackage>
> ----------------------
>
> Then, this is the code I replaced in the DeviceItemProvider.java
> ------------------------
> protected AdapterFactoryItemDelegator itemDelegator;
>
> /**
> * This constructs an instance from a factory and a notifier. <!--
> * begin-user-doc --> <!-- end-user-doc -->
> * * @generated
> */
> public DeviceItemProvider(AdapterFactory adapterFactory) {
> super(adapterFactory);
> itemDelegator = new
> AdapterFactoryItemDelegator(((ComposeableAdapterFactory)adap terFactory).getRootAdapterFactory());
>
> }
>
> /**
> * This returns the property descriptors for the adapted class. <!--
> * begin-user-doc --> <!-- end-user-doc -->
> * * @generated
> */
> @Override
> public List<IItemPropertyDescriptor> getPropertyDescriptors(Object
> object) {
> if (itemPropertyDescriptors == null) {
Keep in mind that if you guard it like this, it won't be recomputed for
each "object". So you don't want this guard; you want the whole list to
be recomputed each time.
> super.getPropertyDescriptors(object);
>
> addLogicalNamePropertyDescriptor(object);
>
> Device device = (Device) object;
> EList<Property> propList = device.getProperties();
> if (propList.size() != 0) {
> for (int i = 0; i < propList.size(); i++) {
> Property prop = device.getProperties().get(i);
> // addPropertyValueDescriptor(prop);
>
> if (prop != null)
>
> for (IItemPropertyDescriptor
> itemPropertyDescriptor : itemDelegator
> .getPropertyDescriptors(prop)) {
Keep in mind that you need to create properties with unique names or
they will be merged...
> String id = itemPropertyDescriptor.getId(prop);
> //don't generate descriptors for the name
> if (!(itemPropertyDescriptor.getDisplayName(prop)
> .equals("Name")))
> itemPropertyDescriptors
> .add(new
> MyPropertyDescriptorDecorator(
> prop,
> itemPropertyDescriptor));
> }
> }
> }
> }
> return itemPropertyDescriptors;
> }
>
> -------------------
> Then, this is the class that I have to override the display name:
> --------------------
> package prop.provider;
>
> import org.eclipse.emf.edit.provider.IItemPropertyDescriptor;
> import org.eclipse.emf.edit.provider.ItemPropertyDescriptorDecorato r;
>
> import prop.Property;
>
> public class MyPropertyDescriptorDecorator extends
> ItemPropertyDescriptorDecorator {
>
>
> String displayName;
>
> public MyPropertyDescriptorDecorator(Object object,
> IItemPropertyDescriptor itemPropertyDescriptor) {
> super(object, itemPropertyDescriptor);
> Property prop = (Property) object;
> this.displayName = prop.getName();
> }
>
>
>
> @Override
> public String getDisplayName(Object thisObject) {
> // TODO Auto-generated method stub
> String value = itemPropertyDescriptor.getDisplayName(object);
> if(value.equals("Value"))
> return this.displayName;
> else
> return value;
> }
>
> }
> --------------------------------------------
> Officially it's not part of my work now. :-).
> But still I would like to know is there anything that am missing here?
> Or only this much can be done?
>
> Thank you,
>
> Asha R.
>
> PS:
> I wish I could delete all the useless posts I have written, because
> now I understand the problem well. :-).
Hehehe.
>
>
Re: Implementing Dynamic Properties with list - Before Giving it up :-(!!! [message #425306 is a reply to message #425301] Sat, 22 November 2008 08:30 Go to previous messageGo to next message
Asha Ramegowda is currently offline Asha RamegowdaFriend
Messages: 77
Registered: July 2009
Member
Hi Ed,

I just tried to delegate my entire list.
Something like this.
---
List<IItemPropertyDescriptor> itemPropDescs =
itemDelegator.getPropertyDescriptors(propList);
itemPropertyDescriptors.addAll(itemPropDescs);
---
But it did not work.
It has returned null for itemPropDescs.

Yeah, I understand that each property should have a unique name.
I am not understanding how I can control it?
I can see only getId method for the PropertyDescriptors but could not find
setId.
Then, I thought displayName itself is considered as the unique id because
of a comment written in base implementation classes somewhere.
But, I am not able to find a place where I can try to set a unique id?
Do, I need to provide my own PropertyDescriptors so that I can control the
ids during the construction?

But, if my delegator handles my list properly, I don't need this I guess.

Thank you,

Asha R.
Re: Implementing Dynamic Properties with list - Before Giving it up :-(!!! [message #425307 is a reply to message #425306] Sat, 22 November 2008 08:37 Go to previous messageGo to next message
Asha Ramegowda is currently offline Asha RamegowdaFriend
Messages: 77
Registered: July 2009
Member
Hi Ed,

Do I need to take care of handling this list in the PropertyItemProvider?

Thank you,

Asha R.
Re: Implementing Dynamic Properties with list - Before Giving it up :-(!!! [message #425308 is a reply to message #425307] Sat, 22 November 2008 08:41 Go to previous messageGo to next message
Asha Ramegowda is currently offline Asha RamegowdaFriend
Messages: 77
Registered: July 2009
Member
Oh sorry! It's not possible.
It's a wrong question. Please ignore this.
Re: Implementing Dynamic Properties with list - Before Giving it up :-(!!! [message #425309 is a reply to message #425306] Sat, 22 November 2008 09:30 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30897
Registered: July 2009
Senior Member
Asha,

Comments below.

Asha R wrote:
> Hi Ed,
>
> I just tried to delegate my entire list.
> Something like this.
> ---
> List<IItemPropertyDescriptor> itemPropDescs =
> itemDelegator.getPropertyDescriptors(propList);
> itemPropertyDescriptors.addAll(itemPropDescs);
It's pretty clear in the samples I pointed you too that those involved
creating decorators. You'll need to do that. And you need to work with
the individual properties not just pass in the list.
> ---
> But it did not work. It has returned null for itemPropDescs.
>
> Yeah, I understand that each property should have a unique name.
> I am not understanding how I can control it?
Via the decorator that's created. Look at the MappingItemProvider.
> I can see only getId method for the PropertyDescriptors but could not
> find setId.
You can specialize the class that's created.
> Then, I thought displayName itself is considered as the unique id
> because of a comment written in base implementation classes somewhere.
> But, I am not able to find a place where I can try to set a unique id?
The mapping sample shows a way.
> Do, I need to provide my own PropertyDescriptors so that I can control
> the ids during the construction?
That's a way too,.
>
> But, if my delegator handles my list properly, I don't need this I guess.
You'll find out.
>
> Thank you,
>
> Asha R.
>
>
>
Re: Implementing Dynamic Properties with list - Before Giving it up :-(!!! [message #425312 is a reply to message #425309] Sat, 22 November 2008 11:22 Go to previous message
Asha Ramegowda is currently offline Asha RamegowdaFriend
Messages: 77
Registered: July 2009
Member
Wow Ed,

It works!!!
Only some minor things are left for me to do now, if I really want to
implement it :-).
Like changing the name and all...:-).
Hope that would work.
Let me try.

Thank you,

Asha R.
Previous Topic:Custom serialization
Next Topic:[CDO] Welcome Stefan Winkler as new committer
Goto Forum:
  


Current Time: Sun Feb 23 14:20:47 GMT 2020

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

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

Back to the top