Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Deleting child reference deletes referent?
Deleting child reference deletes referent? [message #417058] Mon, 25 February 2008 15:59 Go to next message
Mike Gering is currently offline Mike GeringFriend
Messages: 41
Registered: July 2009
Member
I would like to show non-containment references in my model as children
of the reference owner. It works fine when I set the genmodel properties
chilren=true, notify=true for the reference. I can dnd existing
instances to the owner and they get added to the reference list.

However, if I delete a reference, not only does the reference get
deleted, but the referent, too. This seems counter-intuitive to me. Is
this the way it is supposed to work? Is there a way to get the behavior
I want?

I'm using EMF 2.2 and I have not found this problem described in the
newsgroup.

Thanks,
Mike Gering
Re: Deleting child reference deletes referent? [message #417061 is a reply to message #417058] Mon, 25 February 2008 16:45 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Mike,

DeleteAction does have a constructor that lets you specify true or false
for removeAllReferences. Normally deleting something really does mean
that the object is going away and all reference to it should be
cleared. Likely you want some kind of hybrid approach...


Mike Gering wrote:
> I would like to show non-containment references in my model as
> children of the reference owner. It works fine when I set the genmodel
> properties chilren=true, notify=true for the reference. I can dnd
> existing instances to the owner and they get added to the reference list.
>
> However, if I delete a reference, not only does the reference get
> deleted, but the referent, too. This seems counter-intuitive to me. Is
> this the way it is supposed to work? Is there a way to get the
> behavior I want?
>
> I'm using EMF 2.2 and I have not found this problem described in the
> newsgroup.
>
> Thanks,
> Mike Gering


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Deleting child reference deletes referent? [message #417062 is a reply to message #417061] Mon, 25 February 2008 16:58 Go to previous messageGo to next message
Mike Gering is currently offline Mike GeringFriend
Messages: 41
Registered: July 2009
Member
Ed,

I think you may misunderstand. I want to delete the non-containment
reference to the object, not the object being referenced. When I see the
reference in the tree,and delete it, I would not expect the referenced
object to be deleted. When I delete the reference in the
FeatureEditorDialog, it deletes only the reference. Why should it behave
differently in the tree editor?

Thanks,
Mike
Ed Merks wrote:
> Mike,
>
> DeleteAction does have a constructor that lets you specify true or false
> for removeAllReferences. Normally deleting something really does mean
> that the object is going away and all reference to it should be
> cleared. Likely you want some kind of hybrid approach...
>
>
> Mike Gering wrote:
>> I would like to show non-containment references in my model as
>> children of the reference owner. It works fine when I set the genmodel
>> properties chilren=true, notify=true for the reference. I can dnd
>> existing instances to the owner and they get added to the reference list.
>>
>> However, if I delete a reference, not only does the reference get
>> deleted, but the referent, too. This seems counter-intuitive to me. Is
>> this the way it is supposed to work? Is there a way to get the
>> behavior I want?
>>
>> I'm using EMF 2.2 and I have not found this problem described in the
>> newsgroup.
>>
>> Thanks,
>> Mike Gering
Re: Deleting child reference deletes referent? [message #417064 is a reply to message #417062] Mon, 25 February 2008 17:37 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.
--------------070209030505070108030001
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Mike,

No. I understood that. :-P But the action you invoke is delete and it
is applied to an object direct. Indeed when using the dialog you are
manipulating only references to the object, not asking for the object
itself to be deleted. You'll see the flag I mentioned toggles between
using a delete command and a remove command where the dialog is only
using the latter:

| @Override
*public *Command createCommand(Collection<?> selection)
{
*return *removeAllReferences ? DeleteCommand.create(domain, selection) : RemoveCommand.create(domain, selection);
}|

I could imagine specialized AdapterFactoryEditingDomain.createCommand to
specialize this case:

| *else if *(commandClass == DeleteCommand.*class*)
{
*return new *DeleteCommand(this, commandParameter.getCollection());
}|


You might pick apart the selection, and if you are operating on a
wrapper, you could just do a remove instead of a delete...


Mike Gering wrote:
> Ed,
>
> I think you may misunderstand. I want to delete the non-containment
> reference to the object, not the object being referenced. When I see
> the reference in the tree,and delete it, I would not expect the
> referenced object to be deleted. When I delete the reference in the
> FeatureEditorDialog, it deletes only the reference. Why should it
> behave differently in the tree editor?
>
> Thanks,
> Mike
> Ed Merks wrote:
>> Mike,
>>
>> DeleteAction does have a constructor that lets you specify true or
>> false for removeAllReferences. Normally deleting something really
>> does mean that the object is going away and all reference to it
>> should be cleared. Likely you want some kind of hybrid approach...
>>
>>
>> Mike Gering wrote:
>>> I would like to show non-containment references in my model as
>>> children of the reference owner. It works fine when I set the
>>> genmodel properties chilren=true, notify=true for the reference. I
>>> can dnd existing instances to the owner and they get added to the
>>> reference list.
>>>
>>> However, if I delete a reference, not only does the reference get
>>> deleted, but the referent, too. This seems counter-intuitive to me.
>>> Is this the way it is supposed to work? Is there a way to get the
>>> behavior I want?
>>>
>>> I'm using EMF 2.2 and I have not found this problem described in the
>>> newsgroup.
>>>
>>> Thanks,
>>> Mike Gering


--------------070209030505070108030001
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Mike,<br>
<br>
No.&nbsp; I understood that.&nbsp; :-P&nbsp; But the action you invoke is delete and
it is applied to an object direct.&nbsp; Indeed when using the dialog you
are manipulating only references to the object, not asking for the
object itself to be deleted.&nbsp; You'll see the flag I mentioned toggles
between using a delete command and a remove command where the dialog is
only using the latter:<br>
<blockquote>
<title></title>
<style type="text/css">
<!--code { font-family: Courier New, Courier; font-size: 10pt; margin: 0px; }-->
</style>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<!-- ======================================================== --><!-- = Java Sourcecode to HTML automatically converted code = --><!-- = Java2Html Converter 5.0 [2006-02-26] by Markus Gebhard markus@jave.de = -->
<!-- = Further information: http://www.java2html.de = -->
<div class="java" align="left">
<table bgcolor="#ffffff" border="0" cellpadding="3" cellspacing="0">
<tbody>
<tr>
<!-- start source code --> <td align="left" nowrap="nowrap"
valign="top"> <code><font color="#ffffff">&nbsp;&nbsp;</font><font
color="#646464">@Override</font><br>
<font color="#ffffff">&nbsp;&nbsp;</font><font color="#7f0055"><b>public&nbsp;</b></font><font
color="#000000">Command&nbsp;createCommand</font><font color="#000000">(</font><font
color="#000000">Collection&lt;?&gt;&nbsp;selection </font><font
color="#000000">)</font><br>
<font color="#ffffff">&nbsp;&nbsp;</font><font color="#000000">{</font><br>
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font ><font color="#7f0055"><b>return&nbsp;</b></font><font
color="#000000"> removeAllReferences&nbsp;?&nbsp;DeleteCommand.create </font><font
color="#000000">(</font><font color="#000000">domain,&nbsp;selection</font><font
color="#000000">)&nbsp;</font><font color="#000000">:&nbsp;RemoveCommand.create</font><font
color="#000000">(</font><font color="#000000">domain,&nbsp;selection</font><font
color="#000000">)</font><font color="#000000">;</font><br>
<font color="#ffffff">&nbsp;&nbsp;</font><font color="#000000">}</font></code>
</td>
<!-- end source code --> </tr>
</tbody>
</table>
</div>
<!-- = END of automatically generated HTML code = -->
<!-- ======================================================== --></blockquote>
I could imagine specialized AdapterFactoryEditingDomain.createCommand
to specialize this case:<br>
<title></title>
<style type="text/css">
<!--code { font-family: Courier New, Courier; font-size: 10pt; margin: 0px; }-->
</style>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<!-- ======================================================== -->
<!-- = Java Sourcecode to HTML automatically converted code = --><!-- = Java2Html Converter 5.0 [2006-02-26] by Markus Gebhard markus@jave.de = -->
<!-- = Further information: http://www.java2html.de = -->
<blockquote>
<div class="java" align="left">
<table bgcolor="#ffffff" border="0" cellpadding="3" cellspacing="0">
<tbody>
<tr>
<!-- start source code --> <td align="left" nowrap="nowrap"
valign="top"> <code><font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font ><font
color="#7f0055"><b>else&nbsp;if&nbsp;</b></font ><font color="#000000">(</font><font
color="#000000">commandClass&nbsp;==&nbsp;DeleteCommand. </font><font
color="#7f0055"><b>class</b></font><font color="#000000">)</font><br>
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font ><font color="#000000">{</font><br>
<font color="#ffffff"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font><font color="#7f0055"><b>return&nbsp;new&nbsp;</b></font ><font
color="#000000">DeleteCommand</font><font color="#000000">(</font><font
color="#000000">this,&nbsp;commandParameter.getCollection </font><font
color="#000000">())</font><font color="#000000">;</font><br>
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font ><font color="#000000">}</font></code>
</td>
<!-- end source code --> </tr>
</tbody>
</table>
</div>
<br>
</blockquote>
You might pick apart the selection, and if you are operating on a
wrapper, you could just do a remove instead of a delete...<br>
<br>
<!-- = END of automatically generated HTML code = -->
<!-- ======================================================== --><br>
Mike Gering wrote:
<blockquote cite="mid:fpus35$bg2$1@build.eclipse.org" type="cite">Ed,
<br>
<br>
I think you may misunderstand. I want to delete the non-containment
reference to the object, not the object being referenced. When I see
the reference in the tree,and delete it, I would not expect the
referenced object to be deleted.&nbsp; When I delete the reference in the
FeatureEditorDialog, it deletes only the reference. Why should it
behave differently in the tree editor?
<br>
<br>
Thanks,
<br>
Mike
<br>
Ed Merks wrote:
<br>
<blockquote type="cite">Mike,
<br>
<br>
DeleteAction does have a constructor that lets you specify true or
false for removeAllReferences.&nbsp; Normally deleting something really does
mean that the object is going away and all reference to it should be
cleared.&nbsp; Likely you want some kind of hybrid approach...
<br>
<br>
<br>
Mike Gering wrote:
<br>
<blockquote type="cite">I would like to show non-containment
references in my model as children of the reference owner. It works
fine when I set the genmodel properties&nbsp; chilren=true, notify=true for
the reference. I can dnd existing instances to the owner and they get
added to the reference list.
<br>
<br>
However, if I delete a reference, not only does the reference get
deleted, but the referent, too. This seems counter-intuitive to me. Is
this the way it is supposed to work? Is there a way to get the behavior
I want?
<br>
<br>
I'm using EMF 2.2 and I have not found this problem described in the
newsgroup.
<br>
<br>
Thanks,
<br>
Mike Gering
<br>
</blockquote>
</blockquote>
</blockquote>
<br>
</body>
</html>

--------------070209030505070108030001--


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Deleting child reference deletes referent? [message #417067 is a reply to message #417064] Mon, 25 February 2008 18:13 Go to previous messageGo to next message
Mike Gering is currently offline Mike GeringFriend
Messages: 41
Registered: July 2009
Member
Thanks, Ed!

Mike

Ed Merks wrote:
> Mike,
>
> No. I understood that. :-P But the action you invoke is delete and it
> is applied to an object direct. Indeed when using the dialog you are
> manipulating only references to the object, not asking for the object
> itself to be deleted. You'll see the flag I mentioned toggles between
> using a delete command and a remove command where the dialog is only
> using the latter:
>
> | @Override
> *public *Command createCommand(Collection<?> selection)
> {
> *return *removeAllReferences ? DeleteCommand.create(domain, selection) : RemoveCommand.create(domain, selection);
> }|
>
> I could imagine specialized AdapterFactoryEditingDomain.createCommand to
> specialize this case:
>
> | *else if *(commandClass == DeleteCommand.*class*)
> {
> *return new *DeleteCommand(this, commandParameter.getCollection());
> }|
>
>
> You might pick apart the selection, and if you are operating on a
> wrapper, you could just do a remove instead of a delete...
>
>
> Mike Gering wrote:
>> Ed,
>>
>> I think you may misunderstand. I want to delete the non-containment
>> reference to the object, not the object being referenced. When I see
>> the reference in the tree,and delete it, I would not expect the
>> referenced object to be deleted. When I delete the reference in the
>> FeatureEditorDialog, it deletes only the reference. Why should it
>> behave differently in the tree editor?
>>
>> Thanks,
>> Mike
>> Ed Merks wrote:
>>> Mike,
>>>
>>> DeleteAction does have a constructor that lets you specify true or
>>> false for removeAllReferences. Normally deleting something really
>>> does mean that the object is going away and all reference to it
>>> should be cleared. Likely you want some kind of hybrid approach...
>>>
>>>
>>> Mike Gering wrote:
>>>> I would like to show non-containment references in my model as
>>>> children of the reference owner. It works fine when I set the
>>>> genmodel properties chilren=true, notify=true for the reference. I
>>>> can dnd existing instances to the owner and they get added to the
>>>> reference list.
>>>>
>>>> However, if I delete a reference, not only does the reference get
>>>> deleted, but the referent, too. This seems counter-intuitive to me.
>>>> Is this the way it is supposed to work? Is there a way to get the
>>>> behavior I want?
>>>>
>>>> I'm using EMF 2.2 and I have not found this problem described in the
>>>> newsgroup.
>>>>
>>>> Thanks,
>>>> Mike Gering
>
Re: Deleting child reference deletes referent? [message #417168 is a reply to message #417067] Thu, 28 February 2008 16:30 Go to previous messageGo to next message
Mike Gering is currently offline Mike GeringFriend
Messages: 41
Registered: July 2009
Member
Ed,

The solution still eludes me. The
AdapterFactoryEditingDomain.createCommand() method doesn't have the
selection in its context. The CommandParameter.collection refers to the
model object and has nothing set for the feature, owner. etc. I can't
test anything in my specialized AdapterFactoryEditingDomain for a
reference selection versus a containment selection.

On the other hand, the DeleteAction is where delete versus remove
decision is made, as you point out. I'm thinking I need to provide a
specialization of the DeleteAction that looks for these reference
deletes, and creates special RemoveCommands for them and for the
remainder of objects, delegate to the superclass, and combine both sets
of commands. Is this on the right path, or am I heading further into the
weeds?

Thanks,
Mike

Mike Gering wrote:
> Thanks, Ed!
>
> Mike
>
> Ed Merks wrote:
>> Mike,
>>
>> No. I understood that. :-P But the action you invoke is delete and
>> it is applied to an object direct. Indeed when using the dialog you
>> are manipulating only references to the object, not asking for the
>> object itself to be deleted. You'll see the flag I mentioned toggles
>> between using a delete command and a remove command where the dialog
>> is only using the latter:
>>
>> | @Override
>> *public *Command createCommand(Collection<?> selection)
>> {
>> *return *removeAllReferences ? DeleteCommand.create(domain,
>> selection) : RemoveCommand.create(domain, selection);
>> }|
>>
>> I could imagine specialized AdapterFactoryEditingDomain.createCommand
>> to specialize this case:
>>
>> | *else if *(commandClass == DeleteCommand.*class*)
>> {
>> *return new *DeleteCommand(this,
>> commandParameter.getCollection());
>> }|
>>
>>
>> You might pick apart the selection, and if you are operating on a
>> wrapper, you could just do a remove instead of a delete...
>>
>>
>> Mike Gering wrote:
>>> Ed,
>>>
>>> I think you may misunderstand. I want to delete the non-containment
>>> reference to the object, not the object being referenced. When I see
>>> the reference in the tree,and delete it, I would not expect the
>>> referenced object to be deleted. When I delete the reference in the
>>> FeatureEditorDialog, it deletes only the reference. Why should it
>>> behave differently in the tree editor?
>>>
>>> Thanks,
>>> Mike
>>> Ed Merks wrote:
>>>> Mike,
>>>>
>>>> DeleteAction does have a constructor that lets you specify true or
>>>> false for removeAllReferences. Normally deleting something really
>>>> does mean that the object is going away and all reference to it
>>>> should be cleared. Likely you want some kind of hybrid approach...
>>>>
>>>>
>>>> Mike Gering wrote:
>>>>> I would like to show non-containment references in my model as
>>>>> children of the reference owner. It works fine when I set the
>>>>> genmodel properties chilren=true, notify=true for the reference. I
>>>>> can dnd existing instances to the owner and they get added to the
>>>>> reference list.
>>>>>
>>>>> However, if I delete a reference, not only does the reference get
>>>>> deleted, but the referent, too. This seems counter-intuitive to me.
>>>>> Is this the way it is supposed to work? Is there a way to get the
>>>>> behavior I want?
>>>>>
>>>>> I'm using EMF 2.2 and I have not found this problem described in
>>>>> the newsgroup.
>>>>>
>>>>> Thanks,
>>>>> Mike Gering
>>
Re: Deleting child reference deletes referent? [message #417169 is a reply to message #417168] Thu, 28 February 2008 16:48 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.
--------------080203030306080608070903
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Mike Gering wrote:
> Ed,
>
> The solution still eludes me. The
> AdapterFactoryEditingDomain.createCommand() method doesn't have the
> selection in its context. The CommandParameter.collection refers to
> the model object and has nothing set for the feature, owner. etc. I
> can't test anything in my specialized AdapterFactoryEditingDomain for
> a reference selection versus a containment selection.
Aren't the displayed objects under the non-containment feature
wrappers? Isn't that the case?
>
> On the other hand, the DeleteAction is where delete versus remove
> decision is made, as you point out.
It just delegates to the domain.
> I'm thinking I need to provide a specialization of the DeleteAction
> that looks for these reference deletes, and creates special
> RemoveCommands for them and for the remainder of objects, delegate to
> the superclass, and combine both sets of commands. Is this on the
> right path, or am I heading further into the weeds?
So I was imagining the doing this in the domain without need to do it in
the action...

Perhaps you need to force wrappers to be created (override
isWrappingNeeded) so you'll know when you are operating on the
referenced child as opposed to the real one actually contained.

| *protected *Object createWrapper(EObject object, EStructuralFeature feature, Object value, *int *index)
{
*if *(!isWrappingNeeded(object)) *return *value;

*if *(FeatureMapUtil.isFeatureMap(feature))
{
value = *new *FeatureMapEntryWrapperItemProvider((FeatureMap.Entry)value, object, (EAttribute)feature, index, adapterFactory, getResourceLocator());
}
*else if *(feature *instanceof *EAttribute)
{
value = *new *AttributeValueWrapperItemProvider(value, object, (EAttribute)feature, index, adapterFactory, getResourceLocator());
}
*else if *(!((EReference)feature).isContainment())
{
value = *new *DelegatingWrapperItemProvider(value, object, feature, index, adapterFactory);
}

*return *value;
}|

>
> Thanks,
> Mike
>
> Mike Gering wrote:
>> Thanks, Ed!
>>
>> Mike
>>
>> Ed Merks wrote:
>>> Mike,
>>>
>>> No. I understood that. :-P But the action you invoke is delete
>>> and it is applied to an object direct. Indeed when using the dialog
>>> you are manipulating only references to the object, not asking for
>>> the object itself to be deleted. You'll see the flag I mentioned
>>> toggles between using a delete command and a remove command where
>>> the dialog is only using the latter:
>>>
>>> | @Override
>>> *public *Command createCommand(Collection<?> selection)
>>> {
>>> *return *removeAllReferences ? DeleteCommand.create(domain,
>>> selection) : RemoveCommand.create(domain, selection);
>>> }|
>>>
>>> I could imagine specialized
>>> AdapterFactoryEditingDomain.createCommand to specialize this case:
>>>
>>> | *else if *(commandClass == DeleteCommand.*class*)
>>> {
>>> *return new *DeleteCommand(this,
>>> commandParameter.getCollection());
>>> }|
>>>
>>>
>>> You might pick apart the selection, and if you are operating on a
>>> wrapper, you could just do a remove instead of a delete...
>>>
>>>
>>> Mike Gering wrote:
>>>> Ed,
>>>>
>>>> I think you may misunderstand. I want to delete the non-containment
>>>> reference to the object, not the object being referenced. When I
>>>> see the reference in the tree,and delete it, I would not expect the
>>>> referenced object to be deleted. When I delete the reference in
>>>> the FeatureEditorDialog, it deletes only the reference. Why should
>>>> it behave differently in the tree editor?
>>>>
>>>> Thanks,
>>>> Mike
>>>> Ed Merks wrote:
>>>>> Mike,
>>>>>
>>>>> DeleteAction does have a constructor that lets you specify true or
>>>>> false for removeAllReferences. Normally deleting something really
>>>>> does mean that the object is going away and all reference to it
>>>>> should be cleared. Likely you want some kind of hybrid approach...
>>>>>
>>>>>
>>>>> Mike Gering wrote:
>>>>>> I would like to show non-containment references in my model as
>>>>>> children of the reference owner. It works fine when I set the
>>>>>> genmodel properties chilren=true, notify=true for the reference.
>>>>>> I can dnd existing instances to the owner and they get added to
>>>>>> the reference list.
>>>>>>
>>>>>> However, if I delete a reference, not only does the reference get
>>>>>> deleted, but the referent, too. This seems counter-intuitive to
>>>>>> me. Is this the way it is supposed to work? Is there a way to get
>>>>>> the behavior I want?
>>>>>>
>>>>>> I'm using EMF 2.2 and I have not found this problem described in
>>>>>> the newsgroup.
>>>>>>
>>>>>> Thanks,
>>>>>> Mike Gering
>>>


--------------080203030306080608070903
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Mike Gering wrote:
<blockquote cite="mid:fq6nj3$h7q$1@build.eclipse.org" type="cite">Ed,
<br>
<br>
The solution still eludes me. The
AdapterFactoryEditingDomain.createCommand() method doesn't have the
selection in its context. The CommandParameter.collection refers to the
model object and has nothing set for the feature, owner. etc. I can't
test anything in my specialized AdapterFactoryEditingDomain for a
reference selection versus a containment selection.<br>
</blockquote>
Aren't the displayed objects under the non-containment feature
wrappers?&nbsp; Isn't that the case?<br>
<blockquote cite="mid:fq6nj3$h7q$1@build.eclipse.org" type="cite"><br>
On the other hand, the DeleteAction is where delete versus remove
decision is made, as you point out.</blockquote>
It just delegates to the domain.<br>
<blockquote cite="mid:fq6nj3$h7q$1@build.eclipse.org" type="cite"> I'm
thinking I need to provide a specialization of the DeleteAction that
looks for these reference deletes, and creates special RemoveCommands
for them and for the remainder of objects, delegate to the superclass,
and combine both sets of commands. Is this on the right path, or am I
heading further into the weeds?
<br>
</blockquote>
So I was imagining the doing this in the domain without need to do it
in the action...<br>
<br>
Perhaps you need to force wrappers to be created (override
isWrappingNeeded) so you'll know when you are operating on the
referenced child as opposed to the real one actually contained.<br>
<blockquote>
<title></title>
<style type="text/css">
<!--code { font-family: Courier New, Courier; font-size: 10pt; margin: 0px; }-->
</style>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<!-- ======================================================== --><!-- = Java Sourcecode to HTML automatically converted code = --><!-- = Java2Html Converter 5.0 [2006-02-26] by Markus Gebhard markus@jave.de = -->
<!-- = Further information: http://www.java2html.de = -->
<div class="java" align="left">
<table bgcolor="#ffffff" border="0" cellpadding="3" cellspacing="0">
<tbody>
<tr>
<!-- start source code --> <td align="left" nowrap="nowrap"
valign="top"> <code><font color="#ffffff">&nbsp;&nbsp;</font><font
color="#7f0055"><b>protected&nbsp;</b></font><font color="#000000">Object&nbsp;createWrapper</font><font
color="#000000">(</font><font color="#000000"> EObject&nbsp;object,&nbsp;EStructuralFeature&nbs p;feature,&nbsp;Object&nbsp;value,&nbsp; </font><font
color="#7f0055"><b>int&nbsp;</b></font><font color="#000000">index</font><font
color="#000000">)</font><br>
<font color="#ffffff">&nbsp;&nbsp;</font><font color="#000000">{</font><br>
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font ><font color="#7f0055"><b>if&nbsp;</b></font><font
color="#000000">(</font><font color="#000000">!isWrappingNeeded</font><font
color="#000000">(</font><font color="#000000">object</font><font
color="#000000">))&nbsp;</font><font color="#7f0055"><b>return&nbsp;</b></font><font
color="#000000">value;</font><br>
<font color="#ffffff"></font><br>
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font ><font color="#7f0055"><b>if&nbsp;</b></font><font
color="#000000">(</font><font color="#000000">FeatureMapUtil.isFeatureMap</font><font
color="#000000">(</font><font color="#000000">feature</font><font
color="#000000">))</font><br>
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font ><font color="#000000">{</font><br>
<font color="#ffffff"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font><font color="#000000">value&nbsp;=&nbsp;</font><font
color="#7f0055"><b>new&nbsp;</b></font><font color="#000000">FeatureMapEntryWrapperItemProvider</font> <font
color="#000000">((</font><font color="#000000">FeatureMap.Entry</font><font
color="#000000">)</font><font color="#000000">value,&nbsp;object,&nbsp;</font><font
color="#000000">(</font><font color="#000000">EAttribute</font><font
color="#000000">)</font><font color="#000000"> feature,&nbsp;index,&nbsp;adapterFactory,&nbsp;g etResourceLocator </font><font
color="#000000">())</font><font color="#000000">;</font><br>
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font ><font color="#000000">}</font><br>
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font ><font color="#7f0055"><b>else&nbsp;if&nbsp;</b></font ><font
color="#000000">(</font><font color="#000000">feature&nbsp;</font><font
color="#7f0055"><b>instanceof&nbsp;</b></font><font color="#000000">EAttribute</font><font
color="#000000">)</font><br>
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font ><font color="#000000">{</font><br>
<font color="#ffffff"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font><font color="#000000">value&nbsp;=&nbsp;</font><font
color="#7f0055"><b>new&nbsp;</b></font><font color="#000000">AttributeValueWrapperItemProvider</font><font
color="#000000">(</font><font color="#000000">value,&nbsp;object,&nbsp;</font><font
color="#000000">(</font><font color="#000000">EAttribute</font><font
color="#000000">)</font><font color="#000000"> feature,&nbsp;index,&nbsp;adapterFactory,&nbsp;g etResourceLocator </font><font
color="#000000">())</font><font color="#000000">;</font><br>
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font ><font color="#000000">}</font><br>
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font ><font color="#7f0055"><b>else&nbsp;if&nbsp;</b></font ><font
color="#000000">(</font><font color="#000000">!</font><font
color="#000000">((</font><font color="#000000">EReference</font><font
color="#000000">)</font><font color="#000000">feature</font><font
color="#000000">)</font><font color="#000000">.isContainment</font><font
color="#000000">())</font><br>
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font ><font color="#000000">{</font><br>
<font color="#ffffff"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font><font color="#000000">value&nbsp;=&nbsp;</font><font
color="#7f0055"><b>new&nbsp;</b></font><font color="#000000">DelegatingWrapperItemProvider</font><font
color="#000000">(</font><font color="#000000"> value,&nbsp;object,&nbsp;feature,&nbsp;index,&am p;nbsp;adapterFactory </font><font
color="#000000">)</font><font color="#000000">;</font><br>
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font ><font color="#000000">}</font><br>
<font color="#ffffff"></font><br>
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font ><font color="#7f0055"><b>return&nbsp;</b></font><font
color="#000000">value;</font><br>
<font color="#ffffff">&nbsp;&nbsp;</font><font color="#000000">}</font></code>
</td>
<!-- end source code --> </tr>
</tbody>
</table>
</div>
<!-- = END of automatically generated HTML code = -->
<!-- ======================================================== --></blockquote>
<blockquote cite="mid:fq6nj3$h7q$1@build.eclipse.org" type="cite"><br>
Thanks,
<br>
Mike
<br>
<br>
Mike Gering wrote:
<br>
<blockquote type="cite">Thanks, Ed!
<br>
<br>
Mike
<br>
<br>
Ed Merks wrote:
<br>
<blockquote type="cite">Mike,
<br>
<br>
No.&nbsp; I understood that.&nbsp; :-P&nbsp; But the action you invoke is delete and
it is applied to an object direct.&nbsp; Indeed when using the dialog you
are manipulating only references to the object, not asking for the
object itself to be deleted.&nbsp; You'll see the flag I mentioned toggles
between using a delete command and a remove command where the dialog is
only using the latter:
<br>
<br>
&nbsp;&nbsp;&nbsp; |&nbsp; @Override
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *public *Command createCommand(Collection&lt;?&gt; selection)
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; *return *removeAllReferences ? DeleteCommand.create(domain,
selection) : RemoveCommand.create(domain, selection);
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }|
<br>
<br>
I could imagine specialized AdapterFactoryEditingDomain.createCommand
to specialize this case:
<br>
<br>
&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp; *else if *(commandClass == DeleteCommand.*class*)
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; {
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; *return new *DeleteCommand(this,
commandParameter.getCollection());
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; }|
<br>
<br>
<br>
You might pick apart the selection, and if you are operating on a
wrapper, you could just do a remove instead of a delete...
<br>
<br>
<br>
Mike Gering wrote:
<br>
<blockquote type="cite">Ed,
<br>
<br>
I think you may misunderstand. I want to delete the non-containment
reference to the object, not the object being referenced. When I see
the reference in the tree,and delete it, I would not expect the
referenced object to be deleted.&nbsp; When I delete the reference in the
FeatureEditorDialog, it deletes only the reference. Why should it
behave differently in the tree editor?
<br>
<br>
Thanks,
<br>
Mike
<br>
Ed Merks wrote:
<br>
<blockquote type="cite">Mike,
<br>
<br>
DeleteAction does have a constructor that lets you specify true or
false for removeAllReferences.&nbsp; Normally deleting something really does
mean that the object is going away and all reference to it should be
cleared.&nbsp; Likely you want some kind of hybrid approach...
<br>
<br>
<br>
Mike Gering wrote:
<br>
<blockquote type="cite">I would like to show non-containment
references in my model as children of the reference owner. It works
fine when I set the genmodel properties&nbsp; chilren=true, notify=true for
the reference. I can dnd existing instances to the owner and they get
added to the reference list.
<br>
<br>
However, if I delete a reference, not only does the reference get
deleted, but the referent, too. This seems counter-intuitive to me. Is
this the way it is supposed to work? Is there a way to get the behavior
I want?
<br>
<br>
I'm using EMF 2.2 and I have not found this problem described in the
newsgroup.
<br>
<br>
Thanks,
<br>
Mike Gering
<br>
</blockquote>
</blockquote>
</blockquote>
<br>
</blockquote>
</blockquote>
</blockquote>
<br>
</body>
</html>

--------------080203030306080608070903--


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Deleting child reference deletes referent? [message #417173 is a reply to message #417169] Thu, 28 February 2008 17:50 Go to previous messageGo to next message
Mike Gering is currently offline Mike GeringFriend
Messages: 41
Registered: July 2009
Member
Ed Merks wrote:
> Aren't the displayed objects under the non-containment feature
> wrappers? Isn't that the case?

Nope. The ItemProviderAdapter.isWrapperNeeded() method looks only for
attributes and ignores references:
for (Iterator i = getAnyChildrenFeatures(object).iterator();
i.hasNext(); )
{
EStructuralFeature f = (EStructuralFeature)i.next();
if (f instanceof EAttribute)
{
wrappingNeeded = Boolean.TRUE;
}
}


> Perhaps you need to force wrappers to be created (override
> isWrappingNeeded) so you'll know when you are operating on the
> referenced child as opposed to the real one actually contained.

I did that and lo! the chilren references get wrapped, and to my glee,
the delete command works as I want, without having to subclass change
AdapterFactoryEditingDomain. Deleting the reference child deletes the
reference only. Deleting the contained object deletes it and its
references, as before.

Mike
Re: Deleting child reference deletes referent? [message #417175 is a reply to message #417173] Thu, 28 February 2008 18:52 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Mike,

That makes sense. When we delete the wrapper, we literally only delete
the wrapper not the wrapped thing itself...


Mike Gering wrote:
> Ed Merks wrote:
>> Aren't the displayed objects under the non-containment feature
>> wrappers? Isn't that the case?
>
> Nope. The ItemProviderAdapter.isWrapperNeeded() method looks only for
> attributes and ignores references:
> for (Iterator i = getAnyChildrenFeatures(object).iterator();
> i.hasNext(); )
> {
> EStructuralFeature f = (EStructuralFeature)i.next();
> if (f instanceof EAttribute)
> {
> wrappingNeeded = Boolean.TRUE;
> }
> }
>
>
>> Perhaps you need to force wrappers to be created (override
>> isWrappingNeeded) so you'll know when you are operating on the
>> referenced child as opposed to the real one actually contained.
>
> I did that and lo! the chilren references get wrapped, and to my glee,
> the delete command works as I want, without having to subclass change
> AdapterFactoryEditingDomain. Deleting the reference child deletes the
> reference only. Deleting the contained object deletes it and its
> references, as before.
>
> Mike


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Deleting child reference deletes referent? [message #417179 is a reply to message #417175] Thu, 28 February 2008 19:30 Go to previous messageGo to next message
Mike Gering is currently offline Mike GeringFriend
Messages: 41
Registered: July 2009
Member
Ed Merks wrote:
> Mike,
>
> That makes sense. When we delete the wrapper, we literally only delete
> the wrapper not the wrapped thing itself...
>
>

This has been very educational for me. Thanks! It makes me wonder,
however, whether the existing isWrapperNeeded() method shouldn't also
wrap references.

Mike
Re: Deleting child reference deletes referent? [message #417183 is a reply to message #417179] Thu, 28 February 2008 20:02 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Mike,

EMF.Edit has had to evolved over many years and we've tried to be very
careful not to break existing clients by changes in behavior or even to
force regeneration. So while it does make sense to check in
isWrapperNeeded for non-containment references, we can't be sure that
there aren't clients who have suppressed their containment references
and are showing just non-containment references which might be derived
from containment references and hence for sure induce a proper tree
structure, i.e, no cycles and no repeat objects. I suppose we could
generate an override and make that optional...


Mike Gering wrote:
> Ed Merks wrote:
>> Mike,
>>
>> That makes sense. When we delete the wrapper, we literally only
>> delete the wrapper not the wrapped thing itself...
>>
>>
>
> This has been very educational for me. Thanks! It makes me wonder,
> however, whether the existing isWrapperNeeded() method shouldn't also
> wrap references.
>
> Mike


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Deleting child reference deletes referent? [message #417184 is a reply to message #417183] Thu, 28 February 2008 20:31 Go to previous messageGo to next message
Mike Gering is currently offline Mike GeringFriend
Messages: 41
Registered: July 2009
Member
Ed Merks wrote:
> Mike,
>
> EMF.Edit has had to evolved over many years and we've tried to be very
> careful not to break existing clients by changes in behavior or even to
> force regeneration. So while it does make sense to check in
> isWrapperNeeded for non-containment references, we can't be sure that
> there aren't clients who have suppressed their containment references
> and are showing just non-containment references which might be derived
> from containment references and hence for sure induce a proper tree
> structure, i.e, no cycles and no repeat objects. I suppose we could
> generate an override and make that optional...
>

I understand, the burdens of success :-) My first reaction is that such
an option would be useful, but I'm not confident. I like the use of
references as children in my generated editor and think the delete
reference semantic is more intuitive. But I've learned time after time
that my user interface decisions are often counter-intuitive for others.
Although an additional option in the the genmodel doesn't directly
affect users, it is an additional burden for the EMF programmer to learn
and consider. I still don't know what all the existing options do, and
it isn't easy to find out, either.

Mike
Re: Deleting child reference deletes referent? [message #417185 is a reply to message #417184] Thu, 28 February 2008 20:52 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Mike,

Yes, there are a great many, so adding ones that will be used little
doesn't have all that much appeal... It's so nice to build tools for
programmers rather than end-users, because programmers have more empathy
for the problems faced by other programmers...


Mike Gering wrote:
> Ed Merks wrote:
>> Mike,
>>
>> EMF.Edit has had to evolved over many years and we've tried to be
>> very careful not to break existing clients by changes in behavior or
>> even to force regeneration. So while it does make sense to check in
>> isWrapperNeeded for non-containment references, we can't be sure that
>> there aren't clients who have suppressed their containment references
>> and are showing just non-containment references which might be
>> derived from containment references and hence for sure induce a
>> proper tree structure, i.e, no cycles and no repeat objects. I
>> suppose we could generate an override and make that optional...
>>
>
> I understand, the burdens of success :-) My first reaction is that
> such an option would be useful, but I'm not confident. I like the use
> of references as children in my generated editor and think the delete
> reference semantic is more intuitive. But I've learned time after time
> that my user interface decisions are often counter-intuitive for
> others. Although an additional option in the the genmodel doesn't
> directly affect users, it is an additional burden for the EMF
> programmer to learn and consider. I still don't know what all the
> existing options do, and it isn't easy to find out, either.
>
> Mike


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Deleting child reference deletes referent? [message #417287 is a reply to message #417173] Tue, 04 March 2008 17:17 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: udaykabe.hotmail.com

Ed,

I am trying to do the same with the following EMF model:

I have 3 EClasses A, B and C. A has a multiplicity-many containment
reference to C, while B has a similar, non-containment reference to C. Both
A and B
display these references as children in my view. I can DND an instance of C
from A into B. Undo and Redo operations for the DND seem to work fine. If
I delete
an instance of C, both the contained and non-contained objects are deleted.
Undo
Delete throws an exception which I have not yet chased down.

I have overridden isWrappingNeeded() to return true in the item provider for
class B but doing only
this does not seem to work. Is there something else or something different
I need to do?

Thanks.

Uday

Here is the exception trace:

org.eclipse.emf.common.util.WrappedException: An exception was ignored
during command execution
at
org.eclipse.emf.common.command.BasicCommandStack.handleError (BasicCommandStack.java:279)
at
org.eclipse.emf.common.command.BasicCommandStack.undo(BasicC ommandStack.java:146)
at org.eclipse.emf.edit.ui.action.UndoAction.run(UndoAction.jav a:67)
at org.eclipse.jface.action.Action.runWithEvent(Action.java:499 )
at
org.eclipse.ui.actions.RetargetAction.runWithEvent(RetargetA ction.java:229)
at
org.eclipse.jface.action.ActionContributionItem.handleWidget Selection(ActionContributionItem.java:539)
at
org.eclipse.jface.action.ActionContributionItem.access$2(Act ionContributionItem.java:488)
at
org.eclipse.jface.action.ActionContributionItem$5.handleEven t(ActionContributionItem.java:400)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java :66)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:928)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.ja va:3348)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java :2968)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.jav a:1914)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:1878)
at
org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Work bench.java:419)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.j ava:149)
at
ws.kabe.news.presentation.NewsEditorAdvisor$Application.run( NewsEditorAdvisor.java:110)
at
org.eclipse.core.internal.runtime.PlatformActivator$1.run(Pl atformActivator.java:78)
at
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .runApplication(EclipseAppLauncher.java:92)
at
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .start(EclipseAppLauncher.java:68)
at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:400)
at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:177)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.eclipse.core.launcher.Main.invokeFramework(Main.java:336 )
at org.eclipse.core.launcher.Main.basicRun(Main.java:280)
at org.eclipse.core.launcher.Main.run(Main.java:977)
at org.eclipse.core.launcher.Main.main(Main.java:952)
Caused by:
org.eclipse.emf.common.util.BasicEList$BasicIndexOutOfBounds Exception:
index=3, size=0
at org.eclipse.emf.common.util.BasicEList.add(BasicEList.java:6 38)
at
org.eclipse.emf.edit.command.RemoveCommand.doUndo(RemoveComm and.java:461)
at
org.eclipse.emf.edit.command.AbstractOverrideableCommand.und o(AbstractOverrideableCommand.java:157)
at
org.eclipse.emf.common.command.CommandWrapper.undo(CommandWr apper.java:198)
at
org.eclipse.emf.common.command.CompoundCommand.undo(Compound Command.java:333)
at
org.eclipse.emf.common.command.BasicCommandStack.undo(BasicC ommandStack.java:141)
... 28 more



"Mike Gering" <mike@aol.com> wrote in message
news:fq6s7o$gbj$1@build.eclipse.org...
> Ed Merks wrote:
>> Aren't the displayed objects under the non-containment feature wrappers?
>> Isn't that the case?
>
> Nope. The ItemProviderAdapter.isWrapperNeeded() method looks only for
> attributes and ignores references:
> for (Iterator i = getAnyChildrenFeatures(object).iterator();
> i.hasNext(); )
> {
> EStructuralFeature f = (EStructuralFeature)i.next();
> if (f instanceof EAttribute)
> {
> wrappingNeeded = Boolean.TRUE;
> }
> }
>
>
>> Perhaps you need to force wrappers to be created (override
>> isWrappingNeeded) so you'll know when you are operating on the referenced
>> child as opposed to the real one actually contained.
>
> I did that and lo! the chilren references get wrapped, and to my glee, the
> delete command works as I want, without having to subclass change
> AdapterFactoryEditingDomain. Deleting the reference child deletes the
> reference only. Deleting the contained object deletes it and its
> references, as before.
>
> Mike
Re: Deleting child reference deletes referent? [message #417289 is a reply to message #417287] Tue, 04 March 2008 17:41 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.
--------------010902020200040201050308
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Uday,

So you've verified that wrappers are being created for the children
displayed by B? And that when you are invoking delete on that child,
it's being invoked for that wrapper?

It looks like you tried to invoke undo, but you didn't mention that...


Uday Kabe wrote:
> Ed,
>
> I am trying to do the same with the following EMF model:
>
> I have 3 EClasses A, B and C. A has a multiplicity-many containment
> reference to C, while B has a similar, non-containment reference to C. Both
> A and B
> display these references as children in my view. I can DND an instance of C
> from A into B. Undo and Redo operations for the DND seem to work fine. If
> I delete
> an instance of C, both the contained and non-contained objects are deleted.
> Undo
> Delete throws an exception which I have not yet chased down.
>
> I have overridden isWrappingNeeded() to return true in the item provider for
> class B but doing only
> this does not seem to work. Is there something else or something different
> I need to do?
>
> Thanks.
>
> Uday
>
> Here is the exception trace:
>
> org.eclipse.emf.common.util.WrappedException: An exception was ignored
> during command execution
> at
> org.eclipse.emf.common.command.BasicCommandStack.handleError (BasicCommandStack.java:279)
> at
> org.eclipse.emf.common.command.BasicCommandStack.undo(BasicC ommandStack.java:146)
> at org.eclipse.emf.edit.ui.action.UndoAction.run(UndoAction.jav a:67)
> at org.eclipse.jface.action.Action.runWithEvent(Action.java:499 )
> at
> org.eclipse.ui.actions.RetargetAction.runWithEvent(RetargetA ction.java:229)
> at
> org.eclipse.jface.action.ActionContributionItem.handleWidget Selection(ActionContributionItem.java:539)
> at
> org.eclipse.jface.action.ActionContributionItem.access$2(Act ionContributionItem.java:488)
> at
> org.eclipse.jface.action.ActionContributionItem$5.handleEven t(ActionContributionItem.java:400)
> at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java :66)
> at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:928)
> at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.ja va:3348)
> at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java :2968)
> at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.jav a:1914)
> at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:1878)
> at
> org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Work bench.java:419)
> at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.j ava:149)
> at
> ws.kabe.news.presentation.NewsEditorAdvisor$Application.run( NewsEditorAdvisor.java:110)
> at
> org.eclipse.core.internal.runtime.PlatformActivator$1.run(Pl atformActivator.java:78)
> at
> org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .runApplication(EclipseAppLauncher.java:92)
> at
> org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .start(EclipseAppLauncher.java:68)
> at
> org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:400)
> at
> org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:177)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:39)
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:25)
> at java.lang.reflect.Method.invoke(Method.java:585)
> at org.eclipse.core.launcher.Main.invokeFramework(Main.java:336 )
> at org.eclipse.core.launcher.Main.basicRun(Main.java:280)
> at org.eclipse.core.launcher.Main.run(Main.java:977)
> at org.eclipse.core.launcher.Main.main(Main.java:952)
> Caused by:
> org.eclipse.emf.common.util.BasicEList$BasicIndexOutOfBounds Exception:
> index=3, size=0
> at org.eclipse.emf.common.util.BasicEList.add(BasicEList.java:6 38)
> at
> org.eclipse.emf.edit.command.RemoveCommand.doUndo(RemoveComm and.java:461)
> at
> org.eclipse.emf.edit.command.AbstractOverrideableCommand.und o(AbstractOverrideableCommand.java:157)
> at
> org.eclipse.emf.common.command.CommandWrapper.undo(CommandWr apper.java:198)
> at
> org.eclipse.emf.common.command.CompoundCommand.undo(Compound Command.java:333)
> at
> org.eclipse.emf.common.command.BasicCommandStack.undo(BasicC ommandStack.java:141)
> ... 28 more
>
>
>
> "Mike Gering" <mike@aol.com> wrote in message
> news:fq6s7o$gbj$1@build.eclipse.org...
>
>> Ed Merks wrote:
>>
>>> Aren't the displayed objects under the non-containment feature wrappers?
>>> Isn't that the case?
>>>
>> Nope. The ItemProviderAdapter.isWrapperNeeded() method looks only for
>> attributes and ignores references:
>> for (Iterator i = getAnyChildrenFeatures(object).iterator();
>> i.hasNext(); )
>> {
>> EStructuralFeature f = (EStructuralFeature)i.next();
>> if (f instanceof EAttribute)
>> {
>> wrappingNeeded = Boolean.TRUE;
>> }
>> }
>>
>>
>>
>>> Perhaps you need to force wrappers to be created (override
>>> isWrappingNeeded) so you'll know when you are operating on the referenced
>>> child as opposed to the real one actually contained.
>>>
>> I did that and lo! the chilren references get wrapped, and to my glee, the
>> delete command works as I want, without having to subclass change
>> AdapterFactoryEditingDomain. Deleting the reference child deletes the
>> reference only. Deleting the contained object deletes it and its
>> references, as before.
>>
>> Mike
>>
>
>
>


