Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » CreateChildCommand and the EStructuralFeature
CreateChildCommand and the EStructuralFeature [message #422477] Sun, 07 September 2008 13:31 Go to next message
Eclipse UserFriend
Originally posted by: andreas-scharf.gmx.de

Hi,

I'm trying to implement programmtic creation of CreateChildCommands. In
my GEF editor I can use tools to build new model elements into existing
ones, so at the time where I am asked for the command to actually create
the child I only know which child to create in which parent but not the
EStructuralFeature. So I thought that

CreateChildCommand.create(editingDomain, parent, new
CommandParameter(null, null, newChild), Collections.EMPTY_LIST));

will do the thing and my ItemProvider will fill in the correct feature.
But that's not the case. I can imagine that this is not always possible
(in cases where I have to different references which could potentially
hold the childs type). How do I solve that problem? Do I have to ask my
ItemProvider myself for the childrenFeatures (via
getChildrenFeatures(Object)) and pick the correct feature? Or am I
missing something?

Thx,
Andreas
Re: CreateChildCommand and the EStructuralFeature [message #422478 is a reply to message #422477] Sun, 07 September 2008 13:45 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Andreas,

Comments below.

Andreas Scharf wrote:
> Hi,
>
> I'm trying to implement programmtic creation of CreateChildCommands.
> In my GEF editor I can use tools to build new model elements into
> existing ones, so at the time where I am asked for the command to
> actually create the child I only know which child to create in which
> parent but not the
> EStructuralFeature. So I thought that
>
> CreateChildCommand.create(editingDomain, parent, new
> CommandParameter(null, null, newChild), Collections.EMPTY_LIST));
>
> will do the thing and my ItemProvider will fill in the correct
> feature. But that's not the case. I can imagine that this is not
> always possible (in cases where I have to different references which
> could potentially hold the childs type). How do I solve that problem?
> Do I have to ask my ItemProvider myself for the childrenFeatures (via
> getChildrenFeatures(Object)) and pick the correct feature? Or am I
> missing something?
I wonder how can you be sure the parent even has a feature to hold the
child you've created? There's a protected getChildFeature that does
this kind of work, but I don't really understand why you wouldn't know
in advance what type of relation you are trying to create between the
parent and its child...
>
> Thx,
> Andreas


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: CreateChildCommand and the EStructuralFeature [message #422479 is a reply to message #422478] Sun, 07 September 2008 13:59 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: andreas-scharf.gmx.de

Ed,

> I wonder how can you be sure the parent even has a feature to hold the
> child you've created?

Yes - that's right! The command then wouldn't be executable which in my
GEF editor would result in showing the user that he/she is not allowed
to build this child in this parent.

I don't know how familiar you are with editPolicys in GEF. But basically
I get a CreateRequest with the child that should be created. The
EditPolicy is installed at an EditPart from where I then know the
parent. What I know need is the right feature. Of course I could
hard-code things like if(child instanceof A) feature = aReference. But
that would cost a lot of work and is not very flexible.

Maybe I'm missing something obvious but I don't know what. Before I
worked with "normal" GEF commands, now Im trying to switch to EMF
Transactional and to adapt all my GEF commands to equivalent EMF stuff.
In GEF I had a method like getSuitableReference(EObject parent,EObject
child) to get the feature.


Ed Merks schrieb:
> Andreas,
>
> Comments below.
>
> Andreas Scharf wrote:
>> Hi,
>>
>> I'm trying to implement programmtic creation of CreateChildCommands.
>> In my GEF editor I can use tools to build new model elements into
>> existing ones, so at the time where I am asked for the command to
>> actually create the child I only know which child to create in which
>> parent but not the
>> EStructuralFeature. So I thought that
>>
>> CreateChildCommand.create(editingDomain, parent, new
>> CommandParameter(null, null, newChild), Collections.EMPTY_LIST));
>>
>> will do the thing and my ItemProvider will fill in the correct
>> feature. But that's not the case. I can imagine that this is not
>> always possible (in cases where I have to different references which
>> could potentially hold the childs type). How do I solve that problem?
>> Do I have to ask my ItemProvider myself for the childrenFeatures (via
>> getChildrenFeatures(Object)) and pick the correct feature? Or am I
>> missing something?
> I wonder how can you be sure the parent even has a feature to hold the
> child you've created? There's a protected getChildFeature that does
> this kind of work, but I don't really understand why you wouldn't know
> in advance what type of relation you are trying to create between the
> parent and its child...
>>
>> Thx,
>> Andreas
Re: CreateChildCommand and the EStructuralFeature [message #422480 is a reply to message #422479] Sun, 07 September 2008 14:10 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------020005080906050006040307
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

Andreas,

You could specialize all your item providers like this:

protected Command createCreateChildCommand(EditingDomain domain,
EObject owner, EStructuralFeature feature, Object value, int index,
Collection<?> collection)
{
return new CreateChildCommand(domain, owner, feature== null ?
getChildFeature(owner, value) : feature, value, index, collection,
this);
}

Hopefully you have one root class or a small number in which you can do
this. Or you could use the "Provider Root Extends Class" property in
the GenModel to specify a specialized ItemProviderAdapter from which all
your root providers will inherit.


Andreas Scharf wrote:
> Ed,
>
> > I wonder how can you be sure the parent even has a feature to hold the
> > child you've created?
>
> Yes - that's right! The command then wouldn't be executable which in
> my GEF editor would result in showing the user that he/she is not
> allowed to build this child in this parent.
>
> I don't know how familiar you are with editPolicys in GEF. But
> basically I get a CreateRequest with the child that should be
> created. The EditPolicy is installed at an EditPart from where I then
> know the parent. What I know need is the right feature. Of course I
> could hard-code things like if(child instanceof A) feature =
> aReference. But that would cost a lot of work and is not very flexible.
>
> Maybe I'm missing something obvious but I don't know what. Before I
> worked with "normal" GEF commands, now Im trying to switch to EMF
> Transactional and to adapt all my GEF commands to equivalent EMF
> stuff. In GEF I had a method like getSuitableReference(EObject
> parent,EObject child) to get the feature.
>
>
> Ed Merks schrieb:
>> Andreas,
>>
>> Comments below.
>>
>> Andreas Scharf wrote:
>>> Hi,
>>>
>>> I'm trying to implement programmtic creation of CreateChildCommands.
>>> In my GEF editor I can use tools to build new model elements into
>>> existing ones, so at the time where I am asked for the command to
>>> actually create the child I only know which child to create in which
>>> parent but not the
>>> EStructuralFeature. So I thought that
>>>
>>> CreateChildCommand.create(editingDomain, parent, new
>>> CommandParameter(null, null, newChild), Collections.EMPTY_LIST));
>>>
>>> will do the thing and my ItemProvider will fill in the correct
>>> feature. But that's not the case. I can imagine that this is not
>>> always possible (in cases where I have to different references which
>>> could potentially hold the childs type). How do I solve that
>>> problem? Do I have to ask my ItemProvider myself for the
>>> childrenFeatures (via getChildrenFeatures(Object)) and pick the
>>> correct feature? Or am I missing something?
>> I wonder how can you be sure the parent even has a feature to hold
>> the child you've created? There's a protected getChildFeature that
>> does this kind of work, but I don't really understand why you
>> wouldn't know in advance what type of relation you are trying to
>> create between the parent and its child...
>>>
>>> Thx,
>>> Andreas

