Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » EMF newbie question
EMF newbie question [message #486485] Thu, 17 September 2009 19:52 Go to next message
Eclipse UserFriend
Originally posted by: mc5686.mclink.it

Hi Everybody,
I am a complete newbie to EMF and thus, please, bear with me :)

I am trying to setup my first (after tutorials) real EMF project.

I am using annotated java to define my model (as per tutorials, again).

My current problem is: how to fill-up references (contained="false") as
references to a "real" container (something similar to enums, but with a
List of real classes).

I have a series of Interfaces:
IProduct: name, description, price, ...
IOrder: reference to IProduct, quantity, deliveryDate, ...
ICustomer: name, address, ..., List<IOrder>
IFirm: name, address, ..., List<IProduct>, List<ICustomer>

I am simplifying, of course.
My problem is the "reference to IProduct" should not be owned by IOrder,
but a reference to some IProduct already defined and owned by IFirm.
This would be a FOREIGN KEY in SQL.
I would expect an editor showing a (dynamically filled) list (or combo)
but I have been unable to achieve this.

Can someone point me in the right direction?

Thanks in advance.
Re: EMF newbie question [message #486503 is a reply to message #486485] Thu, 17 September 2009 21:23 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Mauro,

Comments below.

Mauro Condarelli wrote:
> Hi Everybody,
> I am a complete newbie to EMF and thus, please, bear with me :)
>
> I am trying to setup my first (after tutorials) real EMF project.
>
> I am using annotated java to define my model (as per tutorials, again).
>
> My current problem is: how to fill-up references (contained="false")
> as references to a "real" container (something similar to enums, but
> with a List of real classes).
>
> I have a series of Interfaces:
> IProduct: name, description, price, ...
> IOrder: reference to IProduct, quantity, deliveryDate, ...
> ICustomer: name, address, ..., List<IOrder>
> IFirm: name, address, ..., List<IProduct>, List<ICustomer>
>
> I am simplifying, of course.
> My problem is the "reference to IProduct" should not be owned by
> IOrder, but a reference to some IProduct already defined and owned by
> IFirm.
> This would be a FOREIGN KEY in SQL.
> I would expect an editor showing a (dynamically filled) list (or
> combo) but I have been unable to achieve this.
Unless you add containment="true" you should end up with a
non-containment reference. Note that you can always create an Ecore
model and generate the code to see what @model annotations come out for
that. I'd also suggest you look at the nice EMF refcard.
http://refcardz.dzone.com/refcardz/essential-emf
>
> Can someone point me in the right direction?
> Thanks in advance.
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EMF newbie question [message #486553 is a reply to message #486503] Fri, 18 September 2009 08:10 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: mc5686.mclink.it

Thanks.
I have evidently been unclear.
I already discovered the trick of leaving out the containment="true"
attribute.
Problem is:
If I do that the generated editor will create a temporary IProduct
instance and will refuse to save it (because it has to be contained
somewhere).

How do I convince EMF to generate an editor that will not generate a new
instance, but will allow me to select an existing IProduct contained in
another class (instance of IFirm)?

Can this be done?
I suppose the answer is "yes", because it looks like a very common
operation, but I found no references to it.

Thanks for the pointer. I'm printing it now :)

Regards
Mauro


Ed Merks wrote:

> Mauro,

> Comments below.

> Mauro Condarelli wrote:
>> Hi Everybody,
>> I am a complete newbie to EMF and thus, please, bear with me :)
>>
>> I am trying to setup my first (after tutorials) real EMF project.
>>
>> I am using annotated java to define my model (as per tutorials, again).
>>
>> My current problem is: how to fill-up references (contained="false")
>> as references to a "real" container (something similar to enums, but
>> with a List of real classes).
>>
>> I have a series of Interfaces:
>> IProduct: name, description, price, ...
>> IOrder: reference to IProduct, quantity, deliveryDate, ...
>> ICustomer: name, address, ..., List<IOrder>
>> IFirm: name, address, ..., List<IProduct>, List<ICustomer>
>>
>> I am simplifying, of course.
>> My problem is the "reference to IProduct" should not be owned by
>> IOrder, but a reference to some IProduct already defined and owned by
>> IFirm.
>> This would be a FOREIGN KEY in SQL.
>> I would expect an editor showing a (dynamically filled) list (or
>> combo) but I have been unable to achieve this.
> Unless you add containment="true" you should end up with a
> non-containment reference. Note that you can always create an Ecore
> model and generate the code to see what @model annotations come out for
> that. I'd also suggest you look at the nice EMF refcard.
> http://refcardz.dzone.com/refcardz/essential-emf
>>
>> Can someone point me in the right direction?
>> Thanks in advance.
>>
>>
Re: EMF newbie question [message #486675 is a reply to message #486553] Fri, 18 September 2009 14:34 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Mauro,

Comments below.

Mauro Condarelli wrote:
> Thanks.
> I have evidently been unclear.
> I already discovered the trick of leaving out the containment="true"
> attribute.
> Problem is:
> If I do that the generated editor will create a temporary IProduct
> instance and will refuse to save it (because it has to be contained
> somewhere).
That sounds like what would happen if you don't use containment="true"
>
> How do I convince EMF to generate an editor that will not generate a
> new instance, but will allow me to select an existing IProduct
> contained in another class (instance of IFirm)?
You have to make containment false and then you can choose from
instances contained already elsewhere in the model (or in another
resource you load into the editor).
>
> Can this be done?
> I suppose the answer is "yes", because it looks like a very common
> operation, but I found no references to it.
The library example illustrates this where the books and writers are
contained by the library but can refer to each other.
>
> Thanks for the pointer. I'm printing it now :)
>
> Regards
> Mauro
>
>
> Ed Merks wrote:
>
>> Mauro,
>
>> Comments below.
>
>> Mauro Condarelli wrote:
>>> Hi Everybody,
>>> I am a complete newbie to EMF and thus, please, bear with me :)
>>>
>>> I am trying to setup my first (after tutorials) real EMF project.
>>>
>>> I am using annotated java to define my model (as per tutorials, again).
>>>
>>> My current problem is: how to fill-up references (contained="false")
>>> as references to a "real" container (something similar to enums, but
>>> with a List of real classes).
>>>
>>> I have a series of Interfaces:
>>> IProduct: name, description, price, ...
>>> IOrder: reference to IProduct, quantity, deliveryDate, ...
>>> ICustomer: name, address, ..., List<IOrder>
>>> IFirm: name, address, ..., List<IProduct>, List<ICustomer>
>>>
>>> I am simplifying, of course.
>>> My problem is the "reference to IProduct" should not be owned by
>>> IOrder, but a reference to some IProduct already defined and owned
>>> by IFirm.
>>> This would be a FOREIGN KEY in SQL.
>>> I would expect an editor showing a (dynamically filled) list (or
>>> combo) but I have been unable to achieve this.
>> Unless you add containment="true" you should end up with a
>> non-containment reference. Note that you can always create an Ecore
>> model and generate the code to see what @model annotations come out
>> for that. I'd also suggest you look at the nice EMF refcard.
>> http://refcardz.dzone.com/refcardz/essential-emf
>>>
>>> Can someone point me in the right direction?
>>> Thanks in advance.
>>>
>>>
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EMF newbie question [message #486746 is a reply to message #486675] Fri, 18 September 2009 21:20 Go to previous messageGo to next message
Mauro Condarelli is currently offline Mauro CondarelliFriend
Messages: 428
Registered: September 2009
Senior Member
Hi,
I'm here again Embarrassed

I managed to make this work.

Next problem:

I have a tree structure and each node has an EList holding some of the same kind of information (users, in this case). Here I have 'containment="true"'.

The leafs do have an EList of references to users (containment="false").

The generated editor shows, for the leafs, all users defined (contained) everywhere in the tree.

I would like to restrict the possible choices to just the users contained in the nodes in the path that leads from the root to the leaf.
I.E.: the leaf should have (an EList of references to) a subset of the users defined in the branch.
How can I do this?

Other thing: how can I specify custom icons for the various node elements?

Thanks a lot for Your patience
Mauro
Re: EMF newbie question [message #486837 is a reply to message #486746] Sat, 19 September 2009 18:07 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Mauro,

Comments below.

Mauro Condarelli wrote:
> Hi,
> I'm here again :blush:
> I managed to make this work.
>
> Next problem:
>
> I have a tree structure and each node has an EList holding some of
> the same kind of information (users, in this case). Here I have
> 'containment="true"'.
>
> The leafs do have an EList of references to users (containment="false").
>
> The generated editor shows, for the leafs, all users defined
> (contained) everywhere in the tree.
>
> I would like to restrict the possible choices to just the users
> contained in the nodes in the path that leads from the root to the
> leaf. I.E.: the leaf should have (an EList of references to) a subset
> of the users defined in the branch.
> How can I do this?
Specialize getChoiceOfValues for the property, e.g,

/**
* This adds a property descriptor for the EType feature.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated NOT
*/
protected void addETypePropertyDescriptor(Object object)
{
itemPropertyDescriptors.add
(new ItemPropertyDescriptorWithUniqueChoiceOfValueLabels

(((ComposeableAdapterFactory)adapterFactory).getRootAdapterF actory(),
getResourceLocator(),
getString("_UI_ETypedElement_eType_feature"),
getString("_UI_ETypedElement_eType_description"),
EcorePackage.Literals.ETYPED_ELEMENT__ETYPE,
true,
false,
true,
null,
null,
null)
{
@Override
public Collection<?> getChoiceOfValues(Object object)

>
> Other thing: how can I specify custom icons for the various node
> elements?
Replace the generated icons in the *.edit project with your own.
>
> Thanks a lot for Your patience
> Mauro


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EMF newbie question [message #487083 is a reply to message #486837] Mon, 21 September 2009 19:11 Go to previous messageGo to next message
Mauro Condarelli is currently offline Mauro CondarelliFriend
Messages: 428
Registered: September 2009
Senior Member
Sorry,
I feel very stupid.

This is one of my generated methods:

/**
* This adds a property descriptor for the Name feature.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
protected void addNamePropertyDescriptor(Object object) {
itemPropertyDescriptors.add
(createItemPropertyDescriptor
(((ComposeableAdapterFactory)adapterFactory).getRootAdapterF actory(),
getResourceLocator(),
getString("_UI_Character_name_feature"),
getString("_UI_PropertyDescriptor_description", "_UI_Character_name_feature", "_UI_Character_type"),
MCWritePackage.Literals.CHARACTER__NAME,
true,
false,
false,
ItemPropertyDescriptor.GENERIC_VALUE_IMAGE,
null,
null));
}

This resembles what You posted earlier, but not quite.
I tried changing this to:

protected void addNamePropertyDescriptor(Object object) {
itemPropertyDescriptors.add( new new ItemPropertyDescriptorWithUniqueChoiceOfValueLabels(
...

but it says new ItemPropertyDescriptorWithUniqueChoiceOfValueLabels is unresolved (also after Ctrl-O).

Where can I find documentation about this?
I searched the Help to no avail.
I will also check the hits I had on the the web, but some pointer from a knowledgeable person would be very welcome Smile

TiA
Mauro

Re: EMF newbie question [message #487091 is a reply to message #487083] Mon, 21 September 2009 20:07 Go to previous messageGo to next message
Mauro Condarelli is currently offline Mauro CondarelliFriend
Messages: 428
Registered: September 2009
Senior Member
Mauro Condarelli wrote on Mon, 21 September 2009 15:11
Sorry,
I feel very stupid.
...
but it says new ItemPropertyDescriptorWithUniqueChoiceOfValueLabels is unresolved (also after Ctrl-O).
...


Ok.
It seems now it is called "ItemPropertyDescriptorDecorator".

Just the same: Is there any good documentation available?

Thanks
Mauro
Re: EMF newbie question [message #487103 is a reply to message #487091] Mon, 21 September 2009 21:59 Go to previous messageGo to next message
Mauro Condarelli is currently offline Mauro CondarelliFriend
Messages: 428
Registered: September 2009
Senior Member
I'm getting mad Confused

I managed to have the selection working, at least it displays in the selector the items I think it should.

So far, so good.

Problem is that the properties of my "leafs" do not refresh correctly Sad

When I switch from one leaf to the other the lists remain the same, even if they are actually different (I checked the saved XML).


This is my tentative mcwrite.genmodel:
<?xml version="1.0" encoding="UTF-8"?>
<genmodel:GenModel xmi:version="2.0"
    xmlns:xmi="http://www.omg.org/XMI" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore"
    xmlns:genmodel="http://www.eclipse.org/emf/2002/GenModel" modelDirectory="/it.condarelli.emf.mcwrite/src"
    modelPluginID="it.condarelli.emf.mcwrite" modelName="MCWrite" importerID="org.eclipse.emf.importer.ecore"
    complianceLevel="6.0" copyrightFields="false">
  <foreignModel>mcwrite.ecore</foreignModel>
  <genPackages prefix="MCWrite" basePackage="it.condarelli.emf" disposableProviderFactory="true"
      ecorePackage="mcwrite.ecore#/">
    <genEnums typeSafeEnumCompatible="false" ecoreEnum="mcwrite.ecore#//CharacterType">
      <genEnumLiterals ecoreEnumLiteral="mcwrite.ecore#//CharacterType/Unknown"/>
      <genEnumLiterals ecoreEnumLiteral="mcwrite.ecore#//CharacterType/World"/>
      <genEnumLiterals ecoreEnumLiteral="mcwrite.ecore#//CharacterType/Book"/>
      <genEnumLiterals ecoreEnumLiteral="mcwrite.ecore#//CharacterType/Local"/>
    </genEnums>
    <genClasses ecoreClass="mcwrite.ecore#//World">
      <genFeatures createChild="false" ecoreFeature="ecore:EAttribute mcwrite.ecore#//World/name"/>
      <genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference mcwrite.ecore#//World/books"/>
      <genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference mcwrite.ecore#//World/characters"/>
      <genFeatures createChild="false" ecoreFeature="ecore:EAttribute mcwrite.ecore#//World/desc"/>
      <genFeatures createChild="false" ecoreFeature="ecore:EAttribute mcwrite.ecore#//World/content"/>
    </genClasses>
    <genClasses ecoreClass="mcwrite.ecore#//Book">
      <genFeatures property="None" notify="false" createChild="false" ecoreFeature="ecore:EReference mcwrite.ecore#//Book/world"/>
      <genFeatures createChild="false" ecoreFeature="ecore:EAttribute mcwrite.ecore#//Book/title"/>
      <genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference mcwrite.ecore#//Book/characters"/>
      <genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference mcwrite.ecore#//Book/chapters"/>
      <genFeatures createChild="false" ecoreFeature="ecore:EAttribute mcwrite.ecore#//Book/desc"/>
      <genFeatures createChild="false" ecoreFeature="ecore:EAttribute mcwrite.ecore#//Book/content"/>
    </genClasses>
    <genClasses ecoreClass="mcwrite.ecore#//Chapter">
      <genFeatures property="None" notify="false" createChild="false" ecoreFeature="ecore:EReference mcwrite.ecore#//Chapter/book"/>
      <genFeatures createChild="false" ecoreFeature="ecore:EAttribute mcwrite.ecore#//Chapter/title"/>
      <genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference mcwrite.ecore#//Chapter/characters"/>
      <genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference mcwrite.ecore#//Chapter/scenes"/>
      <genFeatures createChild="false" ecoreFeature="ecore:EAttribute mcwrite.ecore#//Chapter/desc"/>
      <genFeatures createChild="false" ecoreFeature="ecore:EAttribute mcwrite.ecore#//Chapter/content"/>
    </genClasses>
    <genClasses ecoreClass="mcwrite.ecore#//Scene">
      <genFeatures property="None" notify="false" createChild="false" ecoreFeature="ecore:EReference mcwrite.ecore#//Scene/chapter"/>
      <genFeatures createChild="false" ecoreFeature="ecore:EAttribute mcwrite.ecore#//Scene/title"/>
      <genFeatures notify="false" createChild="false" propertySortChoices="true" ecoreFeature="ecore:EReference mcwrite.ecore#//Scene/viewPoint"/>
      <genFeatures notify="false" createChild="false" propertySortChoices="true" ecoreFeature="ecore:EReference mcwrite.ecore#//Scene/actors"/>
      <genFeatures createChild="false" ecoreFeature="ecore:EAttribute mcwrite.ecore#//Scene/desc"/>
      <genFeatures createChild="false" ecoreFeature="ecore:EAttribute mcwrite.ecore#//Scene/content"/>
    </genClasses>
    <genClasses ecoreClass="mcwrite.ecore#//Character">
      <genFeatures createChild="false" ecoreFeature="ecore:EAttribute mcwrite.ecore#//Character/name"/>
      <genFeatures property="Readonly" createChild="false" ecoreFeature="ecore:EAttribute mcwrite.ecore#//Character/type"/>
      <genFeatures createChild="false" ecoreFeature="ecore:EAttribute mcwrite.ecore#//Character/alias"/>
      <genFeatures createChild="false" ecoreFeature="ecore:EAttribute mcwrite.ecore#//Character/desc"/>
      <genFeatures createChild="false" ecoreFeature="ecore:EAttribute mcwrite.ecore#//Character/bio"/>
    </genClasses>
  </genPackages>
</genmodel:GenModel>



Here is the code I modified in SceneItemProvider.java:
	private  List<Character> getCharacters(Object o) {
		List<Character> ret = new ArrayList<Character>();
		if (o instanceof Scene) {
			Scene s = (Scene) o;
			o = s.getChapter();
		}
		if (o instanceof Chapter) {
			Chapter c = (Chapter) o;
			ret.addAll(c.getCharacters());
			o = c.getBook();
		}
		if (o instanceof Book) {
			Book b = (Book) o;
			ret.addAll(b.getCharacters());
			o = b.getWorld();
		}
		if (o instanceof World) {
			World w = (World) o;
			ret.addAll(w.getCharacters());
		}
		return ret;
	}

	/**
	 * This adds a property descriptor for the View Point feature.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated NOT
	 */
	protected void addViewPointPropertyDescriptor(Object object) {
		itemPropertyDescriptors.add(
				new ItemPropertyDescriptorDecorator(object, 
						createItemPropertyDescriptor(
								((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(),
								getResourceLocator(),
								getString("_UI_Scene_viewPoint_feature"),
								getString("_UI_PropertyDescriptor_description", "_UI_Scene_viewPoint_feature", "_UI_Scene_type"),
								MCWritePackage.Literals.SCENE__VIEW_POINT,
								true,
								false,
								true,
								null,
								null,
								null)) {
					@Override
					public Collection<?> getChoiceOfValues(Object thisObject) {
						return getCharacters(thisObject);
					}
				});
	}
	/* generated (original)
	protected void addViewPointPropertyDescriptor(Object object) {
		itemPropertyDescriptors.add
			(createItemPropertyDescriptor
				(((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(),
				 getResourceLocator(),
				 getString("_UI_Scene_viewPoint_feature"),
				 getString("_UI_PropertyDescriptor_description", "_UI_Scene_viewPoint_feature", "_UI_Scene_type"),
				 MCWritePackage.Literals.SCENE__VIEW_POINT,
				 true,
				 false,
				 true,
				 null,
				 null,
				 null));
	}
	*/

	/**
	 * This adds a property descriptor for the Actors feature.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated NOT
	 */
	protected void addActorsPropertyDescriptor(Object object) {
		itemPropertyDescriptors.add(
				new ItemPropertyDescriptorDecorator(object, 
						createItemPropertyDescriptor(
								((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(),
								getResourceLocator(),
								getString("_UI_Scene_actors_feature"),
								getString("_UI_PropertyDescriptor_description", "_UI_Scene_actors_feature", "_UI_Scene_type"),
								MCWritePackage.Literals.SCENE__ACTORS,
								true,
								false,
								true,
								null,
								null,
								null))
				{
					@Override
					public Collection<?> getChoiceOfValues(Object thisObject) {
						return getCharacters(thisObject);
					}
				});
	}
	/* generated (original)
	protected void addActorsPropertyDescriptor(Object object) {
		itemPropertyDescriptors.add
			(createItemPropertyDescriptor
				(((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(),
				 getResourceLocator(),
				 getString("_UI_Scene_actors_feature"),
				 getString("_UI_PropertyDescriptor_description", "_UI_Scene_actors_feature", "_UI_Scene_type"),
				 MCWritePackage.Literals.SCENE__ACTORS,
				 true,
				 false,
				 true,
				 null,
				 null,
				 null));
	}
	*/


Please-please help me!
I am willing to send any piece of my code that could be useful to pinpoint the problem, of course!

TiA
Mauro
Re: EMF newbie question [message #487275 is a reply to message #487103] Tue, 22 September 2009 16:07 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Mauro,

Comments below.

Mauro Condarelli wrote:
> I'm getting mad :?
Angry or crazy? :-P
> I managed to have the selection working, at least it displays in the
> selector the items I think it should.
>
> So far, so good.
>
> Problem is that the properties of my "leafs" do not refresh correctly :(
> When I switch from one leaf to the other the lists remain the same,
> even if they are actually different (I checked the saved XML).
I'm not sure I follow. Is the property descriptor's getChoiceOfValues
being called each time?
>
>
> This is my tentative mcwrite.genmodel:<?xml version="1.0"
> encoding="UTF-8"?>
> <genmodel:GenModel xmi:version="2.0"
> xmlns:xmi="http://www.omg.org/XMI"
> xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore"
> xmlns:genmodel="http://www.eclipse.org/emf/2002/GenModel"
> modelDirectory="/it.condarelli.emf.mcwrite/src"
> modelPluginID="it.condarelli.emf.mcwrite" modelName="MCWrite"
> importerID="org.eclipse.emf.importer.ecore"
> complianceLevel="6.0" copyrightFields="false">
> <foreignModel>mcwrite.ecore</foreignModel>
> <genPackages prefix="MCWrite" basePackage="it.condarelli.emf"
> disposableProviderFactory="true"
> ecorePackage="mcwrite.ecore#/">
> <genEnums typeSafeEnumCompatible="false"
> ecoreEnum="mcwrite.ecore#//CharacterType">
> <genEnumLiterals
> ecoreEnumLiteral="mcwrite.ecore#//CharacterType/Unknown"/>
> <genEnumLiterals
> ecoreEnumLiteral="mcwrite.ecore#//CharacterType/World"/>
> <genEnumLiterals
> ecoreEnumLiteral="mcwrite.ecore#//CharacterType/Book"/>
> <genEnumLiterals
> ecoreEnumLiteral="mcwrite.ecore#//CharacterType/Local"/>
> </genEnums>
> <genClasses ecoreClass="mcwrite.ecore#//World">
> <genFeatures createChild="false" ecoreFeature="ecore:EAttribute
> mcwrite.ecore#//World/name"/>
> <genFeatures property="None" children="true" createChild="true"
> ecoreFeature="ecore:EReference mcwrite.ecore#//World/books"/>
> <genFeatures property="None" children="true" createChild="true"
> ecoreFeature="ecore:EReference mcwrite.ecore#//World/characters"/>
> <genFeatures createChild="false" ecoreFeature="ecore:EAttribute
> mcwrite.ecore#//World/desc"/>
> <genFeatures createChild="false" ecoreFeature="ecore:EAttribute
> mcwrite.ecore#//World/content"/>
> </genClasses>
> <genClasses ecoreClass="mcwrite.ecore#//Book">
> <genFeatures property="None" notify="false" createChild="false"
> ecoreFeature="ecore:EReference mcwrite.ecore#//Book/world"/>
> <genFeatures createChild="false" ecoreFeature="ecore:EAttribute
> mcwrite.ecore#//Book/title"/>
> <genFeatures property="None" children="true" createChild="true"
> ecoreFeature="ecore:EReference mcwrite.ecore#//Book/characters"/>
> <genFeatures property="None" children="true" createChild="true"
> ecoreFeature="ecore:EReference mcwrite.ecore#//Book/chapters"/>
> <genFeatures createChild="false" ecoreFeature="ecore:EAttribute
> mcwrite.ecore#//Book/desc"/>
> <genFeatures createChild="false" ecoreFeature="ecore:EAttribute
> mcwrite.ecore#//Book/content"/>
> </genClasses>
> <genClasses ecoreClass="mcwrite.ecore#//Chapter">
> <genFeatures property="None" notify="false" createChild="false"
> ecoreFeature="ecore:EReference mcwrite.ecore#//Chapter/book"/>
> <genFeatures createChild="false" ecoreFeature="ecore:EAttribute
> mcwrite.ecore#//Chapter/title"/>
> <genFeatures property="None" children="true" createChild="true"
> ecoreFeature="ecore:EReference mcwrite.ecore#//Chapter/characters"/>
> <genFeatures property="None" children="true" createChild="true"
> ecoreFeature="ecore:EReference mcwrite.ecore#//Chapter/scenes"/>
> <genFeatures createChild="false" ecoreFeature="ecore:EAttribute
> mcwrite.ecore#//Chapter/desc"/>
> <genFeatures createChild="false" ecoreFeature="ecore:EAttribute
> mcwrite.ecore#//Chapter/content"/>
> </genClasses>
> <genClasses ecoreClass="mcwrite.ecore#//Scene">
> <genFeatures property="None" notify="false" createChild="false"
> ecoreFeature="ecore:EReference mcwrite.ecore#//Scene/chapter"/>
> <genFeatures createChild="false" ecoreFeature="ecore:EAttribute
> mcwrite.ecore#//Scene/title"/>
> <genFeatures notify="false" createChild="false"
> propertySortChoices="true" ecoreFeature="ecore:EReference
> mcwrite.ecore#//Scene/viewPoint"/>
> <genFeatures notify="false" createChild="false"
> propertySortChoices="true" ecoreFeature="ecore:EReference
> mcwrite.ecore#//Scene/actors"/>
> <genFeatures createChild="false" ecoreFeature="ecore:EAttribute
> mcwrite.ecore#//Scene/desc"/>
> <genFeatures createChild="false" ecoreFeature="ecore:EAttribute
> mcwrite.ecore#//Scene/content"/>
> </genClasses>
> <genClasses ecoreClass="mcwrite.ecore#//Character">
> <genFeatures createChild="false" ecoreFeature="ecore:EAttribute
> mcwrite.ecore#//Character/name"/>
> <genFeatures property="Readonly" createChild="false"
> ecoreFeature="ecore:EAttribute mcwrite.ecore#//Character/type"/>
> <genFeatures createChild="false" ecoreFeature="ecore:EAttribute
> mcwrite.ecore#//Character/alias"/>
> <genFeatures createChild="false" ecoreFeature="ecore:EAttribute
> mcwrite.ecore#//Character/desc"/>
> <genFeatures createChild="false" ecoreFeature="ecore:EAttribute
> mcwrite.ecore#//Character/bio"/>
> </genClasses>
> </genPackages>
> </genmodel:GenModel>
>
>
>
> Here is the code I modified in SceneItemProvider.java: private
> List<Character> getCharacters(Object o) {
> List<Character> ret = new ArrayList<Character>();
> if (o instanceof Scene) {
> Scene s = (Scene) o;
> o = s.getChapter();
> }
> if (o instanceof Chapter) {
> Chapter c = (Chapter) o;
> ret.addAll(c.getCharacters());
> o = c.getBook();
> }
> if (o instanceof Book) {
> Book b = (Book) o;
> ret.addAll(b.getCharacters());
> o = b.getWorld();
> }
> if (o instanceof World) {
> World w = (World) o;
> ret.addAll(w.getCharacters());
> }
> return ret;
> }
>
> /**
> * This adds a property descriptor for the View Point feature.
> * <!-- begin-user-doc -->
> * <!-- end-user-doc -->
> * @generated NOT
> */
> protected void addViewPointPropertyDescriptor(Object object) {
> itemPropertyDescriptors.add(
> new ItemPropertyDescriptorDecorator(object,
> createItemPropertyDescriptor(
>
> ((ComposeableAdapterFactory)adapterFactory).getRootAdapterFa ctory(),
> getResourceLocator(),
> getString("_UI_Scene_viewPoint_feature"),
>
> getString("_UI_PropertyDescriptor_description",
> "_UI_Scene_viewPoint_feature", "_UI_Scene_type"),
>
> MCWritePackage.Literals.SCENE__VIEW_POINT,
> true,
> false,
> true,
> null,
> null,
> null)) {
> @Override
> public Collection<?> getChoiceOfValues(Object
> thisObject) {
> return getCharacters(thisObject);
> }
> });
> }
> /* generated (original)
> protected void addViewPointPropertyDescriptor(Object object) {
> itemPropertyDescriptors.add
> (createItemPropertyDescriptor
>
> (((ComposeableAdapterFactory)adapterFactory).getRootAdapterF actory(),
> getResourceLocator(),
> getString("_UI_Scene_viewPoint_feature"),
> getString("_UI_PropertyDescriptor_description",
> "_UI_Scene_viewPoint_feature", "_UI_Scene_type"),
> MCWritePackage.Literals.SCENE__VIEW_POINT,
> true,
> false,
> true,
> null,
> null,
> null));
> }
> */
>
> /**
> * This adds a property descriptor for the Actors feature.
> * <!-- begin-user-doc -->
> * <!-- end-user-doc -->
> * @generated NOT
> */
> protected void addActorsPropertyDescriptor(Object object) {
> itemPropertyDescriptors.add(
> new ItemPropertyDescriptorDecorator(object,
> createItemPropertyDescriptor(
>
> ((ComposeableAdapterFactory)adapterFactory).getRootAdapterFa ctory(),
> getResourceLocator(),
> getString("_UI_Scene_actors_feature"),
>
> getString("_UI_PropertyDescriptor_description",
> "_UI_Scene_actors_feature", "_UI_Scene_type"),
> MCWritePackage.Literals.SCENE__ACTORS,
> true,
> false,
> true,
> null,
> null,
> null))
> {
> @Override
> public Collection<?> getChoiceOfValues(Object
> thisObject) {
> return getCharacters(thisObject);
> }
> });
> }
> /* generated (original)
> protected void addActorsPropertyDescriptor(Object object) {
> itemPropertyDescriptors.add
> (createItemPropertyDescriptor
>
> (((ComposeableAdapterFactory)adapterFactory).getRootAdapterF actory(),
> getResourceLocator(),
> getString("_UI_Scene_actors_feature"),
> getString("_UI_PropertyDescriptor_description",
> "_UI_Scene_actors_feature", "_UI_Scene_type"),
> MCWritePackage.Literals.SCENE__ACTORS,
> true,
> false,
> true,
> null,
> null,
> null));
> }
> */
>
>
> Please-please help me!
I assume you've set a breakpoint in the getChoiceOfValues method to
track when it's being called?
> I am willing to send any piece of my code that could be useful to
> pinpoint the problem, of course!
It looks okay. The debugger will probably help better than me.
>
> TiA
> Mauro


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EMF newbie question [message #487475 is a reply to message #487275] Wed, 23 September 2009 11:44 Go to previous messageGo to next message
Mauro Condarelli is currently offline Mauro CondarelliFriend
Messages: 428
Registered: September 2009
Senior Member
Quote:
Mauro Condarelli wrote:
> I'm getting mad Confused
Angry or crazy? Razz

I'm just at Witt's end Sad

Quote:
> Problem is that the properties of my "leafs" do not refresh correctly Sad
> When I switch from one leaf to the other the lists remain the same,
> even if they are actually different (I checked the saved XML).
I'm not sure I follow. Is the property descriptor's getChoiceOfValues
being called each time?

My command of English language is evidently lacking... which is not unlikely, since I'm Italian Smile
What I tried to say is:

  • I am using (for testing) the generated editor, no modifications.
  • I have a small test tree I can upload, if useful.
  • The "leafs" (Scene) have references (List<Character> Actors; Character Viewpoint;) declared with contained="false".
  • The "nodes" (World, Book, Chapter) have a list of Characters (List<Character> Characters;) declared with contained="true".
  • In the "leaf" I can open the generated dialog to chose the character for the references.
  • In this case the getChoiceOfValues() *is* called and I can chose only the characters in teh currently active branch (this is correct).
  • The saved .XML reflects the various choices (this is correct).
  • If I switch from one leaf to another I see in the editor the same values that are present in the previous chosen leaf; this is *not* a simple screen-refresh problem because it happens even if i do not go directly from one leaf to the other.
  • If I open the editor dialog-box I see in the left pane the right choices (as computed using my custom getChoiceOfValues()), but in the right I find the (possibly incompatible) entries from the previous edit.
  • It seems the data structures of the editor for the non-owned references are not reloaded from the model when I switch from one leaf to the other; is it possible?

I am unable to understand what's going on and, obviously, the debugger can't help me if I don't know where I should breakpoint. The "malfunctioning" software isn't something I wrote; It is either library or generated.
What could I have done to trigger this behavior?

TiA
Mauro
Re: EMF newbie question [message #487501 is a reply to message #487475] Wed, 23 September 2009 12:58 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Mauro,

Comments below.

Mauro Condarelli wrote:
> Quote:
>> Mauro Condarelli wrote:
>> > I'm getting mad :?
>> Angry or crazy? :p
> I'm just at Witt's end :(
>
> Quote:
>> > Problem is that the properties of my "leafs" do not refresh
>> correctly :(
>> > When I switch from one leaf to the other the lists remain the same,
>> > even if they are actually different (I checked the saved XML).
>> I'm not sure I follow. Is the property descriptor's getChoiceOfValues
>> being called each time?
> My command of English language is evidently lacking... which is not
> unlikely, since I'm Italian :)
> What I tried to say is:
>
> I am using (for testing) the generated editor, no modifications.
> I have a small test tree I can upload, if useful.
> The "leafs" (Scene) have references (List<Character> Actors; Character
> Viewpoint;) declared with contained="false". The "nodes" (World, Book,
> Chapter) have a list of Characters (List<Character> Characters;)
> declared with contained="true".
> In the "leaf" I can open the generated dialog to chose the character
> for the references.
> In this case the getChoiceOfValues() *is* called and I can chose only
> the characters in teh currently active branch (this is correct).
> The saved .XML reflects the various choices (this is correct).
> If I switch from one leaf to another I see in the editor the same
> values that are present in the previous chosen leaf; this is *not* a
> simple screen-refresh problem because it happens even if i do not go
> directly from one leaf to the other.
> If I open the editor dialog-box I see in the left pane the right
> choices (as computed using my custom getChoiceOfValues()), but in the
> right I find the (possibly incompatible) entries from the previous edit.
> It seems the data structures of the editor for the non-owned
> references are not reloaded from the model when I switch from one leaf
> to the other; is it possible?
It doesn't sound possible no. Use the debugger to see how the
"currentValues" is passed to the constructor of FeatureEditorDialog.
>
> I am unable to understand what's going on and, obviously, the debugger
> can't help me if I don't know where I should breakpoint. The
> "malfunctioning" software isn't something I wrote; It is either
> library or generated.
The basic generated editors don't generally have the problem you describe...
> What could I have done to trigger this behavior?
>
> TiA
> Mauro


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EMF newbie question [message #487616 is a reply to message #487501] Wed, 23 September 2009 18:15 Go to previous messageGo to next message
Mauro Condarelli is currently offline Mauro CondarelliFriend
Messages: 428
Registered: September 2009
Senior Member
Quote:
> library or generated.
The basic generated editors don't generally have the problem you describe...
> What could I have done to trigger this behavior?


I'm pretty sure they haven't Smile
Problem is mine has it Sad

I do attach three zipfiles:
The first is the bunch of annotated interfaces I started with (here is a small error in the plugin.xml file case mismatch: MCWrite should be Mcwrite).
The second is the resulting set of plugins (this includes the hand modifications to a single file: SceneItemProvider.java).
The third is a test XML file.

Please have a look

Thanks in advance <8real sorry to pester You, but I'm quite desperate).
Mauro

P.S.: There is a limit of two attached files, so I paste the XML here:
===============================================
<?xml version="1.0" encoding="UTF-8"?>
<it.condarelli.emf.mcwrite:World xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:it.condarelli.emf.mcwrite="http:///it/condarelli/emf/mcwrite.ecore">
<books title="Book I">
<characters name="Book I - Actor"/>
<chapters title="Book I - Chapter 1">
<characters name="Book I - Chapter 1 - Actor"/>
<scenes title="Book I - Chapter 1 - Scene a"/>
<scenes title="Book I - Chapter 1 - Scene b" viewPoint="//@books.0/@chapters.1/@characters.0" actors="//@books.0/@chapters.0/@characters.0"/>
</chapters>
<chapters title="Book I - Chapter 2">
<characters name="Book I - Chapter 2 - Actor"/>
<scenes title="Book I - Chapter 2 - Scene a"/>
<scenes title="Book I - Chapter 2 - Scene b"/>
</chapters>
</books>
<books title="Book II">
<characters name="Book II - Actor"/>
<chapters title="Book II - Chapter 1">
<characters name="Book II - Chapter 1 - Actor"/>
<scenes title="Book II - Chapter 1 - Scene a"/>
<scenes title="Book II - Chapter 1 - Scene b"/>
</chapters>
<chapters title="Book II - Chapter 2">
<characters name="Book II - Chapter 2 - Actor"/>
<scenes title="Book II - Chapter 2 - Scene a"/>
<scenes title="Book II - Chapter 2 - Scene b"/>
</chapters>
</books>
<characters name="World - Actor"/>
</it.condarelli.emf.mcwrite:World>
===============================================
Re: EMF newbie question [message #487684 is a reply to message #487616] Thu, 24 September 2009 07:18 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Mauro,

Comments below.

Mauro Condarelli wrote:
> Quote:
>> > library or generated.
>> The basic generated editors don't generally have the problem you
>> describe...
>> > What could I have done to trigger this behavior?
>
>
> I'm pretty sure they haven't :)
You didn't start out describing this problem, it seemed to have started
happening after I told you about property descriptors...
> Problem is mine has it :(
>
> I do attach three zipfiles:
I don't see them though.
> The first is the bunch of annotated interfaces I started with (here is
> a small error in the plugin.xml file case mismatch: MCWrite should be
> Mcwrite).
> The second is the resulting set of plugins (this includes the hand
> modifications to a single file: SceneItemProvider.java).
See, there are changes.
> The third is a test XML file.
>
> Please have a look
>
> Thanks in advance <8real sorry to pester You, but I'm quite desperate).
In the last note I suggested where to set a breakpoint. That's really
your best bet. Did you know about Ctrl-Shift-T for finding classes when
you know just their names?
> Mauro
>
> P.S.: There is a limit of two attached files, so I paste the XML here:
> ===============================================
> <?xml version="1.0" encoding="UTF-8"?>
> <it.condarelli.emf.mcwrite:World xmi:version="2.0"
> xmlns:xmi="http://www.omg.org/XMI"
> xmlns:it.condarelli.emf.mcwrite="http:///it/condarelli/emf/mcwrite.ecore">
>
> <books title="Book I">
> <characters name="Book I - Actor"/>
> <chapters title="Book I - Chapter 1">
> <characters name="Book I - Chapter 1 - Actor"/>
> <scenes title="Book I - Chapter 1 - Scene a"/>
> <scenes title="Book I - Chapter 1 - Scene b"
> viewPoint="//@books.0/@chapters.1/@characters.0"
> actors="//@books.0/@chapters.0/@characters.0"/>
> </chapters>
> <chapters title="Book I - Chapter 2">
> <characters name="Book I - Chapter 2 - Actor"/>
> <scenes title="Book I - Chapter 2 - Scene a"/>
> <scenes title="Book I - Chapter 2 - Scene b"/>
> </chapters>
> </books>
> <books title="Book II">
> <characters name="Book II - Actor"/>
> <chapters title="Book II - Chapter 1">
> <characters name="Book II - Chapter 1 - Actor"/>
> <scenes title="Book II - Chapter 1 - Scene a"/>
> <scenes title="Book II - Chapter 1 - Scene b"/>
> </chapters>
> <chapters title="Book II - Chapter 2">
> <characters name="Book II - Chapter 2 - Actor"/>
> <scenes title="Book II - Chapter 2 - Scene a"/>
> <scenes title="Book II - Chapter 2 - Scene b"/>
> </chapters>
> </books>
> <characters name="World - Actor"/>
> </it.condarelli.emf.mcwrite:World>
> ===============================================
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EMF newbie question [solved] [message #488157 is a reply to message #487684] Fri, 25 September 2009 17:44 Go to previous messageGo to next message
Mauro Condarelli is currently offline Mauro CondarelliFriend
Messages: 428
Registered: September 2009
Senior Member
Thanks for the hints.
I managed to make the default editor work.

Problem was some misunderstanding about what to do.

I am still puzzled though:

This is the working code:
	protected void addActorsPropertyDescriptor(Object object) {
		itemPropertyDescriptors.add(
				new ItemPropertyDescriptor(
						((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(),
						getResourceLocator(),
						getString("_UI_Scene_actors_feature"),
						getString("_UI_PropertyDescriptor_description", "_UI_Scene_actors_feature", "_UI_Scene_type"),
						McwritePackage.Literals.SCENE__ACTORS,
						true,
						false,
						true,
						null,
						null,
						null
				) {
					@Override
					public Collection<?> getChoiceOfValues(Object thisObject) {
						return getActors(thisObject);
					}
				});
	}

while this is the not working code:
	protected void addActorsPropertyDescriptor(Object object) {
		itemPropertyDescriptors.add(
				new ItemPropertyDescriptorDecorator(
						object,
						createItemPropertyDescriptor(
								((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(),
								getResourceLocator(),
								getString("_UI_Scene_actors_feature"),
								getString("_UI_PropertyDescriptor_description", "_UI_Scene_actors_feature", "_UI_Scene_type"),
								McwritePackage.Literals.SCENE__ACTORS,
								true,
								false,
								true,
								null,
								null,
								null) 
				) {
					@Override
					public Collection<?> getChoiceOfValues(Object thisObject) {
						return getActors(thisObject);
					}
				});
	}


To my understanding (and perusal of code) they should be equivalent, but obviously aren't.
Can someone explain me what I'm not seeing?

Anyways, as said, it now works.
Many thanks for the (undeserved) help.

Best Regards
Mauro
Re: EMF newbie question [solved] [message #488162 is a reply to message #488157] Fri, 25 September 2009 17:51 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Mauro,

The logic to add the property descriptors isn't called repeatedly, at
least by default, it's done once and cached for all objects of that
type. The second approach locks the descriptor onto the first object
for which descriptors are needed...

Mauro Condarelli wrote:
> Thanks for the hints.
> I managed to make the default editor work.
>
> Problem was some misunderstanding about what to do.
>
> I am still puzzled though:
>
> This is the working code:
> protected void addActorsPropertyDescriptor(Object object) {
> itemPropertyDescriptors.add(
> new ItemPropertyDescriptor(
>
> ((ComposeableAdapterFactory)adapterFactory).getRootAdapterFa ctory(),
> getResourceLocator(),
> getString("_UI_Scene_actors_feature"),
>
> getString("_UI_PropertyDescriptor_description",
> "_UI_Scene_actors_feature", "_UI_Scene_type"),
> McwritePackage.Literals.SCENE__ACTORS,
> true,
> false,
> true,
> null,
> null,
> null
> ) {
> @Override
> public Collection<?> getChoiceOfValues(Object
> thisObject) {
> return getActors(thisObject);
> }
> });
> }
>
> while this is the not working code:
> protected void addActorsPropertyDescriptor(Object object) {
> itemPropertyDescriptors.add(
> new ItemPropertyDescriptorDecorator(
> object,
> createItemPropertyDescriptor(
>
> ((ComposeableAdapterFactory)adapterFactory).getRootAdapterFa ctory(),
> getResourceLocator(),
> getString("_UI_Scene_actors_feature"),
>
> getString("_UI_PropertyDescriptor_description",
> "_UI_Scene_actors_feature", "_UI_Scene_type"),
> McwritePackage.Literals.SCENE__ACTORS,
> true,
> false,
> true,
> null,
> null,
> null) ) {
> @Override
> public Collection<?> getChoiceOfValues(Object
> thisObject) {
> return getActors(thisObject);
> }
> });
> }
>
>
> To my understanding (and perusal of code) they should be equivalent,
> but obviously aren't.
> Can someone explain me what I'm not seeing?
>
> Anyways, as said, it now works.
> Many thanks for the (undeserved) help.
>
> Best Regards
> Mauro


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EMF newbie question [message #545648 is a reply to message #486746] Thu, 08 July 2010 13:53 Go to previous message
Christophe Bouhier is currently offline Christophe BouhierFriend
Messages: 937
Registered: July 2009
Senior Member
Hi,

See inline below. Can you be specific about which UI part you refer to ?

Mauro Condarelli wrote:
> Hi,
> I'm here again :blush:
> I managed to make this work.
>
> Next problem:
>
> I have a tree structure and each node has an EList holding some of the
> same kind of information (users, in this case). Here I have
> 'containment="true"'.
>
> The leafs do have an EList of references to users (containment="false").
>

> The generated editor shows, for the leafs, all users defined (contained)
> everywhere in the tree.
>
What do you mean by shows? Only the contained users would appear as a
branch on this tree. A non contained user will not be shown in the
outline, but would appear in the properties view and editable with a
feature selector dialog. Is this what you mean?

> I would like to restrict the possible choices to just the users

Which choices are you referring to?

> contained in the nodes in the path that leads from the root to the leaf.
> I.E.: the leaf should have (an EList of references to) a subset of the
> users defined in the branch.
> How can I do this?
>
> Other thing: how can I specify custom icons for the various node elements?
EMF by default produces icons for your model objects in you
..edit/icons/full/obj16 folder. Simply replace them and you will see a
different icon.


>
> Thanks a lot for Your patience
> Mauro
Previous Topic:Setting eContainer for EObjects of a dynamically created EPackage
Next Topic:EMF Model migration dilemma.
Goto Forum:
  


Current Time: Tue Apr 23 13:16:56 GMT 2024

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

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

Back to the top