--------------010902020200040201050308
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Uday,<br>
<br>
So you've verified that wrappers are being created for the children
displayed by B?&nbsp; And that when you are invoking delete on that child,
it's being invoked for that wrapper?<br>
<br>
It looks like you tried to invoke undo, but you didn't mention that...<br>
<br>
<br>
Uday Kabe wrote:
<blockquote cite="mid:fqk07a$7v1$1@build.eclipse.org" type="cite">
<pre wrap="">Ed,

I am trying to do the same with the following EMF model:

I have 3 EClasses A, B and C. A has a multiplicity-many containment
reference to C, while B has a similar, non-containment reference to C. Both
A and B
display these references as children in my view. I can DND an instance of C
from A into B. Undo and Redo operations for the DND seem to work fine. If
I delete
an instance of C, both the contained and non-contained objects are deleted.
Undo
Delete throws an exception which I have not yet chased down.

I have overridden isWrappingNeeded() to return true in the item provider for
class B but doing only
this does not seem to work. Is there something else or something different
I need to do?

Thanks.

Uday

Here is the exception trace:

org.eclipse.emf.common.util.WrappedException: An exception was ignored
during command execution
at
org.eclipse.emf.common.command.BasicCommandStack.handleError (BasicCommandStack.java:279)
at
org.eclipse.emf.common.command.BasicCommandStack.undo(BasicC ommandStack.java:146)
at org.eclipse.emf.edit.ui.action.UndoAction.run(UndoAction.jav a:67)
at org.eclipse.jface.action.Action.runWithEvent(Action.java:499 )
at
org.eclipse.ui.actions.RetargetAction.runWithEvent(RetargetA ction.java:229)
at
org.eclipse.jface.action.ActionContributionItem.handleWidget Selection(ActionContributionItem.java:539)
at
org.eclipse.jface.action.ActionContributionItem.access$2(Act ionContributionItem.java:488)
at
org.eclipse.jface.action.ActionContributionItem$5.handleEven t(ActionContributionItem.java:400)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java :66)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:928)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.ja va:3348)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java :2968)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.jav a:1914)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:1878)
at
org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Work bench.java:419)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.j ava:149)
at
ws.kabe.news.presentation.NewsEditorAdvisor$Application.run( NewsEditorAdvisor.java:110)
at
org.eclipse.core.internal.runtime.PlatformActivator$1.run(Pl atformActivator.java:78)
at
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .runApplication(EclipseAppLauncher.java:92)
at
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .start(EclipseAppLauncher.java:68)
at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:400)
at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:177)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.eclipse.core.launcher.Main.invokeFramework(Main.java:336 )
at org.eclipse.core.launcher.Main.basicRun(Main.java:280)
at org.eclipse.core.launcher.Main.run(Main.java:977)
at org.eclipse.core.launcher.Main.main(Main.java:952)
Caused by:
org.eclipse.emf.common.util.BasicEList$BasicIndexOutOfBounds Exception:
index=3, size=0
at org.eclipse.emf.common.util.BasicEList.add(BasicEList.java:6 38)
at
org.eclipse.emf.edit.command.RemoveCommand.doUndo(RemoveComm and.java:461)
at
org.eclipse.emf.edit.command.AbstractOverrideableCommand.und o(AbstractOverrideableCommand.java:157)
at
org.eclipse.emf.common.command.CommandWrapper.undo(CommandWr apper.java:198)
at
org.eclipse.emf.common.command.CompoundCommand.undo(Compound Command.java:333)
at
org.eclipse.emf.common.command.BasicCommandStack.undo(BasicC ommandStack.java:141)
... 28 more