--------------020005080906050006040307
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">
Andreas,<br>
<br>
You could specialize all your item providers like this:<br>
<blockquote><small>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: CreateChildCommand and the EStructuralFeature [message #422481 is a reply to message #422480] Sun, 07 September 2008 14:18 Go to previous message
Eclipse UserFriend
Originally posted by: andreas-scharf.gmx.de

Ed,

ok, I think this would work. I'll try that and thanks for your fast help!


Ed Merks schrieb:
> Andreas,
>
> You could specialize all your item providers like this:
>
> protected Command createCreateChildCommand(EditingDomain domain,
> EObject owner, EStructuralFeature feature, Object value, int index,
> Collection<?> collection)
> {
> return new CreateChildCommand(domain, owner, feature== null ?
> getChildFeature(owner, value) : feature, value, index, collection,
> this);
> }
>
> Hopefully you have one root class or a small number in which you can do
> this. Or you could use the "Provider Root Extends Class" property in
> the GenModel to specify a specialized ItemProviderAdapter from which all
> your root providers will inherit.
>
>
> Andreas Scharf wrote:
>> Ed,
>>
>> > I wonder how can you be sure the parent even has a feature to hold the
>> > child you've created?
>>
>> Yes - that's right! The command then wouldn't be executable which in
>> my GEF editor would result in showing the user that he/she is not
>> allowed to build this child in this parent.
>>
>> I don't know how familiar you are with editPolicys in GEF. But
>> basically I get a CreateRequest with the child that should be
>> created. The EditPolicy is installed at an EditPart from where I then
>> know the parent. What I know need is the right feature. Of course I
>> could hard-code things like if(child instanceof A) feature =
>> aReference. But that would cost a lot of work and is not very flexible.
>>
>> Maybe I'm missing something obvious but I don't know what. Before I
>> worked with "normal" GEF commands, now Im trying to switch to EMF
>> Transactional and to adapt all my GEF commands to equivalent EMF
>> stuff. In GEF I had a method like getSuitableReference(EObject
>> parent,EObject child) to get the feature.
>>
>>
>> Ed Merks schrieb:
>>> Andreas,
>>>
>>> Comments below.
>>>
>>> Andreas Scharf wrote:
>>>> Hi,
>>>>
>>>> I'm trying to implement programmtic creation of CreateChildCommands.
>>>> In my GEF editor I can use tools to build new model elements into
>>>> existing ones, so at the time where I am asked for the command to
>>>> actually create the child I only know which child to create in which
>>>> parent but not the
>>>> EStructuralFeature. So I thought that
>>>>
>>>> CreateChildCommand.create(editingDomain, parent, new
>>>> CommandParameter(null, null, newChild), Collections.EMPTY_LIST));
>>>>
>>>> will do the thing and my ItemProvider will fill in the correct
>>>> feature. But that's not the case. I can imagine that this is not
>>>> always possible (in cases where I have to different references which
>>>> could potentially hold the childs type). How do I solve that
>>>> problem? Do I have to ask my ItemProvider myself for the
>>>> childrenFeatures (via getChildrenFeatures(Object)) and pick the
>>>> correct feature? Or am I missing something?
>>> I wonder how can you be sure the parent even has a feature to hold
>>> the child you've created? There's a protected getChildFeature that
>>> does this kind of work, but I don't really understand why you
>>> wouldn't know in advance what type of relation you are trying to
>>> create between the parent and its child...
>>>>
>>>> Thx,
>>>> Andreas
Previous Topic:Exception thrown when calling eClass
Next Topic:[Teneo] FK generation when 0..1 cardinality
Goto Forum:
  


Current Time: Fri Apr 26 18:26:32 GMT 2024

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

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

Back to the top