"Mike Gering" <a class="moz-txt-link-rfc2396E" href="mailto:mike@aol.com">&lt;mike@aol.com&gt;</a> wrote in message
<a class="moz-txt-link-freetext" href="news:fq6s7o$gbj$1@build.eclipse.org">news:fq6s7o$gbj$1@build.eclipse.org</a>...
</pre>
<blockquote type="cite">
<pre wrap="">Ed Merks wrote:
</pre>
<blockquote type="cite">
<pre wrap="">Aren't the displayed objects under the non-containment feature wrappers?
Isn't that the case?
</pre>
</blockquote>
<pre wrap="">Nope. The ItemProviderAdapter.isWrapperNeeded() method looks only for
attributes and ignores references:
for (Iterator i = getAnyChildrenFeatures(object).iterator();
i.hasNext(); )
{
EStructuralFeature f = (EStructuralFeature)i.next();
if (f instanceof EAttribute)
{
wrappingNeeded = Boolean.TRUE;
}
}


</pre>
<blockquote type="cite">
<pre wrap="">Perhaps you need to force wrappers to be created (override
isWrappingNeeded) so you'll know when you are operating on the referenced
child as opposed to the real one actually contained.
</pre>
</blockquote>
<pre wrap="">I did that and lo! the chilren references get wrapped, and to my glee, the
delete command works as I want, without having to subclass change
AdapterFactoryEditingDomain. Deleting the reference child deletes the
reference only. Deleting the contained object deletes it and its
references, as before.

Mike
</pre>
</blockquote>
<pre wrap=""><!---->

</pre>
</blockquote>
<br>
</body>
</html>

--------------010902020200040201050308--


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Deleting child reference deletes referent? [message #417328 is a reply to message #417289] Wed, 05 March 2008 15:48 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: udaykabe.hotmail.com

This is a multi-part message in MIME format.

------=_NextPart_000_008D_01C87EA6.22EE69A0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Ed,

Thanks. Very perceptive.

The wrappers are indeed being created. These wrappers are =
DelegatingWrapperItemProvider's which delegate to the wrapped value's =
IStructuredItemContentProvider.

My problem: My override of AdapterFactoryContentProvider's getChildren() =
was inadvertently delivering the "value" instead of the "wrapper" to the =
Delete command. Each wrapper I create is now an anon =
DelegatingWrapperItemProvider which handles some of these overrides.

The behavior of the Delete command is a bit awkward as it currently =
sits. When I select a reference, it deletes all such references which =
is not what I want but does not delete the referent which is what I =
want. If I select the referent, it deletes the referent and all =
references which is also what I want. I know that the Delete action is =
constructed with the DeleteAction(removeAllReferencesOnDelete() =3D =
true) constructor. Hence, the DeleteCommand() is used instead of the =
RemoveCommand. It appears that removeAllReferencesOnDelete() is not =
fine-grained enough to suit my needs. So,

1. Is there some easy mechanism available to delete only the selected =
reference (I think this entails using the RemoveCommand) and retain all =
other behavior of Delete? Ideally, the user would select the delete =
menu item, and I would provide a dialog box with a choice of which =
behavior they wish to choose: delete a single reference, delete all =
references, or delete all references and referent.
2. Is there some handy mechanism to manipulate wrappers, eg, unwrap =
them?
3. There appears no "easy" way to choose between the RemoveCommand and =
the DeleteCommand in ItemProviderAdapter. What is the whole picture =
here?
4. In my app, the user can create references by using DND. When the =
DND is in progress, I see a shorcut overlay on the icon. How and where =
is this done?
5. In addition to DND, I would like to provide a copy-and-paste =
approach to creating references which would have the same effect. Could =
you give me a quick summary of what I would have to do to achieve this?

Sorry for the lengthy post. I would normally pursue this on my own =
("please teach me to fish"), but right now I am so pressed for time that =
any hand-holding ("please give me a fish") would really be appreciated.

Thanks Ed.

Uday
"Ed Merks" <merks@ca.ibm.com> wrote in message =
news:fqk1kt$f3g$1@build.eclipse.org...
Uday,

So you've verified that wrappers are being created for the children =
displayed by B? And that when you are invoking delete on that child, =
it's being invoked for that wrapper?

It looks like you tried to invoke undo, but you didn't mention that...


Uday Kabe wrote:=20
Ed,

I am trying to do the same with the following EMF model:

I have 3 EClasses A, B and C. A has a multiplicity-many containment
reference to C, while B has a similar, non-containment reference to C. =
Both=20
A and B
display these references as children in my view. I can DND an instance =
of C
from A into B. Undo and Redo operations for the DND seem to work fine. =
If=20
I delete
an instance of C, both the contained and non-contained objects are =
deleted.=20
Undo
Delete throws an exception which I have not yet chased down.

I have overridden isWrappingNeeded() to return true in the item provider =
for=20
class B but doing only
this does not seem to work. Is there something else or something =
different=20
I need to do?

Thanks.

Uday

Here is the exception trace:

org.eclipse.emf.common.util.WrappedException: An exception was ignored=20
during command execution
at=20
org.eclipse.emf.common.command.BasicCommandStack.handleError (BasicCommand=
Stack.java:279)
at=20
org.eclipse.emf.common.command.BasicCommandStack.undo(BasicC ommandStack.j=
ava:146)
at org.eclipse.emf.edit.ui.action.UndoAction.run(UndoAction.jav a:67)
at org.eclipse.jface.action.Action.runWithEvent(Action.java:499 )
at=20
org.eclipse.ui.actions.RetargetAction.runWithEvent(RetargetA ction.java:22=
9)
at=20
org.eclipse.jface.action.ActionContributionItem.handleWidget Selection(Act=
ionContributionItem.java:539)
at=20
org.eclipse.jface.action.ActionContributionItem.access$2(Act ionContributi=
onItem.java:488)
at=20
org.eclipse.jface.action.ActionContributionItem$5.handleEven t(ActionContr=
ibutionItem.java:400)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java :66)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:928)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.ja va:3348)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java :2968)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.jav a:1914)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:1878)
at=20
org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Work bench.java:41=
9)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.j ava:149)
at=20
ws.kabe.news.presentation.NewsEditorAdvisor$Application.run( NewsEditorAdv=
isor.java:110)
at=20
org.eclipse.core.internal.runtime.PlatformActivator$1.run(Pl atformActivat=
or.java:78)
at=20
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .runApplicati=
on(EclipseAppLauncher.java:92)
at=20
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .start(Eclips=
eAppLauncher.java:68)
at=20
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:4=
00)
at=20
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:1=
77)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at=20
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java=
:39)
at=20
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorI=
mpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.eclipse.core.launcher.Main.invokeFramework(Main.java:336 )
at org.eclipse.core.launcher.Main.basicRun(Main.java:280)
at org.eclipse.core.launcher.Main.run(Main.java:977)
at org.eclipse.core.launcher.Main.main(Main.java:952)
Caused by:=20
org.eclipse.emf.common.util.BasicEList$BasicIndexOutOfBounds Exception:=20
index=3D3, size=3D0
at org.eclipse.emf.common.util.BasicEList.add(BasicEList.java:6 38)
at=20
org.eclipse.emf.edit.command.RemoveCommand.doUndo(RemoveComm and.java:461)=

at=20
org.eclipse.emf.edit.command.AbstractOverrideableCommand.und o(AbstractOve=
rrideableCommand.java:157)
at=20
org.eclipse.emf.common.command.CommandWrapper.undo(CommandWr apper.java:19=
8)
at=20
org.eclipse.emf.common.command.CompoundCommand.undo(Compound Command.java:=
333)
at=20
org.eclipse.emf.common.command.BasicCommandStack.undo(BasicC ommandStack.j=
ava:141)
... 28 more



"Mike Gering" <mike@aol.com> wrote in message=20
news:fq6s7o$gbj$1@build.eclipse.org...
Ed Merks wrote:
Aren't the displayed objects under the non-containment feature =
wrappers?=20
Isn't that the case?
Nope. The ItemProviderAdapter.isWrapperNeeded() method looks only =
for=20
attributes and ignores references:
for (Iterator i =3D getAnyChildrenFeatures(object).iterator();=20
i.hasNext(); )
{
EStructuralFeature f =3D (EStructuralFeature)i.next();
if (f instanceof EAttribute)
{
wrappingNeeded =3D Boolean.TRUE;
}
}


Perhaps you need to force wrappers to be created (override=20
isWrappingNeeded) so you'll know when you are operating on the =
referenced=20
child as opposed to the real one actually contained.
I did that and lo! the chilren references get wrapped, and to my =
glee, the=20
delete command works as I want, without having to subclass change=20
AdapterFactoryEditingDomain. Deleting the reference child deletes the=20
reference only. Deleting the contained object deletes it and its=20
references, as before.

Mike=20
=20

=20

------=_NextPart_000_008D_01C87EA6.22EE69A0
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type =
content=3Dtext/html;charset=3DISO-8859-1>
<META content=3D"MSHTML 6.00.6000.16608" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY text=3D#000000 bgColor=3D#ffffff>
<DIV>
<DIV><FONT face=3DArial size=3D2>Ed,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Thanks. Very perceptive.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>The&nbsp;wrappers are indeed being =
created.&nbsp;=20
T</FONT><FONT face=3DArial size=3D2>hese wrappers are=20
DelegatingWrapperItemProvider's which delegate to the wrapped value's=20
IStructuredItemContentProvider.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>My problem:&nbsp;My override=20
of&nbsp;AdapterFactoryContentProvider's getChildren()&nbsp;was =
inadvertently=20
delivering the "value" instead of the </FONT><FONT face=3DArial =
size=3D2>"wrapper"=20
to the Delete command.&nbsp; Each wrapper I create is now an anon=20
DelegatingWrapperItemProvider which handles some of these=20
overrides.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>The behavior of the Delete command is a =
bit awkward=20
as it currently sits.&nbsp; When I select a reference, it deletes all =
such=20
references which is not what I want but&nbsp;does not delete=20
the&nbsp;referent&nbsp;which is what I want.&nbsp; If I select the =
referent, it=20
deletes&nbsp;the referent&nbsp;and all references&nbsp;which is also =
what I=20
want.&nbsp; I know that the Delete action is constructed with =
</FONT><FONT=20
face=3DArial size=3D2>the DeleteAction(removeAllReferencesOnDelete() =3D =
true)=20
constructor.&nbsp; Hence, the DeleteCommand() is used instead of the=20
RemoveCommand.&nbsp;&nbsp;It appears =
that&nbsp;removeAllReferencesOnDelete() is=20
not fine-grained enough to suit my needs.&nbsp; So,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>1. Is there some easy mechanism =
available to delete=20
only the selected reference (I think this entails using the=20
RemoveCommand)&nbsp;and retain all other behavior of Delete?&nbsp; =
Ideally, the=20
user would select the delete menu item, and I would provide a dialog box =
with a=20
choice of which behavior they wish to choose: delete a single reference, =
delete=20
all references, or delete all references and referent.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>2. Is there some handy mechanism =
to&nbsp;manipulate=20
wrappers, eg, unwrap them?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>3.&nbsp;There appears no "easy" way to =
choose=20
between the RemoveCommand and the DeleteCommand in =
ItemProviderAdapter.&nbsp;=20
What is the whole picture here?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>4.&nbsp; In my app, the user can create =
references=20
by using DND.&nbsp; When the DND is in progress, I see a shorcut overlay =
on the=20
icon.&nbsp; How and where is this done?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>5.&nbsp; In addition to DND, I would =
like to=20
provide a copy-and-paste approach to creating references which would =
have the=20
same effect.&nbsp; Could you give me a quick summary of what I would =
have to do=20
to achieve this?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Sorry for the lengthy post.&nbsp; I =
would normally=20
pursue this on my own ("please teach me to fish"), but right now I am so =
pressed=20
for time that any&nbsp;hand-holding ("please give me a fish") would =
really be=20
appreciated.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Thanks Ed.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Uday</FONT></DIV></DIV>
<BLOCKQUOTE=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<DIV>"Ed Merks" &lt;<A =
href=3D"mailto:merks@ca.ibm.com">merks@ca.ibm.com</A>&gt;=20
wrote in message <A=20
=
href=3D"news:fqk1kt$f3g$1@build.eclipse.org">news:fqk1kt$f3g$1@build.ecli=
pse.org</A>...</DIV>Uday,<BR><BR>So=20
you've verified that wrappers are being created for the children =
displayed by=20
B?&nbsp; And that when you are invoking delete on that child, it's =
being=20
invoked for that wrapper?<BR><BR>It looks like you tried to invoke =
undo, but=20
you didn't mention that...<BR><BR><BR>Uday Kabe wrote:=20
<BLOCKQUOTE cite=3Dmid:fqk07a$7v1$1@build.eclipse.org =
type=3D"cite"><PRE wrap=3D"">Ed,

I am trying to do the same with the following EMF model:

I have 3 EClasses A, B and C. A has a multiplicity-many containment
reference to C, while B has a similar, non-containment reference to C. =
Both=20
A and B
display these references as children in my view. I can DND an instance =
of C
from A into B. Undo and Redo operations for the DND seem to work fine. =
If=20
I delete
an instance of C, both the contained and non-contained objects are =
deleted.=20
Undo
Delete throws an exception which I have not yet chased down.

I have overridden isWrappingNeeded() to return true in the item provider =
for=20
class B but doing only
this does not seem to work. Is there something else or something =
different=20
I need to do?

Thanks.

Uday

Here is the exception trace:

org.eclipse.emf.common.util.WrappedException: An exception was ignored=20
during command execution
at=20
org.eclipse.emf.common.command.BasicCommandStack.handleError (BasicCommand=
Stack.java:279)
at=20
org.eclipse.emf.common.command.BasicCommandStack.undo(BasicC ommandStack.j=
ava:146)
at org.eclipse.emf.edit.ui.action.UndoAction.run(UndoAction.jav a:67)
at org.eclipse.jface.action.Action.runWithEvent(Action.java:499 )
at=20
org.eclipse.ui.actions.RetargetAction.runWithEvent(RetargetA ction.java:22=
9)
at=20
org.eclipse.jface.action.ActionContributionItem.handleWidget Selection(Act=
ionContributionItem.java:539)
at=20
org.eclipse.jface.action.ActionContributionItem.access$2(Act ionContributi=
onItem.java:488)
at=20
org.eclipse.jface.action.ActionContributionItem$5.handleEven t(ActionContr=
ibutionItem.java:400)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java :66)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:928)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.ja va:3348)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java :2968)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.jav a:1914)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:1878)
at=20
org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Work bench.java:41=
9)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.j ava:149)
at=20
ws.kabe.news.presentation.NewsEditorAdvisor$Application.run( NewsEditorAdv=
isor.java:110)
at=20
org.eclipse.core.internal.runtime.PlatformActivator$1.run(Pl atformActivat=
or.java:78)
at=20
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .runApplicati=
on(EclipseAppLauncher.java:92)
at=20
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .start(Eclips=
eAppLauncher.java:68)
at=20
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:4=
00)
at=20
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:1=
77)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at=20
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java=
:39)
at=20
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorI=
mpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.eclipse.core.launcher.Main.invokeFramework(Main.java:336 )
at org.eclipse.core.launcher.Main.basicRun(Main.java:280)
at org.eclipse.core.launcher.Main.run(Main.java:977)
at org.eclipse.core.launcher.Main.main(Main.java:952)
Caused by:=20
org.eclipse.emf.common.util.BasicEList$BasicIndexOutOfBounds Exception:=20
index=3D3, size=3D0
at org.eclipse.emf.common.util.BasicEList.add(BasicEList.java:6 38)
at=20
org.eclipse.emf.edit.command.RemoveCommand.doUndo(RemoveComm and.java:461)=

at=20
org.eclipse.emf.edit.command.AbstractOverrideableCommand.und o(AbstractOve=
rrideableCommand.java:157)
at=20
org.eclipse.emf.common.command.CommandWrapper.undo(CommandWr apper.java:19=
8)
at=20
org.eclipse.emf.common.command.CompoundCommand.undo(Compound Command.java:=
333)
at=20
org.eclipse.emf.common.command.BasicCommandStack.undo(BasicC ommandStack.j=
ava:141)
... 28 more



"Mike Gering" <A class=3Dmoz-txt-link-rfc2396E =
href=3D"mailto:mike@aol.com">&lt;mike@aol.com&gt;</A> wrote in message=20
<A class=3Dmoz-txt-link-freetext =
href=3D"news:fq6s7o$gbj$1@build.eclipse.org">news:fq6s7o$gbj$1@build.ecli=
pse.org</A>...
</PRE>
<BLOCKQUOTE type=3D"cite"><PRE wrap=3D"">Ed Merks wrote:
</PRE>
<BLOCKQUOTE type=3D"cite"><PRE wrap=3D"">Aren't the displayed =
objects under the non-containment feature wrappers?=20
Isn't that the case?
</PRE></BLOCKQUOTE><PRE wrap=3D"">Nope. The =
ItemProviderAdapter.isWrapperNeeded() method looks only for=20
attributes and ignores references:
for (Iterator i =3D getAnyChildrenFeatures(object).iterator();=20
i.hasNext(); )
{
EStructuralFeature f =3D (EStructuralFeature)i.next();
if (f instanceof EAttribute)
{
wrappingNeeded =3D Boolean.TRUE;
}
}


</PRE>
<BLOCKQUOTE type=3D"cite"><PRE wrap=3D"">Perhaps you need to force =
wrappers to be created (override=20
isWrappingNeeded) so you'll know when you are operating on the =
referenced=20
child as opposed to the real one actually contained.
</PRE></BLOCKQUOTE><PRE wrap=3D"">I did that and lo! the chilren =
references get wrapped, and to my glee, the=20
delete command works as I want, without having to subclass change=20
AdapterFactoryEditingDomain. Deleting the reference child deletes the=20
reference only. Deleting the contained object deletes it and its=20
references, as before.

Mike=20
</PRE></BLOCKQUOTE><PRE wrap=3D""><!---->

</PRE></BLOCKQUOTE><BR></BLOCKQUOTE></BODY></HTML>

------=_NextPart_000_008D_01C87EA6.22EE69A0--
Re: Deleting child reference deletes referent? [message #417334 is a reply to message #417328] Wed, 05 March 2008 16: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.
--------------060904080507080700070706
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Uday,

Comments below.

Uday Kabe wrote:
> Ed,
>
> Thanks. Very perceptive.
>
> The wrappers are indeed being created. These wrappers are
> DelegatingWrapperItemProvider's which delegate to the wrapped value's
> IStructuredItemContentProvider.
>
> My problem: My override of AdapterFactoryContentProvider's
> getChildren() was inadvertently delivering the "value" instead of the
> "wrapper" to the Delete command. Each wrapper I create is now an anon
> DelegatingWrapperItemProvider which handles some of these overrides.
>
> The behavior of the Delete command is a bit awkward as it currently
> sits. When I select a reference, it deletes all such references which
> is not what I want but does not delete the referent which is what I want.
EObjects themselves can't be deleted. They're only deleted by virtue
of eliminating all references to them so they can be garbage collected.
> If I select the referent, it deletes the referent and all
> references which is also what I want. I know that the Delete action
> is constructed with the DeleteAction(removeAllReferencesOnDelete() =
> true) constructor. Hence, the DeleteCommand() is used instead of the
> RemoveCommand. It appears that removeAllReferencesOnDelete() is not
> fine-grained enough to suit my needs.
I'm a bit confused. You are always selecting an object and always
deleting that object...
> So,
>
> 1. Is there some easy mechanism available to delete only the selected
> reference (I think this entails using the RemoveCommand) and retain
> all other behavior of Delete? Ideally, the user would select the
> delete menu item, and I would provide a dialog box with a choice of
> which behavior they wish to choose: delete a single reference, delete
> all references, or delete all references and referent.
I understand delete single reference to mean remove the object from the
one object that's referencing it. I would expect delete on the wrapper
to do that. I would expect that delete all references would be what
delete normally does when applied to the actual EObject. The third
choice escapes me...
> 2. Is there some handy mechanism to manipulate wrappers, eg, unwrap them?
Yes. Wrappers implement IWrapperItemProvider and methods like
AdapterFactoryEditingDomain.unwrap is useful tool.
> 3. There appears no "easy" way to choose between the RemoveCommand and
> the DeleteCommand in ItemProviderAdapter. What is the whole picture here?
What you see is all there is. :-P
> 4. In my app, the user can create references by using DND. When the
> DND is in progress, I see a shorcut overlay on the icon. How and
> where is this done?
DragAndDropCommand does a lot of fancy and complex things to make all
this work.
> 5. In addition to DND, I would like to provide a copy-and-paste
> approach to creating references which would have the same effect.
> Could you give me a quick summary of what I would have to do to
> achieve this?
What happens now? I imagine it's a bit tricky since copy kind of
implies created a new object...
>
> Sorry for the lengthy post. I would normally pursue this on my own
> ("please teach me to fish"), but right now I am so pressed for time
> that any hand-holding ("please give me a fish") would really be
> appreciated.
I'm setting up a really big fish tank at home in the next few weeks. 180
gallons. I guess that's not related to your fish question though. :-P

The best you can really do is specialize the domain's createCommand or
the individual item provider create*Command methods...
>
> Thanks Ed.
>
> Uday
>
> "Ed Merks" <merks@ca.ibm.com <mailto:merks@ca.ibm.com>> wrote in
> message news:fqk1kt$f3g$1@build.eclipse.org...
> Uday,
>
> So you've verified that wrappers are being created for the
> children displayed by B? And that when you are invoking delete on
> that child, it's being invoked for that wrapper?
>
> It looks like you tried to invoke undo, but you didn't mention that...
>
>
> Uday Kabe wrote:
>> Ed,
>>
>> I am trying to do the same with the following EMF model:
>>
>> I have 3 EClasses A, B and C. A has a multiplicity-many containment
>> reference to C, while B has a similar, non-containment reference to C. Both
>> A and B
>> display these references as children in my view. I can DND an instance of C
>> from A into B. Undo and Redo operations for the DND seem to work fine. If
>> I delete
>> an instance of C, both the contained and non-contained objects are deleted.
>> Undo
>> Delete throws an exception which I have not yet chased down.
>>
>> I have overridden isWrappingNeeded() to return true in the item provider for
>> class B but doing only
>> this does not seem to work. Is there something else or something different
>> I need to do?
>>
>> Thanks.
>>
>> Uday
>>
>> Here is the exception trace:
>>
>> org.eclipse.emf.common.util.WrappedException: An exception was ignored
>> during command execution
>> at
>> org.eclipse.emf.common.command.BasicCommandStack.handleError (BasicCommandStack.java:279)
>> at
>> org.eclipse.emf.common.command.BasicCommandStack.undo(BasicC ommandStack.java:146)
>> at org.eclipse.emf.edit.ui.action.UndoAction.run(UndoAction.jav a:67)
>> at org.eclipse.jface.action.Action.runWithEvent(Action.java:499 )
>> at
>> org.eclipse.ui.actions.RetargetAction.runWithEvent(RetargetA ction.java:229)
>> at
>> org.eclipse.jface.action.ActionContributionItem.handleWidget Selection(ActionContributionItem.java:539)
>> at
>> org.eclipse.jface.action.ActionContributionItem.access$2(Act ionContributionItem.java:488)
>> at
>> org.eclipse.jface.action.ActionContributionItem$5.handleEven t(ActionContributionItem.java:400)
>> at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java :66)
>> at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:928)
>> at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.ja va:3348)
>> at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java :2968)
>> at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.jav a:1914)
>> at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:1878)
>> at
>> org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Work bench.java:419)
>> at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.j ava:149)
>> at
>> ws.kabe.news.presentation.NewsEditorAdvisor$Application.run( NewsEditorAdvisor.java:110)
>> at
>> org.eclipse.core.internal.runtime.PlatformActivator$1.run(Pl atformActivator.java:78)
>> at
>> org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .runApplication(EclipseAppLauncher.java:92)
>> at
>> org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .start(EclipseAppLauncher.java:68)
>> at
>> org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:400)
>> at
>> org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:177)
>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>> at
>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:39)
>> at
>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:25)
>> at java.lang.reflect.Method.invoke(Method.java:585)
>> at org.eclipse.core.launcher.Main.invokeFramework(Main.java:336 )
>> at org.eclipse.core.launcher.Main.basicRun(Main.java:280)
>> at org.eclipse.core.launcher.Main.run(Main.java:977)
>> at org.eclipse.core.launcher.Main.main(Main.java:952)
>> Caused by:
>> org.eclipse.emf.common.util.BasicEList$BasicIndexOutOfBounds Exception:
>> index=3, size=0
>> at org.eclipse.emf.common.util.BasicEList.add(BasicEList.java:6 38)
>> at
>> org.eclipse.emf.edit.command.RemoveCommand.doUndo(RemoveComm and.java:461)
>> at
>> org.eclipse.emf.edit.command.AbstractOverrideableCommand.und o(AbstractOverrideableCommand.java:157)
>> at
>> org.eclipse.emf.common.command.CommandWrapper.undo(CommandWr apper.java:198)
>> at
>> org.eclipse.emf.common.command.CompoundCommand.undo(Compound Command.java:333)
>> at
>> org.eclipse.emf.common.command.BasicCommandStack.undo(BasicC ommandStack.java:141)
>> ... 28 more
>>
>>
>>
>> "Mike Gering" <mike@aol.com> wrote in message
>> news:fq6s7o$gbj$1@build.eclipse.org...
>>
>>> Ed Merks wrote:
>>>
>>>> Aren't the displayed objects under the non-containment feature wrappers?
>>>> Isn't that the case?
>>>>
>>> Nope. The ItemProviderAdapter.isWrapperNeeded() method looks only for
>>> attributes and ignores references:
>>> for (Iterator i = getAnyChildrenFeatures(object).iterator();
>>> i.hasNext(); )
>>> {
>>> EStructuralFeature f = (EStructuralFeature)i.next();
>>> if (f instanceof EAttribute)
>>> {
>>> wrappingNeeded = Boolean.TRUE;
>>> }
>>> }
>>>
>>>
>>>
>>>> Perhaps you need to force wrappers to be created (override
>>>> isWrappingNeeded) so you'll know when you are operating on the referenced
>>>> child as opposed to the real one actually contained.
>>>>
>>> I did that and lo! the chilren references get wrapped, and to my glee, the
>>> delete command works as I want, without having to subclass change
>>> AdapterFactoryEditingDomain. Deleting the reference child deletes the
>>> reference only. Deleting the contained object deletes it and its
>>> references, as before.
>>>
>>> Mike
>>>
>>
>>
>>
>


--------------060904080507080700070706
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Uday,<br>
<br>
Comments below.<br>
<br>
Uday Kabe wrote:
<blockquote cite="mid:fqmfdo$df3$1@build.eclipse.org" type="cite">
<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1">
<meta content="MSHTML 6.00.6000.16608" name="GENERATOR">
<style></style>
<div>
<div><font face="Arial" size="2">Ed,</font></div>
<div>&nbsp;</div>
<div><font face="Arial" size="2">Thanks. Very perceptive.</font></div>
<div>&nbsp;</div>
<div><font face="Arial" size="2">The&nbsp;wrappers are indeed being
created.&nbsp; T</font><font face="Arial" size="2">hese wrappers are
DelegatingWrapperItemProvider's which delegate to the wrapped value's
IStructuredItemContentProvider.</font></div>
<div>&nbsp;</div>
<div><font face="Arial" size="2">My problem:&nbsp;My override
of&nbsp;AdapterFactoryContentProvider's getChildren()&nbsp;was inadvertently
delivering the "value" instead of the </font><font face="Arial"
size="2">"wrapper" to the Delete command.&nbsp; Each wrapper I create is
now an anon DelegatingWrapperItemProvider which handles some of these
overrides.</font></div>
<div>&nbsp;</div>
<div><font face="Arial" size="2">The behavior of the Delete command
is a bit awkward as it currently sits.&nbsp; When I select a reference, it
deletes all such references which is not what I want but&nbsp;does not
delete the&nbsp;referent&nbsp;which is what I want. <br>
</font></div>
</div>
</blockquote>
EObjects themselves can't be deleted.&nbsp; They're only deleted&nbsp; by virtue
of eliminating all references to them so they can be garbage collected.<br>
<blockquote cite="mid:fqmfdo$df3$1@build.eclipse.org" type="cite">
<div>
<div><font face="Arial" size="2"> If I select the referent, it
deletes&nbsp;the referent&nbsp;and all references&nbsp;which is also what I want.&nbsp; I
know that the Delete action is constructed with </font><font
face="Arial" size="2">the DeleteAction(removeAllReferencesOnDelete() =
true) constructor.&nbsp; Hence, the DeleteCommand() is used instead of the
RemoveCommand.&nbsp;&nbsp;It appears that&nbsp;removeAllReferencesOnDelete() is not
fine-grained enough to suit my needs.&nbsp; </font></div>
</div>
</blockquote>
I'm a bit confused.&nbsp; You are always selecting an object and always
deleting that object...<br>
<blockquote cite="mid:fqmfdo$df3$1@build.eclipse.org" type="cite">
<div>
<div><font face="Arial" size="2">So,</font></div>
<div>&nbsp;</div>
<div><font face="Arial" size="2">1. Is there some easy mechanism
available to delete only the selected reference (I think this entails
using the RemoveCommand)&nbsp;and retain all other behavior of Delete?&nbsp;
Ideally, the user would select the delete menu item, and I would
provide a dialog box with a choice of which behavior they wish to
choose: delete a single reference, delete all references, or delete all
references and referent.</font></div>
</div>
</blockquote>
I understand delete single reference to mean remove the object from the
one object that's referencing it.&nbsp; I would expect delete on the wrapper
to do that.&nbsp; I would expect that delete all references would be what
delete normally does when applied to the actual EObject.&nbsp; The third
choice escapes me...<br>
<blockquote cite="mid:fqmfdo$df3$1@build.eclipse.org" type="cite">
<div>
<div><font face="Arial" size="2">2. Is there some handy mechanism
to&nbsp;manipulate wrappers, eg, unwrap them?</font></div>
</div>
</blockquote>
Yes. Wrappers implement IWrapperItemProvider and methods like
AdapterFactoryEditingDomain.unwrap is useful tool.<br>
<blockquote cite="mid:fqmfdo$df3$1@build.eclipse.org" type="cite">
<div>
<div><font face="Arial" size="2">3.&nbsp;There appears no "easy" way to
choose between the RemoveCommand and the DeleteCommand in
ItemProviderAdapter.&nbsp; What is the whole picture here?</font></div>
</div>
</blockquote>
What you see is all there is.&nbsp; :-P<br>
<blockquote cite="mid:fqmfdo$df3$1@build.eclipse.org" type="cite">
<div>
<div><font face="Arial" size="2">4.&nbsp; In my app, the user can create
references by using DND.&nbsp; When the DND is in progress, I see a shorcut
overlay on the icon.&nbsp; How and where is this done?</font></div>
</div>
</blockquote>
DragAndDropCommand does a lot of fancy and complex things to make all
this work.<br>
<blockquote cite="mid:fqmfdo$df3$1@build.eclipse.org" type="cite">
<div>
<div><font face="Arial" size="2">5.&nbsp; In addition to DND, I would like
to provide a copy-and-paste approach to creating references which would
have the same effect.&nbsp; Could you give me a quick summary of what I
would have to do to achieve this?</font></div>
</div>
</blockquote>
What happens now?&nbsp; I imagine it's a bit tricky since copy kind of
implies created a new object...<br>
<blockquote cite="mid:fqmfdo$df3$1@build.eclipse.org" type="cite">
<div>
<div>&nbsp;</div>
<div><font face="Arial" size="2">Sorry for the lengthy post.&nbsp; I would
normally pursue this on my own ("please teach me to fish"), but right
now I am so pressed for time that any&nbsp;hand-holding ("please give me a
fish") would really be appreciated.</font></div>
</div>
</blockquote>
I'm setting up a really big fish tank at home in the next few weeks.
180 gallons.&nbsp; I guess that's not related to your fish question though.&nbsp;
:-P<br>
<br>
The best you can really do is specialize the domain's createCommand or
the individual item provider create*Command methods...<br>
<blockquote cite="mid:fqmfdo$df3$1@build.eclipse.org" type="cite">
<div>
<div>&nbsp;</div>
<div><font face="Arial" size="2">Thanks Ed.</font></div>
<div>&nbsp;</div>
<div><font face="Arial" size="2">Uday</font></div>
</div>
<blockquote
style="border-left: 2px solid rgb(0, 0, 0); padding-right: 0px; padding-left: 5px; margin-left: 5px; margin-right: 0px;">
<div>"Ed Merks" &lt;<a moz-do-not-send="true"
href="mailto:merks@ca.ibm.com">merks@ca.ibm.com</a>&gt; wrote in
message <a moz-do-not-send="true"
href="news:fqk1kt$f3g$1@build.eclipse.org">news:fqk1kt$f3g$1@build.eclipse.org</a>...</div>
Uday,<br>
<br>
So you've verified that wrappers are being created for the children
displayed by B?&nbsp; And that when you are invoking delete on that child,
it's being invoked for that wrapper?<br>
<br>
It looks like you tried to invoke undo, but you didn't mention that...<br>
<br>
<br>
Uday Kabe wrote:
<blockquote cite="mid:fqk07a$7v1$1@build.eclipse.org" type="cite">
<pre wrap="">Ed,

I am trying to do the same with the following EMF model:

I have 3 EClasses A, B and C. A has a multiplicity-many containment
reference to C, while B has a similar, non-containment reference to C. Both
A and B
display these references as children in my view. I can DND an instance of C
from A into B. Undo and Redo operations for the DND seem to work fine. If
I delete
an instance of C, both the contained and non-contained objects are deleted.
Undo
Delete throws an exception which I have not yet chased down.

I have overridden isWrappingNeeded() to return true in the item provider for
class B but doing only
this does not seem to work. Is there something else or something different
I need to do?

Thanks.

Uday

Here is the exception trace:

org.eclipse.emf.common.util.WrappedException: An exception was ignored
during command execution
at
org.eclipse.emf.common.command.BasicCommandStack.handleError (BasicCommandStack.java:279)
at
org.eclipse.emf.common.command.BasicCommandStack.undo(BasicC ommandStack.java:146)
at org.eclipse.emf.edit.ui.action.UndoAction.run(UndoAction.jav a:67)
at org.eclipse.jface.action.Action.runWithEvent(Action.java:499 )
at
org.eclipse.ui.actions.RetargetAction.runWithEvent(RetargetA ction.java:229)
at
org.eclipse.jface.action.ActionContributionItem.handleWidget Selection(ActionContributionItem.java:539)
at
org.eclipse.jface.action.ActionContributionItem.access$2(Act ionContributionItem.java:488)
at
org.eclipse.jface.action.ActionContributionItem$5.handleEven t(ActionContributionItem.java:400)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java :66)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:928)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.ja va:3348)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java :2968)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.jav a:1914)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:1878)
at
org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Work bench.java:419)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.j ava:149)
at
ws.kabe.news.presentation.NewsEditorAdvisor$Application.run( NewsEditorAdvisor.java:110)
at
org.eclipse.core.internal.runtime.PlatformActivator$1.run(Pl atformActivator.java:78)
at
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .runApplication(EclipseAppLauncher.java:92)
at
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .start(EclipseAppLauncher.java:68)
at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:400)
at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:177)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.eclipse.core.launcher.Main.invokeFramework(Main.java:336 )
at org.eclipse.core.launcher.Main.basicRun(Main.java:280)
at org.eclipse.core.launcher.Main.run(Main.java:977)
at org.eclipse.core.launcher.Main.main(Main.java:952)
Caused by:
org.eclipse.emf.common.util.BasicEList$BasicIndexOutOfBounds Exception:
index=3, size=0
at org.eclipse.emf.common.util.BasicEList.add(BasicEList.java:6 38)
at
org.eclipse.emf.edit.command.RemoveCommand.doUndo(RemoveComm and.java:461)
at
org.eclipse.emf.edit.command.AbstractOverrideableCommand.und o(AbstractOverrideableCommand.java:157)
at
org.eclipse.emf.common.command.CommandWrapper.undo(CommandWr apper.java:198)
at
org.eclipse.emf.common.command.CompoundCommand.undo(Compound Command.java:333)
at
org.eclipse.emf.common.command.BasicCommandStack.undo(BasicC ommandStack.java:141)
... 28 more



"Mike Gering" <a moz-do-not-send="true" class="moz-txt-link-rfc2396E"
href="mailto:mike@aol.com">&lt;mike@aol.com&gt;</a> wrote in message
<a moz-do-not-send="true" class="moz-txt-link-freetext"
href="news:fq6s7o$gbj$1@build.eclipse.org">news:fq6s7o$gbj$1@build.eclipse.org</a>...
</pre>
<blockquote type="cite">
<pre wrap="">Ed Merks wrote:
</pre>
<blockquote type="cite">
<pre wrap="">Aren't the displayed objects under the non-containment feature wrappers?
Isn't that the case?
</pre>
</blockquote>
<pre wrap="">Nope. The ItemProviderAdapter.isWrapperNeeded() method looks only for
attributes and ignores references:
for (Iterator i = getAnyChildrenFeatures(object).iterator();
i.hasNext(); )
{
EStructuralFeature f = (EStructuralFeature)i.next();
if (f instanceof EAttribute)
{
wrappingNeeded = Boolean.TRUE;
}
}


</pre>
<blockquote type="cite">
<pre wrap="">Perhaps you need to force wrappers to be created (override
isWrappingNeeded) so you'll know when you are operating on the referenced
child as opposed to the real one actually contained.
</pre>
</blockquote>
<pre wrap="">I did that and lo! the chilren references get wrapped, and to my glee, the
delete command works as I want, without having to subclass change
AdapterFactoryEditingDomain. Deleting the reference child deletes the
reference only. Deleting the contained object deletes it and its
references, as before.

Mike
</pre>
</blockquote>
<pre wrap=""><!---->

</pre>
</blockquote>
<br>
</blockquote>
</blockquote>
<br>
</body>
</html>

--------------060904080507080700070706--


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Deleting child reference deletes referent? [message #417350 is a reply to message #417334] Wed, 05 March 2008 23:07 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: udaykabe.hotmail.com

Ed,

Thanks. Comments below.

Ed Merks wrote:
> Uday,
>
> Comments below.
>
> Uday Kabe wrote:
>> Ed,
>>
>> Thanks. Very perceptive.
>>
>> The wrappers are indeed being created. These wrappers are
>> DelegatingWrapperItemProvider's which delegate to the wrapped value's
>> IStructuredItemContentProvider.
>>
>> My problem: My override of AdapterFactoryContentProvider's
>> getChildren() was inadvertently delivering the "value" instead of the
>> "wrapper" to the Delete command. Each wrapper I create is now an anon
>> DelegatingWrapperItemProvider which handles some of these overrides.
>>
>> The behavior of the Delete command is a bit awkward as it currently
>> sits. When I select a reference, it deletes all such references which
>> is not what I want but does not delete the referent which is what I want.

> EObjects themselves can't be deleted. They're only deleted by virtue
> of eliminating all references to them so they can be garbage collected.
I understand. Hopefully, I will be a little clearer in the rest of my
reply.

>> If I select the referent, it deletes the referent and all
>> references which is also what I want. I know that the Delete action
>> is constructed with the DeleteAction(removeAllReferencesOnDelete() =
>> true) constructor. Hence, the DeleteCommand() is used instead of the
>> RemoveCommand. It appears that removeAllReferencesOnDelete() is not
>> fine-grained enough to suit my needs.

> I'm a bit confused. You are always selecting an object and always
> deleting that object...
I can understand why since I didn't make myself very clear. In my UI, I
can create multiple references to the same referent using DND. When I
select one of these reference and choose to delete it, the EMF
framework's Delete mechanism deletes all these multiple references. I
looked at the DeleteCommand's source; it resolves all usage
cross-references and deletes them by creating a RemoveCommand for each
reference. This is not what I want since it is counter-intuitive to an
user. The good news is that the referent is not deleted, only the
references.
Now if instead I select the referent, the referent and all the multiple
references are deleted. The referent deletion behavior makes perfect
sense to me.
>> So,
>>
>> 1. Is there some easy mechanism available to delete only the selected
>> reference (I think this entails using the RemoveCommand) and retain
>> all other behavior of Delete? Ideally, the user would select the
>> delete menu item, and I would provide a dialog box with a choice of
>> which behavior they wish to choose: delete a single reference, delete
>> all references, or delete all references and referent.

> I understand delete single reference to mean remove the object from the
> one object that's referencing it. I would expect delete on the wrapper
> to do that.
This is what I want to happen but it does not. Delete on the wrapper
does not delete that wrapper only.

I would expect that delete all references would be what
> delete normally does when applied to the actual EObject. The third
> choice escapes me...
That's because I did not explain it clearly. The third choice is the
situation when delete is applied to the actual EObject which does work
as you and I both expect. So, if I am not as clear as mud again, it is
the first choice that is not working as you and I expect, but is
actually working as the second choice (ie, deleting all references).

>> 2. Is there some handy mechanism to manipulate wrappers, eg, unwrap them?
> Yes. Wrappers implement IWrapperItemProvider and methods like
> AdapterFactoryEditingDomain.unwrap is useful tool.
Thanks. Using this info, I just updated my double-click handling.

>> 3. There appears no "easy" way to choose between the RemoveCommand and
>> the DeleteCommand in ItemProviderAdapter. What is the whole picture here?
> What you see is all there is. :-P
Actually, while peering into the DeleteCommand, I saw that the
DeleteCommand is implemented by creating RemoveCommands and/or
SetCommands. So that was a happy discovery.

>> 4. In my app, the user can create references by using DND. When the
>> DND is in progress, I see a shorcut overlay on the icon. How and
>> where is this done?
> DragAndDropCommand does a lot of fancy and complex things to make all
> this work.
I will dig into this when I get a chance.

>> 5. In addition to DND, I would like to provide a copy-and-paste
>> approach to creating references which would have the same effect.
>> Could you give me a quick summary of what I would have to do to
>> achieve this?
> What happens now? I imagine it's a bit tricky since copy kind of
> implies created a new object...
Interestingly enough, when I do copy/paste, it seems to work like DND
without the animation, ie, the object appears in the target "owner". The
Properties view shows the correct properties for the object.
Double-click does not work as expected. Unlike via DND, the object does
not get persisted when I exit the application.

>>
>> Sorry for the lengthy post. I would normally pursue this on my own
>> ("please teach me to fish"), but right now I am so pressed for time
>> that any hand-holding ("please give me a fish") would really be
>> appreciated.
> I'm setting up a really big fish tank at home in the next few weeks. 180
> gallons. I guess that's not related to your fish question though. :-P
Not unless you can cook me up some Cajun catfish which sounds pretty
darn good right about now. Hmmm, 180 gallons, sounds like you may be
getting ready to farm some big ones. Perhaps I can learn to fish there!

>
> The best you can really do is specialize the domain's createCommand or
> the individual item provider create*Command methods...
Yep. As time and money permit!
Thanks again.
>>
>> Thanks Ed.
>>
>> Uday
>>
>> "Ed Merks" <merks@ca.ibm.com <mailto:merks@ca.ibm.com>> wrote in
>> message news:fqk1kt$f3g$1@build.eclipse.org...
>> Uday,
>>
>> So you've verified that wrappers are being created for the
>> children displayed by B? And that when you are invoking delete on
>> that child, it's being invoked for that wrapper?
>>
>> It looks like you tried to invoke undo, but you didn't mention that...
>>
>>
>> Uday Kabe wrote:
>>> Ed,
>>>
>>> I am trying to do the same with the following EMF model:
>>>
>>> I have 3 EClasses A, B and C. A has a multiplicity-many containment
>>> reference to C, while B has a similar, non-containment reference to C. Both
>>> A and B
>>> display these references as children in my view. I can DND an instance of C
>>> from A into B. Undo and Redo operations for the DND seem to work fine. If
>>> I delete
>>> an instance of C, both the contained and non-contained objects are deleted.
>>> Undo
>>> Delete throws an exception which I have not yet chased down.
>>>
>>> I have overridden isWrappingNeeded() to return true in the item provider for
>>> class B but doing only
>>> this does not seem to work. Is there something else or something different
>>> I need to do?
>>>
>>> Thanks.
>>>
>>> Uday
>>>
>>> Here is the exception trace:
>>>
>>> org.eclipse.emf.common.util.WrappedException: An exception was ignored
>>> during command execution
>>> at
>>> org.eclipse.emf.common.command.BasicCommandStack.handleError (BasicCommandStack.java:279)
>>> at
>>> org.eclipse.emf.common.command.BasicCommandStack.undo(BasicC ommandStack.java:146)
>>> at org.eclipse.emf.edit.ui.action.UndoAction.run(UndoAction.jav a:67)
>>> at org.eclipse.jface.action.Action.runWithEvent(Action.java:499 )
>>> at
>>> org.eclipse.ui.actions.RetargetAction.runWithEvent(RetargetA ction.java:229)
>>> at
>>> org.eclipse.jface.action.ActionContributionItem.handleWidget Selection(ActionContributionItem.java:539)
>>> at
>>> org.eclipse.jface.action.ActionContributionItem.access$2(Act ionContributionItem.java:488)
>>> at
>>> org.eclipse.jface.action.ActionContributionItem$5.handleEven t(ActionContributionItem.java:400)
>>> at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java :66)
>>> at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:928)
>>> at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.ja va:3348)
>>> at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java :2968)
>>> at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.jav a:1914)
>>> at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:1878)
>>> at
>>> org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Work bench.java:419)
>>> at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.j ava:149)
>>> at
>>> ws.kabe.news.presentation.NewsEditorAdvisor$Application.run( NewsEditorAdvisor.java:110)
>>> at
>>> org.eclipse.core.internal.runtime.PlatformActivator$1.run(Pl atformActivator.java:78)
>>> at
>>> org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .runApplication(EclipseAppLauncher.java:92)
>>> at
>>> org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .start(EclipseAppLauncher.java:68)
>>> at
>>> org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:400)
>>> at
>>> org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:177)
>>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>> at
>>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:39)
>>> at
>>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:25)
>>> at java.lang.reflect.Method.invoke(Method.java:585)
>>> at org.eclipse.core.launcher.Main.invokeFramework(Main.java:336 )
>>> at org.eclipse.core.launcher.Main.basicRun(Main.java:280)
>>> at org.eclipse.core.launcher.Main.run(Main.java:977)
>>> at org.eclipse.core.launcher.Main.main(Main.java:952)
>>> Caused by:
>>> org.eclipse.emf.common.util.BasicEList$BasicIndexOutOfBounds Exception:
>>> index=3, size=0
>>> at org.eclipse.emf.common.util.BasicEList.add(BasicEList.java:6 38)
>>> at
>>> org.eclipse.emf.edit.command.RemoveCommand.doUndo(RemoveComm and.java:461)
>>> at
>>> org.eclipse.emf.edit.command.AbstractOverrideableCommand.und o(AbstractOverrideableCommand.java:157)
>>> at
>>> org.eclipse.emf.common.command.CommandWrapper.undo(CommandWr apper.java:198)
>>> at
>>> org.eclipse.emf.common.command.CompoundCommand.undo(Compound Command.java:333)
>>> at
>>> org.eclipse.emf.common.command.BasicCommandStack.undo(BasicC ommandStack.java:141)
>>> ... 28 more
>>>
>>>
>>>
>>> "Mike Gering" <mike@aol.com> wrote in message
>>> news:fq6s7o$gbj$1@build.eclipse.org...
>>>
>>>> Ed Merks wrote:
>>>>
>>>>> Aren't the displayed objects under the non-containment feature wrappers?
>>>>> Isn't that the case?
>>>>>
>>>> Nope. The ItemProviderAdapter.isWrapperNeeded() method looks only for
>>>> attributes and ignores references:
>>>> for (Iterator i = getAnyChildrenFeatures(object).iterator();
>>>> i.hasNext(); )
>>>> {
>>>> EStructuralFeature f = (EStructuralFeature)i.next();
>>>> if (f instanceof EAttribute)
>>>> {
>>>> wrappingNeeded = Boolean.TRUE;
>>>> }
>>>> }
>>>>
>>>>
>>>>
>>>>> Perhaps you need to force wrappers to be created (override
>>>>> isWrappingNeeded) so you'll know when you are operating on the referenced
>>>>> child as opposed to the real one actually contained.
>>>>>
>>>> I did that and lo! the chilren references get wrapped, and to my glee, the
>>>> delete command works as I want, without having to subclass change
>>>> AdapterFactoryEditingDomain. Deleting the reference child deletes the
>>>> reference only. Deleting the contained object deletes it and its
>>>> references, as before.
>>>>
>>>> Mike
>>>>
>>>
>>>
>>>
>>
>
Re: Deleting child reference deletes referent? [message #417359 is a reply to message #417350] Thu, 06 March 2008 13:09 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Uday,

Comments below.

Uday Kabe wrote:
> Ed,
>
> Thanks. Comments below.
>
> Ed Merks wrote:
>> Uday,
>>
>> Comments below.
>>
>> Uday Kabe wrote:
>>> Ed,
>>>
>>> Thanks. Very perceptive.
>>>
>>> The wrappers are indeed being created. These wrappers are
>>> DelegatingWrapperItemProvider's which delegate to the wrapped
>>> value's IStructuredItemContentProvider.
>>>
>>> My problem: My override of AdapterFactoryContentProvider's
>>> getChildren() was inadvertently delivering the "value" instead of
>>> the "wrapper" to the Delete command. Each wrapper I create is now
>>> an anon DelegatingWrapperItemProvider which handles some of these
>>> overrides.
>>>
>>> The behavior of the Delete command is a bit awkward as it currently
>>> sits. When I select a reference, it deletes all such references
>>> which is not what I want but does not delete the referent which is
>>> what I want.
>
>> EObjects themselves can't be deleted. They're only deleted by
>> virtue of eliminating all references to them so they can be garbage
>> collected.
> I understand. Hopefully, I will be a little clearer in the rest of my
> reply.
>
>>> If I select the referent, it deletes the referent and all references
>>> which is also what I want. I know that the Delete action is
>>> constructed with the DeleteAction(removeAllReferencesOnDelete() =
>>> true) constructor. Hence, the DeleteCommand() is used instead of
>>> the RemoveCommand. It appears that removeAllReferencesOnDelete() is
>>> not fine-grained enough to suit my needs.
>
>> I'm a bit confused. You are always selecting an object and always
>> deleting that object...
> I can understand why since I didn't make myself very clear. In my UI,
> I can create multiple references to the same referent using DND. When
> I select one of these reference and choose to delete it, the EMF
> framework's Delete mechanism deletes all these multiple references. I
> looked at the DeleteCommand's source; it resolves all usage
> cross-references and deletes them by creating a RemoveCommand for each
> reference. This is not what I want since it is counter-intuitive to
> an user. The good news is that the referent is not deleted, only the
> references.
> Now if instead I select the referent, the referent and all the
> multiple references are deleted. The referent deletion behavior makes
> perfect sense to me.
>>> So,
>>>
>>> 1. Is there some easy mechanism available to delete only the
>>> selected reference (I think this entails using the RemoveCommand)
>>> and retain all other behavior of Delete? Ideally, the user would
>>> select the delete menu item, and I would provide a dialog box with a
>>> choice of which behavior they wish to choose: delete a single
>>> reference, delete all references, or delete all references and
>>> referent.
>
>> I understand delete single reference to mean remove the object from
>> the one object that's referencing it. I would expect delete on the
>> wrapper to do that.
> This is what I want to happen but it does not. Delete on the wrapper
> does not delete that wrapper only.
>
> I would expect that delete all references would be what
>> delete normally does when applied to the actual EObject. The third
>> choice escapes me...
> That's because I did not explain it clearly. The third choice is the
> situation when delete is applied to the actual EObject which does work
> as you and I both expect. So, if I am not as clear as mud again, it
> is the first choice that is not working as you and I expect, but is
> actually working as the second choice (ie, deleting all references).
>
>>> 2. Is there some handy mechanism to manipulate wrappers, eg, unwrap
>>> them?
>> Yes. Wrappers implement IWrapperItemProvider and methods like
>> AdapterFactoryEditingDomain.unwrap is useful tool.
> Thanks. Using this info, I just updated my double-click handling.
>
>>> 3. There appears no "easy" way to choose between the RemoveCommand
>>> and the DeleteCommand in ItemProviderAdapter. What is the whole
>>> picture here?
>> What you see is all there is. :-P
> Actually, while peering into the DeleteCommand, I saw that the
> DeleteCommand is implemented by creating RemoveCommands and/or
> SetCommands. So that was a happy discovery.
>
>>> 4. In my app, the user can create references by using DND. When
>>> the DND is in progress, I see a shorcut overlay on the icon. How
>>> and where is this done?
>> DragAndDropCommand does a lot of fancy and complex things to make all
>> this work.
> I will dig into this when I get a chance.
>
>>> 5. In addition to DND, I would like to provide a copy-and-paste
>>> approach to creating references which would have the same effect.
>>> Could you give me a quick summary of what I would have to do to
>>> achieve this?
>> What happens now? I imagine it's a bit tricky since copy kind of
>> implies created a new object...
> Interestingly enough, when I do copy/paste, it seems to work like DND
> without the animation, ie, the object appears in the target "owner".
> The Properties view shows the correct properties for the object.
> Double-click does not work as expected. Unlike via DND, the object
> does not get persisted when I exit the application.
Yes, but is it a copy of the object. Perhaps when you serialize,
you'll find it's a dangling reference...
>
>>>
>>> Sorry for the lengthy post. I would normally pursue this on my own
>>> ("please teach me to fish"), but right now I am so pressed for time
>>> that any hand-holding ("please give me a fish") would really be
>>> appreciated.
>> I'm setting up a really big fish tank at home in the next few weeks.
>> 180 gallons. I guess that's not related to your fish question
>> though. :-P
> Not unless you can cook me up some Cajun catfish which sounds pretty
> darn good right about now. Hmmm, 180 gallons, sounds like you may be
> getting ready to farm some big ones. Perhaps I can learn to fish there!
They'll be pets!
>
>>
>> The best you can really do is specialize the domain's createCommand
>> or the individual item provider create*Command methods...
> Yep. As time and money permit!
> Thanks again.
>>>
>>> Thanks Ed.
>>>
>>> Uday
>>>
>>> "Ed Merks" <merks@ca.ibm.com <mailto:merks@ca.ibm.com>> wrote in
>>> message news:fqk1kt$f3g$1@build.eclipse.org...
>>> Uday,
>>>
>>> So you've verified that wrappers are being created for the
>>> children displayed by B? And that when you are invoking delete on
>>> that child, it's being invoked for that wrapper?
>>>
>>> It looks like you tried to invoke undo, but you didn't mention
>>> that...
>>>
>>>
>>> Uday Kabe wrote:
>>>> Ed,
>>>>
>>>> I am trying to do the same with the following EMF model:
>>>>
>>>> I have 3 EClasses A, B and C. A has a multiplicity-many
>>>> containment
>>>> reference to C, while B has a similar, non-containment
>>>> reference to C. Both A and B
>>>> display these references as children in my view. I can DND an
>>>> instance of C
>>>> from A into B. Undo and Redo operations for the DND seem to
>>>> work fine. If I delete
>>>> an instance of C, both the contained and non-contained objects
>>>> are deleted. Undo
>>>> Delete throws an exception which I have not yet chased down.
>>>>
>>>> I have overridden isWrappingNeeded() to return true in the item
>>>> provider for class B but doing only
>>>> this does not seem to work. Is there something else or
>>>> something different I need to do?
>>>>
>>>> Thanks.
>>>>
>>>> Uday
>>>>
>>>> Here is the exception trace:
>>>>
>>>> org.eclipse.emf.common.util.WrappedException: An exception was
>>>> ignored during command execution
>>>> at
>>>> org.eclipse.emf.common.command.BasicCommandStack.handleError (BasicCommandStack.java:279)
>>>>
>>>> at
>>>> org.eclipse.emf.common.command.BasicCommandStack.undo(BasicC ommandStack.java:146)
>>>>
>>>> at
>>>> org.eclipse.emf.edit.ui.action.UndoAction.run(UndoAction.jav a:67)
>>>> at org.eclipse.jface.action.Action.runWithEvent(Action.java:499 )
>>>> at
>>>> org.eclipse.ui.actions.RetargetAction.runWithEvent(RetargetA ction.java:229)
>>>>
>>>> at
>>>> org.eclipse.jface.action.ActionContributionItem.handleWidget Selection(ActionContributionItem.java:539)
>>>>
>>>> at
>>>> org.eclipse.jface.action.ActionContributionItem.access$2(Act ionContributionItem.java:488)
>>>>
>>>> at
>>>> org.eclipse.jface.action.ActionContributionItem$5.handleEven t(ActionContributionItem.java:400)
>>>>
>>>> at
>>>> org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java :66)
>>>> at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:928)
>>>> at
>>>> org.eclipse.swt.widgets.Display.runDeferredEvents(Display.ja va:3348)
>>>> at
>>>> org.eclipse.swt.widgets.Display.readAndDispatch(Display.java :2968)
>>>> at
>>>> org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.jav a:1914)
>>>> at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:1878)
>>>> at
>>>> org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Work bench.java:419)
>>>>
>>>> at
>>>> org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.j ava:149)
>>>> at
>>>> ws.kabe.news.presentation.NewsEditorAdvisor$Application.run( NewsEditorAdvisor.java:110)
>>>>
>>>> at
>>>> org.eclipse.core.internal.runtime.PlatformActivator$1.run(Pl atformActivator.java:78)
>>>>
>>>> at
>>>> org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .runApplication(EclipseAppLauncher.java:92)
>>>>
>>>> at
>>>> org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .start(EclipseAppLauncher.java:68)
>>>>
>>>> at
>>>> org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:400)
>>>>
>>>> at
>>>> org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:177)
>>>>
>>>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>>> at
>>>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:39)
>>>>
>>>> at
>>>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:25)
>>>>
>>>> at java.lang.reflect.Method.invoke(Method.java:585)
>>>> at org.eclipse.core.launcher.Main.invokeFramework(Main.java:336 )
>>>> at org.eclipse.core.launcher.Main.basicRun(Main.java:280)
>>>> at org.eclipse.core.launcher.Main.run(Main.java:977)
>>>> at org.eclipse.core.launcher.Main.main(Main.java:952)
>>>> Caused by:
>>>> org.eclipse.emf.common.util.BasicEList$BasicIndexOutOfBounds Exception:
>>>> index=3, size=0
>>>> at
>>>> org.eclipse.emf.common.util.BasicEList.add(BasicEList.java:6 38)
>>>> at
>>>> org.eclipse.emf.edit.command.RemoveCommand.doUndo(RemoveComm and.java:461)
>>>>
>>>> at
>>>> org.eclipse.emf.edit.command.AbstractOverrideableCommand.und o(AbstractOverrideableCommand.java:157)
>>>>
>>>> at
>>>> org.eclipse.emf.common.command.CommandWrapper.undo(CommandWr apper.java:198)
>>>>
>>>> at
>>>> org.eclipse.emf.common.command.CompoundCommand.undo(Compound Command.java:333)
>>>>
>>>> at
>>>> org.eclipse.emf.common.command.BasicCommandStack.undo(BasicC ommandStack.java:141)
>>>>
>>>> ... 28 more
>>>>
>>>>
>>>>
>>>> "Mike Gering" <mike@aol.com> wrote in message
>>>> news:fq6s7o$gbj$1@build.eclipse.org...
>>>>
>>>>> Ed Merks wrote:
>>>>>
>>>>>> Aren't the displayed objects under the non-containment
>>>>>> feature wrappers? Isn't that the case?
>>>>>>
>>>>> Nope. The ItemProviderAdapter.isWrapperNeeded() method looks
>>>>> only for attributes and ignores references:
>>>>> for (Iterator i =
>>>>> getAnyChildrenFeatures(object).iterator(); i.hasNext(); )
>>>>> {
>>>>> EStructuralFeature f = (EStructuralFeature)i.next();
>>>>> if (f instanceof EAttribute)
>>>>> {
>>>>> wrappingNeeded = Boolean.TRUE;
>>>>> }
>>>>> }
>>>>>
>>>>>
>>>>>
>>>>>> Perhaps you need to force wrappers to be created (override
>>>>>> isWrappingNeeded) so you'll know when you are operating on
>>>>>> the referenced child as opposed to the real one actually
>>>>>> contained.
>>>>>>
>>>>> I did that and lo! the chilren references get wrapped, and to
>>>>> my glee, the delete command works as I want, without having to
>>>>> subclass change AdapterFactoryEditingDomain. Deleting the
>>>>> reference child deletes the reference only. Deleting the
>>>>> contained object deletes it and its references, as before.
>>>>>
>>>>> Mike
>>>>
>>>>
>>>>
>>>
>>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Deleting child reference deletes referent? [message #417366 is a reply to message #417359] Thu, 06 March 2008 16:01 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: udaykabe.hotmail.com

Ed,

Thanks. I need to beat this horse a bit more (should I say fish for more
information). ;-0

The isWrappingNeeded() override initially seemed to do the trick, but now
the Eclipse contribution mechanism no longer recognizes these wrappers as
the unwrapped objects. So all the actions that I have contributed no
longer show up for the wrappers. All of a sudden, there is a domino effect
of changes that become necessary.

I have some other thoughts on how I may be able to do this. The following
questions are probably naive, but I have to ask them anyway especially if I
decide to pursue this path:

1. Is there some meta information that a reference can use to determine
that it is a reference, and also it's unique location in the model instance
hierarchy?
2. Can it backtrack to its referent?
3. In order to achieve 1. and 2., do references have to be modeled as
explicitly bidirectional, meaning they would have bidirectional
navigability?

I have been developing with EMF for two and a half years now. I love using
it, and you would think that I would already know the answers to the above
questions. Again, not to sound like a broken record, but thanks so much for
the super-speedy responses.

Uday
Re: Deleting child reference deletes referent? [message #417371 is a reply to message #417366] Thu, 06 March 2008 17:24 Go to previous message
Eclipse UserFriend
Originally posted by: udaykabe.hotmail.com

Ed,

Ignore my last post.

Thanks.

Uday

"Uday Kabe" <udaykabe@hotmail.com> wrote in message
news:fqp4hm$29u$1@build.eclipse.org...
> Ed,
>
> Thanks. I need to beat this horse a bit more (should I say fish for more
> information). ;-0
>
> The isWrappingNeeded() override initially seemed to do the trick, but now
> the Eclipse contribution mechanism no longer recognizes these wrappers as
> the unwrapped objects. So all the actions that I have contributed no
> longer show up for the wrappers. All of a sudden, there is a domino
> effect of changes that become necessary.
>
> I have some other thoughts on how I may be able to do this. The following
> questions are probably naive, but I have to ask them anyway especially if
> I decide to pursue this path:
>
> 1. Is there some meta information that a reference can use to determine
> that it is a reference, and also it's unique location in the model
> instance hierarchy?
> 2. Can it backtrack to its referent?
> 3. In order to achieve 1. and 2., do references have to be modeled as
> explicitly bidirectional, meaning they would have bidirectional
> navigability?
>
> I have been developing with EMF for two and a half years now. I love
> using it, and you would think that I would already know the answers to the
> above questions. Again, not to sound like a broken record, but thanks so
> much for the super-speedy responses.
>
> Uday
>
Previous Topic:item provider adapter 'getText' redefinitions
Next Topic:symmetric references
Goto Forum:
  


Current Time: Sat Apr 27 05:03:51 GMT 2024

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

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

Back to the top