Home » Modeling » EMF » DeleteCommand, children
| DeleteCommand, children [message #398478] |
Sun, 12 February 2006 03:41  |
Eclipse User |
|
|
|
I noticed that org.eclipse.emf.edit.command.DeleteCommand only removes
objects from their parent container if these references (in the parent
container) are marked as 'children' in the genmodel. Containment references
which are not 'children' are not removed by DeleteCommand. Is this by design
or is it a bug?
Koen
|
|
|
| Re: DeleteCommand, children [message #398488 is a reply to message #398478] |
Mon, 13 February 2006 09:21   |
Eclipse User |
|
|
|
This is a multi-part message in MIME format.
--------------070002060401020408080608
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Koen,
I'm not sure what you are referring to. The DeleteCommand just removes
all references:
public void execute()
{
super.execute();
Map usages = EcoreUtil.UsageCrossReferencer.findAll(collection,
domain.getResourceSet());
for (Iterator i = usages.entrySet().iterator(); i.hasNext(); )
{
Map.Entry entry = (Map.Entry)i.next();
EObject eObject = (EObject)entry.getKey();
Collection settings = (Collection)entry.getValue();
for (Iterator j = settings.iterator(); j.hasNext(); )
{
EStructuralFeature.Setting setting =
(EStructuralFeature.Setting)j.next();
EObject referencingEObject = setting.getEObject();
EStructuralFeature eStructuralFeature =
setting.getEStructuralFeature();
if (eStructuralFeature.isMany())
{
appendAndExecute(RemoveCommand.create(domain,
referencingEObject, eStructuralFeature, eObject));
}
else
{
appendAndExecute(SetCommand.create(domain,
referencingEObject, eStructuralFeature, null));
}
}
}
}
Koen van Dijken wrote:
>I noticed that org.eclipse.emf.edit.command.DeleteCommand only removes
>objects from their parent container if these references (in the parent
>container) are marked as 'children' in the genmodel. Containment references
>which are not 'children' are not removed by DeleteCommand. Is this by design
>or is it a bug?
>
>Koen
>
>
>
>
>
>
--------------070002060401020408080608
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">
Koen,<br>
<br>
I'm not sure what you are referring to. The DeleteCommand just removes
all references:<br>
<blockquote><small> public void execute()</small><br>
<small> {</small><br>
<small> super.execute();</small><br>
<br>
<small> Map usages =
EcoreUtil.UsageCrossReferencer.findAll(collection,
domain.getResourceSet());</small><br>
<small> for (Iterator i = usages.entrySet().iterator();
i.hasNext(); )</small><br>
<small> {</small><br>
<small> Map.Entry entry = (Map.Entry)i.next();</small><br>
<small> EObject eObject = (EObject)entry.getKey();</small><br>
<small> Collection settings = (Collection)entry.getValue();</small><br>
<small> for (Iterator j = settings.iterator(); j.hasNext(); )</small><br>
<small> {</small><br>
<small> EStructuralFeature.Setting setting =
(EStructuralFeature.Setting)j.next();</small><br>
<small> EObject referencingEObject = setting.getEObject();</small><br>
<small> EStructuralFeature eStructuralFeature =
setting.getEStructuralFeature();</small><br>
<small> if (eStructuralFeature.isMany())</small><br>
<small> {</small><br>
<small> appendAndExecute(RemoveCommand.create(domain,
referencingEObject, eStructuralFeature, eObject));</small><br>
<small> }</small><br>
<small> else</small><br>
<small> {</small><br>
<small> appendAndExecute(SetCommand.create(domain,
referencingEObject, eStructuralFeature, null));</small><br>
<small> }</small><br>
<small> }</small><br>
<small> }</small><br>
<small> }</small><br>
</blockquote>
<br>
Koen van Dijken wrote:
<blockquote cite="middsmsb8$s0o$1@utils.eclipse.org" type="cite">
<pre wrap="">I noticed that org.eclipse.emf.edit.command.DeleteCommand only removes
objects from their parent container if these references (in the parent
container) are marked as 'children' in the genmodel. Containment references
which are not 'children' are not removed by DeleteCommand. Is this by design
or is it a bug?
Koen
</pre>
</blockquote>
<br>
</body>
</html>
--------------070002060401020408080608--
|
|
|
| Re: DeleteCommand, children [message #398490 is a reply to message #398488] |
Mon, 13 February 2006 09:41   |
Eclipse User |
|
|
|
This is a multi-part message in MIME format.
------=_NextPart_000_000C_01C630B4.06FEDB90
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Yes, that's what I think it is supposed to do, but it turns out that for =
containment references it only removes them if they are 'children'. This =
is caused by the call to =
org.eclipse.emf.edit.provider.ItemProviderAdapter.getAnyChil drenFeatures(=
) as is visible in this stack trace:
AllDataProviderItemProvider(ItemProviderAdapter).factorRemov eCommand(Edit=
ingDomain, CommandParameter) line: 1052
AllDataProviderItemProvider(ItemProviderAdapter).createComma nd(Object, =
EditingDomain, Class, CommandParameter) line: 787
AdapterFactoryEditingDomain.createCommand(Class, CommandParameter) line: =
396
AdapterFactoryEditingDomain.createCommand(Class, CommandParameter) line: =
450
RemoveCommand.create(EditingDomain, Object, Object, Collection) line: 98
RemoveCommand.create(EditingDomain, Collection) line: 90
DeleteCommand.prepare() line: 97
DeleteCommand(AbstractCommand).canExecute() line: 113
CompoundCommand.appendAndExecute(Command) line: 649
SpatialImpl$3.doExecute() line: 1388
SpatialImpl$3(AbstractOverrideableCommand).execute() line: 128
CompoundCommand.appendAndExecute(Command) line: 653
SpatialImpl$1.doExecute() line: 1192
SpatialImpl$1(AbstractOverrideableCommand).execute() line: 128
BasicCommandStack.execute(Command) line: 91
SpatialImpl.removeDataProviderUndoable(IDataProvider, boolean) line: =
1329
RemoveDataproviderAction.run() line: 36
If in the object from which the reference should be deleted there are no =
references which are 'children' , getAnyChildrenFeatures will return an =
empty list, and factorRemoveCommand will return =
UnexecutableCommand.INSTANCE.
Koen
"Ed Merks" <merks@ca.ibm.com> wrote in message =
news:dsq4kd$u6t$2@utils.eclipse.org...
Koen,
I'm not sure what you are referring to. The DeleteCommand just =
removes all references:
public void execute()
{
super.execute();
Map usages =3D =
EcoreUtil.UsageCrossReferencer.findAll(collection, =
domain.getResourceSet());
for (Iterator i =3D usages.entrySet().iterator(); i.hasNext(); )
{
Map.Entry entry =3D (Map.Entry)i.next();
EObject eObject =3D (EObject)entry.getKey();
Collection settings =3D (Collection)entry.getValue();
for (Iterator j =3D settings.iterator(); j.hasNext(); )
{
EStructuralFeature.Setting setting =3D =
(EStructuralFeature.Setting)j.next();
EObject referencingEObject =3D setting.getEObject();
EStructuralFeature eStructuralFeature =3D =
setting.getEStructuralFeature();
if (eStructuralFeature.isMany())
{
appendAndExecute(RemoveCommand.create(domain, =
referencingEObject, eStructuralFeature, eObject));
}
else
{
appendAndExecute(SetCommand.create(domain, =
referencingEObject, eStructuralFeature, null));
}
}
}
}
Koen van Dijken wrote:=20
I noticed that org.eclipse.emf.edit.command.DeleteCommand only removes=20
objects from their parent container if these references (in the parent=20
container) are marked as 'children' in the genmodel. Containment =
references=20
which are not 'children' are not removed by DeleteCommand. Is this by =
design=20
or is it a bug?
Koen
=20
------=_NextPart_000_000C_01C630B4.06FEDB90
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.2900.2802" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY text=3D#000000 bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Yes, that's what I think it is supposed =
to do, but=20
it turns out that for containment references it only removes them if =
they are=20
'children'. This is caused by the call to=20
org.eclipse.emf.edit.provider.ItemProviderAdapter.getAnyChil drenFeatures(=
) as is=20
visible in this stack trace:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial=20
size=3D2> AllDataProviderItemProvider(ItemProviderAdapter).factorRemov eCom=
mand(EditingDomain,=20
CommandParameter) line:=20
1052<BR> AllDataProviderItemProvider(ItemProviderAdapter).createComma nd(Ob=
ject,=20
EditingDomain, Class, CommandParameter) line:=20
787<BR>AdapterFactoryEditingDomain.createCommand(Class, =
CommandParameter) line:=20
396<BR>AdapterFactoryEditingDomain.createCommand(Class, =
CommandParameter) line:=20
450<BR>RemoveCommand.create(EditingDomain, Object, Object, Collection) =
line:=20
98<BR>RemoveCommand.create(EditingDomain, Collection) line:=20
90<BR>DeleteCommand.prepare() line:=20
97<BR>DeleteCommand(AbstractCommand).canExecute() line:=20
113<BR>CompoundCommand.appendAndExecute(Command) line:=20
649<BR>SpatialImpl$3.doExecute() line:=20
1388<BR>SpatialImpl$3(AbstractOverrideableCommand).execute() line:=20
128<BR>CompoundCommand.appendAndExecute(Command) line:=20
653<BR>SpatialImpl$1.doExecute() line:=20
1192<BR>SpatialImpl$1(AbstractOverrideableCommand).execute() line:=20
128<BR>BasicCommandStack.execute(Command) line:=20
91<BR>SpatialImpl.removeDataProviderUndoable(IDataProvider, boolean) =
line:=20
1329<BR>RemoveDataproviderAction.run() line: 36<BR></FONT></DIV>
<DIV><FONT face=3DArial size=3D2>If in the object from which the =
reference should be=20
deleted there are no references which are 'children' , =
getAnyChildrenFeatures=20
will return an empty list, and factorRemoveCommand will return=20
UnexecutableCommand.INSTANCE.</DIV></FONT>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>Koen</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2> </DIV></FONT>
<BLOCKQUOTE=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<DIV>"Ed Merks" <<A =
href=3D"mailto:merks@ca.ibm.com">merks@ca.ibm.com</A>>=20
wrote in message <A=20
=
href=3D"news:dsq4kd$u6t$2@utils.eclipse.org">news:dsq4kd$u6t$2@utils.ecli=
pse.org</A>...</DIV>Koen,<BR><BR>I'm=20
not sure what you are referring to. The DeleteCommand just =
removes all=20
references:<BR>
<BLOCKQUOTE><SMALL> public void =
execute()</SMALL><BR><SMALL> =20
{</SMALL><BR><SMALL> =20
super.execute();</SMALL><BR><BR><SMALL> Map usages =
=3D=20
EcoreUtil.UsageCrossReferencer.findAll(collection,=20
domain.getResourceSet());</SMALL><BR><SMALL> for =
(Iterator=20
i =3D usages.entrySet().iterator(); i.hasNext();=20
)</SMALL><BR><SMALL> =20
{</SMALL><BR><SMALL> Map.Entry entry =
=3D=20
=
(Map.Entry)i.next();</SMALL><BR><SMALL> =20
EObject eObject =3D=20
=
(EObject)entry.getKey();</SMALL><BR><SMALL> =
=20
Collection settings =3D=20
=
(Collection)entry.getValue();</SMALL><BR><SMALL> &=
nbsp;=20
for (Iterator j =3D settings.iterator(); j.hasNext();=20
)</SMALL><BR><SMALL> =20
{</SMALL><BR><SMALL> =20
EStructuralFeature.Setting setting =3D=20
=
(EStructuralFeature.Setting)j.next();</SMALL><BR><SMALL>  =
; =20
EObject referencingEObject =3D=20
=
setting.getEObject();</SMALL><BR><SMALL> &nb=
sp; =20
EStructuralFeature eStructuralFeature =3D=20
=
setting.getEStructuralFeature();</SMALL><BR><SMALL> &nbs=
p; =20
if=20
=
(eStructuralFeature.isMany())</SMALL><BR><SMALL> &=
nbsp; =20
=
{</SMALL><BR><SMALL>  =
;=20
appendAndExecute(RemoveCommand.create(domain, referencingEObject,=20
eStructuralFeature,=20
=
eObject));</SMALL><BR><SMALL> =20
}</SMALL><BR><SMALL> =20
else</SMALL><BR><SMALL> =20
=
{</SMALL><BR><SMALL>  =
;=20
appendAndExecute(SetCommand.create(domain, referencingEObject,=20
eStructuralFeature,=20
null));</SMALL><BR><SMALL> =
}</SMALL><BR><SMALL> =20
}</SMALL><BR><SMALL> }</SMALL><BR><SMALL> =20
}</SMALL><BR></BLOCKQUOTE><BR>Koen van Dijken wrote:=20
<BLOCKQUOTE cite=3Dmiddsmsb8$s0o$1@utils.eclipse.org =
type=3D"cite"><PRE wrap=3D"">I noticed that =
org.eclipse.emf.edit.command.DeleteCommand only removes=20
objects from their parent container if these references (in the parent=20
container) are marked as 'children' in the genmodel. Containment =
references=20
which are not 'children' are not removed by DeleteCommand. Is this by =
design=20
or is it a bug?
Koen
</PRE></BLOCKQUOTE><BR></BLOCKQUOTE></BODY></HTML>
------=_NextPart_000_000C_01C630B4.06FEDB90--
|
|
|
| Re: DeleteCommand, children [message #398491 is a reply to message #398490] |
Mon, 13 February 2006 10:17   |
Eclipse User |
|
|
|
This is a multi-part message in MIME format.
--------------090504030604000401090806
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Koen,
The expectation is that object being deleted is contained somewhere in
the tree. Is that not the case in your scenario?
Koen van Dijken wrote:
> Yes, that's what I think it is supposed to do, but it turns out that
> for containment references it only removes them if they are
> 'children'. This is caused by the call to
> org.eclipse.emf.edit.provider.ItemProviderAdapter.getAnyChil drenFeatures()
> as is visible in this stack trace:
>
> AllDataProviderItemProvider(ItemProviderAdapter).factorRemov eCommand(EditingDomain,
> CommandParameter) line: 1052
> AllDataProviderItemProvider(ItemProviderAdapter).createComma nd(Object,
> EditingDomain, Class, CommandParameter) line: 787
> AdapterFactoryEditingDomain.createCommand(Class, CommandParameter)
> line: 396
> AdapterFactoryEditingDomain.createCommand(Class, CommandParameter)
> line: 450
> RemoveCommand.create(EditingDomain, Object, Object, Collection) line: 98
> RemoveCommand.create(EditingDomain, Collection) line: 90
> DeleteCommand.prepare() line: 97
> DeleteCommand(AbstractCommand).canExecute() line: 113
> CompoundCommand.appendAndExecute(Command) line: 649
> SpatialImpl$3.doExecute() line: 1388
> SpatialImpl$3(AbstractOverrideableCommand).execute() line: 128
> CompoundCommand.appendAndExecute(Command) line: 653
> SpatialImpl$1.doExecute() line: 1192
> SpatialImpl$1(AbstractOverrideableCommand).execute() line: 128
> BasicCommandStack.execute(Command) line: 91
> SpatialImpl.removeDataProviderUndoable(IDataProvider, boolean) line: 1329
> RemoveDataproviderAction.run() line: 36
> If in the object from which the reference should be deleted there are
> no references which are 'children' , getAnyChildrenFeatures will
> return an empty list, and factorRemoveCommand will return
> UnexecutableCommand.INSTANCE.
>
> Koen
>
>
>
> "Ed Merks" <merks@ca.ibm.com <mailto:merks@ca.ibm.com>> wrote in
> message news:dsq4kd$u6t$2@utils.eclipse.org...
> Koen,
>
> I'm not sure what you are referring to. The DeleteCommand just
> removes all references:
>
> public void execute()
> {
> super.execute();
>
> Map usages =
> EcoreUtil.UsageCrossReferencer.findAll(collection,
> domain.getResourceSet());
> for (Iterator i = usages.entrySet().iterator(); i.hasNext(); )
> {
> Map.Entry entry = (Map.Entry)i.next();
> EObject eObject = (EObject)entry.getKey();
> Collection settings = (Collection)entry.getValue();
> for (Iterator j = settings.iterator(); j.hasNext(); )
> {
> EStructuralFeature.Setting setting =
> (EStructuralFeature.Setting)j.next();
> EObject referencingEObject = setting.getEObject();
> EStructuralFeature eStructuralFeature =
> setting.getEStructuralFeature();
> if (eStructuralFeature.isMany())
> {
> appendAndExecute(RemoveCommand.create(domain,
> referencingEObject, eStructuralFeature, eObject));
> }
> else
> {
> appendAndExecute(SetCommand.create(domain,
> referencingEObject, eStructuralFeature, null));
> }
> }
> }
> }
>
>
> Koen van Dijken wrote:
>
>>I noticed that org.eclipse.emf.edit.command.DeleteCommand only removes
>>objects from their parent container if these references (in the parent
>>container) are marked as 'children' in the genmodel. Containment references
>>which are not 'children' are not removed by DeleteCommand. Is this by design
>>or is it a bug?
>>
>>Koen
>>
>>
>>
>>
>>
>>
>
--------------090504030604000401090806
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">
Koen,<br>
<br>
The expectation is that object being deleted is contained somewhere in
the tree. Is that not the case in your scenario?<br>
<br>
<br>
Koen van Dijken wrote:
<blockquote cite="middsq5s2$1mb$1@utils.eclipse.org" type="cite">
<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1">
<meta content="MSHTML 6.00.2900.2802" name="GENERATOR">
<style></style>
<div><font face="Arial" size="2">Yes, that's what I think it is
supposed to do, but it turns out that for containment references it
only removes them if they are 'children'. This is caused by the call to
org.eclipse.emf.edit.provider.ItemProviderAdapter.getAnyChil drenFeatures()
as is visible in this stack trace:</font></div>
<div> </div>
<div><font face="Arial" size="2"> AllDataProviderItemProvider(ItemProviderAdapter).factorRemov eCommand(EditingDomain,
CommandParameter) line: 1052<br>
AllDataProviderItemProvider(ItemProviderAdapter).createComma nd(Object,
EditingDomain, Class, CommandParameter) line: 787<br>
AdapterFactoryEditingDomain.createCommand(Class, CommandParameter)
line: 396<br>
AdapterFactoryEditingDomain.createCommand(Class, CommandParameter)
line: 450<br>
RemoveCommand.create(EditingDomain, Object, Object, Collection) line: 98<br>
RemoveCommand.create(EditingDomain, Collection) line: 90<br>
DeleteCommand.prepare() line: 97<br>
DeleteCommand(AbstractCommand).canExecute() line: 113<br>
CompoundCommand.appendAndExecute(Command) line: 649<br>
SpatialImpl$3.doExecute() line: 1388<br>
SpatialImpl$3(AbstractOverrideableCommand).execute() line: 128<br>
CompoundCommand.appendAndExecute(Command) line: 653<br>
SpatialImpl$1.doExecute() line: 1192<br>
SpatialImpl$1(AbstractOverrideableCommand).execute() line: 128<br>
BasicCommandStack.execute(Command) line: 91<br>
SpatialImpl.removeDataProviderUndoable(IDataProvider, boolean) line:
1329<br>
RemoveDataproviderAction.run() line: 36<br>
</font></div>
<div><font face="Arial" size="2">If in the object from which the
reference should be deleted there are no references which are
'children' , getAnyChildrenFeatures will return an empty list, and
factorRemoveCommand will return UnexecutableCommand.INSTANCE.</font></div>
<div> </div>
<div><font face="Arial" size="2">Koen</font></div>
<div> </div>
<div><font face="Arial" size="2"> </font></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" <<a href="mailto:merks@ca.ibm.com">merks@ca.ibm.com</a>>
wrote in message <a href="news:dsq4kd$u6t$2@utils.eclipse.org">news:dsq4kd$u6t$2@utils.eclipse.org</a>...</div>
Koen,<br>
<br>
I'm not sure what you are referring to. The DeleteCommand just removes
all references:<br>
<blockquote><small> public void execute()</small><br>
<small> {</small><br>
<small> super.execute();</small><br>
<br>
<small> Map usages =
EcoreUtil.UsageCrossReferencer.findAll(collection,
domain.getResourceSet());</small><br>
<small> for (Iterator i = usages.entrySet().iterator();
i.hasNext(); )</small><br>
<small> {</small><br>
<small> Map.Entry entry = (Map.Entry)i.next();</small><br>
<small> EObject eObject = (EObject)entry.getKey();</small><br>
<small> Collection settings = (Collection)entry.getValue();</small><br>
<small> for (Iterator j = settings.iterator(); j.hasNext(); )</small><br>
<small> {</small><br>
<small> EStructuralFeature.Setting setting =
(EStructuralFeature.Setting)j.next();</small><br>
<small> EObject referencingEObject = setting.getEObject();</small><br>
<small> EStructuralFeature eStructuralFeature =
setting.getEStructuralFeature();</small><br>
<small> if (eStructuralFeature.isMany())</small><br>
<small> {</small><br>
<small> appendAndExecute(RemoveCommand.create(domain,
referencingEObject, eStructuralFeature, eObject));</small><br>
<small> }</small><br>
<small> else</small><br>
<small> {</small><br>
<small> appendAndExecute(SetCommand.create(domain,
referencingEObject, eStructuralFeature, null));</small><br>
<small> }</small><br>
<small> }</small><br>
<small> }</small><br>
<small> }</small><br>
</blockquote>
<br>
Koen van Dijken wrote:
<blockquote cite="middsmsb8$s0o$1@utils.eclipse.org" type="cite">
<pre wrap="">I noticed that org.eclipse.emf.edit.command.DeleteCommand only removes
objects from their parent container if these references (in the parent
container) are marked as 'children' in the genmodel. Containment references
which are not 'children' are not removed by DeleteCommand. Is this by design
or is it a bug?
Koen
</pre>
</blockquote>
<br>
</blockquote>
</blockquote>
<br>
</body>
</html>
--------------090504030604000401090806--
|
|
|
| Re: DeleteCommand, children [message #398493 is a reply to message #398491] |
Mon, 13 February 2006 10:44   |
Eclipse User |
|
|
|
This is a multi-part message in MIME format.
------=_NextPart_000_000C_01C630BC.D2B0E0F0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
I created a testcase. I have this ecore model and genmodel
<?xml version=3D"1.0" encoding=3D"UTF-8"?>
<ecore:EPackage xmi:version=3D"2.0"
xmlns:xmi=3D"http://www.omg.org/XMI" =
xmlns:xsi=3D"http://www.w3.org/2001/XMLSchema-instance"
xmlns:ecore=3D"http://www.eclipse.org/emf/2002/Ecore" name=3D"pack">
<eClassifiers xsi:type=3D"ecore:EClass" name=3D"class1">
<eStructuralFeatures xsi:type=3D"ecore:EReference" name=3D"class2" =
upperBound=3D"-1"
eType=3D"#//class2" containment=3D"true"/>
</eClassifiers>
<eClassifiers xsi:type=3D"ecore:EClass" name=3D"class2"/>
</ecore:EPackage>
<?xml version=3D"1.0" encoding=3D"UTF-8"?>
<genmodel:GenModel xmi:version=3D"2.0"
xmlns:xmi=3D"http://www.omg.org/XMI" =
xmlns:ecore=3D"http://www.eclipse.org/emf/2002/Ecore"
xmlns:genmodel=3D"http://www.eclipse.org/emf/2002/GenModel" =
modelDirectory=3D"/Test/src"
modelPluginID=3D"Test" modelName=3D"My" =
importerID=3D"org.eclipse.emf.importer.ecore">
<foreignModel>My.ecore</foreignModel>
<genPackages prefix=3D"Pack" disposableProviderFactory=3D"true" =
ecorePackage=3D"My.ecore#/">
<genClasses ecoreClass=3D"My.ecore#//class1">
<genFeatures property=3D"Readonly" createChild=3D"true" =
ecoreFeature=3D"ecore:EReference My.ecore#//class1/class2"/>
</genClasses>
<genClasses ecoreClass=3D"My.ecore#//class2"/>
</genPackages>
</genmodel:GenModel>
Note that the containment references to Class2 in Class1 are not =
'children'. I create all the default stuff, including an editor, and =
with this editor I create an instance file which looks like this
<?xml version=3D"1.0" encoding=3D"UTF-8"?>
<null:class1 xmi:version=3D"2.0" xmlns:xmi=3D"http://www.omg.org/XMI" =
xmlns:null=3D"null">
<class2/>
<class2/>
</null:class1>
Class1 has two containment references to instances of Class2. Then for =
quick testing, I patch the generated editor a bit like this:
public void createModel() {
// I assume that the input is a file object.
//
IFileEditorInput modelFile =3D (IFileEditorInput) getEditorInput();
=20
try {
// Load the resource through the editing domain.
//
Resource resource =3D =
editingDomain.loadResource(URI.createPlatformResourceURI(
modelFile.getFile().getFullPath().toString()).toString());
=20
class1 class1 =3D (class1) resource.getContents().get(0);
class2 class2 =3D (class2) class1.getClass2().get(0);
Command cmd =3D DeleteCommand.create(editingDomain,class2);
editingDomain.getCommandStack().execute(cmd);
} catch (Exception exception) {
MyEditorPlugin.INSTANCE.log(exception);
}
}
I create a DeleteCommand to delete the first reference to Class2 in =
Class1. When I reopen the instance file created earlier, the =
DeleteCommand is run. To my suprise, the instance file has not changed. =
Or am I overlooking something?
Koen
"Ed Merks" <merks@ca.ibm.com> wrote in message =
news:dsq7te$5rg$1@utils.eclipse.org...
Koen,
The expectation is that object being deleted is contained somewhere in =
the tree. Is that not the case in your scenario?
Koen van Dijken wrote:=20
Yes, that's what I think it is supposed to do, but it turns out that =
for containment references it only removes them if they are 'children'. =
This is caused by the call to =
org.eclipse.emf.edit.provider.ItemProviderAdapter.getAnyChil drenFeatures(=
) as is visible in this stack trace:
=
AllDataProviderItemProvider(ItemProviderAdapter).factorRemov eCommand(Edit=
ingDomain, CommandParameter) line: 1052
=
AllDataProviderItemProvider(ItemProviderAdapter).createComma nd(Object, =
EditingDomain, Class, CommandParameter) line: 787
AdapterFactoryEditingDomain.createCommand(Class, CommandParameter) =
line: 396
AdapterFactoryEditingDomain.createCommand(Class, CommandParameter) =
line: 450
RemoveCommand.create(EditingDomain, Object, Object, Collection) =
line: 98
RemoveCommand.create(EditingDomain, Collection) line: 90
DeleteCommand.prepare() line: 97
DeleteCommand(AbstractCommand).canExecute() line: 113
CompoundCommand.appendAndExecute(Command) line: 649
SpatialImpl$3.doExecute() line: 1388
SpatialImpl$3(AbstractOverrideableCommand).execute() line: 128
CompoundCommand.appendAndExecute(Command) line: 653
SpatialImpl$1.doExecute() line: 1192
SpatialImpl$1(AbstractOverrideableCommand).execute() line: 128
BasicCommandStack.execute(Command) line: 91
SpatialImpl.removeDataProviderUndoable(IDataProvider, boolean) line: =
1329
RemoveDataproviderAction.run() line: 36
If in the object from which the reference should be deleted there =
are no references which are 'children' , getAnyChildrenFeatures will =
return an empty list, and factorRemoveCommand will return =
UnexecutableCommand.INSTANCE.
Koen
"Ed Merks" <merks@ca.ibm.com> wrote in message =
news:dsq4kd$u6t$2@utils.eclipse.org...
Koen,
I'm not sure what you are referring to. The DeleteCommand just =
removes all references:
public void execute()
{
super.execute();
Map usages =3D =
EcoreUtil.UsageCrossReferencer.findAll(collection, =
domain.getResourceSet());
for (Iterator i =3D usages.entrySet().iterator(); =
i.hasNext(); )
{
Map.Entry entry =3D (Map.Entry)i.next();
EObject eObject =3D (EObject)entry.getKey();
Collection settings =3D (Collection)entry.getValue();
for (Iterator j =3D settings.iterator(); j.hasNext(); )
{
EStructuralFeature.Setting setting =3D =
(EStructuralFeature.Setting)j.next();
EObject referencingEObject =3D setting.getEObject();
EStructuralFeature eStructuralFeature =3D =
setting.getEStructuralFeature();
if (eStructuralFeature.isMany())
{
appendAndExecute(RemoveCommand.create(domain, =
referencingEObject, eStructuralFeature, eObject));
}
else
{
appendAndExecute(SetCommand.create(domain, =
referencingEObject, eStructuralFeature, null));
}
}
}
}
Koen van Dijken wrote:=20
I noticed that org.eclipse.emf.edit.command.DeleteCommand only removes=20
objects from their parent container if these references (in the parent=20
container) are marked as 'children' in the genmodel. Containment =
references=20
which are not 'children' are not removed by DeleteCommand. Is this by =
design=20
or is it a bug?
Koen
=20
------=_NextPart_000_000C_01C630BC.D2B0E0F0
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.2900.2802" name=3DGENERATOR></HEAD>
<BODY text=3D#000000 bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>I created a testcase. I have this =
ecore model=20
and genmodel</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT size=3D2>
<P align=3Dleft><?xml version=3D"1.0" encoding=3D"UTF-8"?></P>
<P align=3Dleft><ecore:EPackage xmi:version=3D"2.0"</P>
<P align=3Dleft>xmlns:xmi=3D"http://www.omg.org/XMI"=20
xmlns:xsi=3D"http://www.w3.org/2001/XMLSchema-instance"</P>
<P align=3Dleft>xmlns:ecore=3D"http://www.eclipse.org/emf/2002/Ecore"=20
name=3D"pack"></P>
<P align=3Dleft><eClassifiers xsi:type=3D"ecore:EClass" =
name=3D"class1"></P>
<P align=3Dleft><eStructuralFeatures xsi:type=3D"ecore:EReference" =
name=3D"class2"=20
upperBound=3D"-1"</P>
<P align=3Dleft>eType=3D"#//class2" containment=3D"true"/></P>
<P align=3Dleft></eClassifiers></P>
<P align=3Dleft><eClassifiers xsi:type=3D"ecore:EClass" =
name=3D"class2"/></P>
<P align=3Dleft></ecore:EPackage></P>
<P align=3Dleft> </P><FONT size=3D2>
<P align=3Dleft><?xml version=3D"1.0" encoding=3D"UTF-8"?></P>
<P align=3Dleft><genmodel:GenModel xmi:version=3D"2.0"</P>
<P align=3Dleft>xmlns:xmi=3D"http://www.omg.org/XMI"=20
xmlns:ecore=3D"http://www.eclipse.org/emf/2002/Ecore"</P>
<P =
align=3Dleft>xmlns:genmodel=3D"http://www.eclipse.org/emf/2002/GenModel" =
modelDirectory=3D"/Test/src"</P>
<P align=3Dleft>modelPluginID=3D"Test" modelName=3D"My"=20
importerID=3D"org.eclipse.emf.importer.ecore"></P>
<P align=3Dleft> <foreignModel>My.ecore</foreignModel&am p;gt; </P>
<P align=3Dleft><genPackages prefix=3D"Pack" =
disposableProviderFactory=3D"true"=20
ecorePackage=3D"My.ecore#/"></P>
<P align=3Dleft><genClasses ecoreClass=3D"My.ecore#//class1"></P>
<P align=3Dleft><genFeatures property=3D"Readonly" =
createChild=3D"true"=20
ecoreFeature=3D"ecore:EReference My.ecore#//class1/class2"/></P>
<P align=3Dleft></genClasses></P>
<P align=3Dleft><genClasses ecoreClass=3D"My.ecore#//class2"/></P>
<P align=3Dleft></genPackages></P>
<P align=3Dleft></genmodel:GenModel></P>
<P align=3Dleft><FONT face=3DArial></FONT> </P>
<P align=3Dleft><FONT face=3DArial>Note that the containment =
references to=20
Class2 in Class1 are not 'children'. </FONT><FONT face=3DArial>I create =
all the=20
default stuff, including an editor, and with this editor I create an =
instance=20
file which looks like this</FONT></P>
<P align=3Dleft><FONT face=3DArial></FONT> </P><FONT size=3D2>
<P align=3Dleft><?xml version=3D"1.0" encoding=3D"UTF-8"?></P>
<P align=3Dleft><null:class1 xmi:version=3D"2.0"=20
xmlns:xmi=3D"http://www.omg.org/XMI" xmlns:null=3D"null"></P>
<P align=3Dleft><class2/></P>
<P align=3Dleft><class2/></P>
<P align=3Dleft></null:class1></P>
<P align=3Dleft><FONT face=3DArial></FONT> </P>
<P align=3Dleft><FONT face=3DArial>Class1 has two containment references =
to=20
instances of Class2. Then for quick testing, I patch the generated =
editor a bit=20
like this:</FONT></P>
<P align=3Dleft><FONT face=3DArial> public void createModel()=20
{<BR> // I assume that the input is a file=20
object.<BR> //<BR> IFileEditorInput modelFile =3D=20
(IFileEditorInput) getEditorInput();<BR> <BR> try=20
{<BR> // Load the resource through the editing=20
domain.<BR> //<BR> Resource resource =
=3D=20
editingDomain.loadResource(URI.createPlatformResourceURI(<BR > =
modelFile.getFile().getFullPat h().toString()).toString(=
));<BR> <BR> class1=20
class1 =3D (class1) =
resource.getContents().get(0);<BR> class2=20
class2 =3D (class2) =
class1.getClass2().get(0);<BR> Command cmd =3D=20
DeleteCommand.create(editingDomain,class2);<BR> editingD=
omain.getCommandStack().execute(cmd);<BR> }=20
catch (Exception exception)=20
{<BR> MyEditorPlugin.INSTANCE.log(ex ception); <BR> &=
nbsp;}<BR> }<BR></FONT></P>
<P align=3Dleft><FONT face=3DArial>I create a DeleteCommand to delete =
the first=20
reference to Class2 in Class1. When I reopen the instance file created =
earlier,=20
the DeleteCommand is run. To my suprise, the instance file has not =
changed. Or=20
am I overlooking something?</FONT></P>
<P align=3Dleft><FONT face=3DArial></FONT> </P>
<P align=3Dleft><FONT face=3DArial>Koen</FONT></P>
<P align=3Dleft><FONT face=3DArial></FONT> </P>
<P align=3Dleft><FONT face=3DArial> </P></FONT>
<P align=3Dleft><FONT face=3DArial></FONT> </P>
<P align=3Dleft><FONT =
face=3DArial></FONT> </P></FONT></FONT></FONT ></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" <<A =
href=3D"mailto:merks@ca.ibm.com">merks@ca.ibm.com</A>>=20
wrote in message <A=20
=
href=3D"news:dsq7te$5rg$1@utils.eclipse.org">news:dsq7te$5rg$1@utils.ecli=
pse.org</A>...</DIV>Koen,<BR><BR>The=20
expectation is that object being deleted is contained somewhere in the =
tree. Is that not the case in your =
scenario?<BR><BR><BR>Koen van=20
Dijken wrote:=20
<BLOCKQUOTE cite=3Dmiddsq5s2$1mb$1@utils.eclipse.org type=3D"cite">
<META content=3D"MSHTML 6.00.2900.2802" name=3DGENERATOR>
<STYLE></STYLE>
<DIV><FONT face=3DArial size=3D2>Yes, that's what I think it is =
supposed to do,=20
but it turns out that for containment references it only removes =
them if=20
they are 'children'. This is caused by the call to=20
=
org.eclipse.emf.edit.provider.ItemProviderAdapter.getAnyChil drenFeatures(=
)=20
as is visible in this stack trace:</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial=20
=
size=3D2> AllDataProviderItemProvider(ItemProviderAdapter).factorRemov eCom=
mand(EditingDomain,=20
CommandParameter) line:=20
=
1052<BR> AllDataProviderItemProvider(ItemProviderAdapter).createComma nd(Ob=
ject,=20
EditingDomain, Class, CommandParameter) line:=20
787<BR>AdapterFactoryEditingDomain.createCommand(Class, =
CommandParameter)=20
line: 396<BR>AdapterFactoryEditingDomain.createCommand(Class,=20
CommandParameter) line: 450<BR>RemoveCommand.create(EditingDomain, =
Object,=20
Object, Collection) line: 98<BR>RemoveCommand.create(EditingDomain,=20
Collection) line: 90<BR>DeleteCommand.prepare() line:=20
97<BR>DeleteCommand(AbstractCommand).canExecute() line:=20
113<BR>CompoundCommand.appendAndExecute(Command) line:=20
649<BR>SpatialImpl$3.doExecute() line:=20
1388<BR>SpatialImpl$3(AbstractOverrideableCommand).execute() line:=20
128<BR>CompoundCommand.appendAndExecute(Command) line:=20
653<BR>SpatialImpl$1.doExecute() line:=20
1192<BR>SpatialImpl$1(AbstractOverrideableCommand).execute() line:=20
128<BR>BasicCommandStack.execute(Command) line:=20
91<BR>SpatialImpl.removeDataProviderUndoable(IDataProvider, boolean) =
line:=20
1329<BR>RemoveDataproviderAction.run() line: 36<BR></FONT></DIV>
<DIV><FONT face=3DArial size=3D2>If in the object from which the =
reference=20
should be deleted there are no references which are 'children' ,=20
getAnyChildrenFeatures will return an empty list, and=20
factorRemoveCommand will return=20
UnexecutableCommand.INSTANCE.</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>Koen</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<BLOCKQUOTE=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: rgb(0,0,0) 2px solid; MARGIN-RIGHT: 0px">
<DIV>"Ed Merks" <<A=20
href=3D"mailto:merks@ca.ibm.com">merks@ca.ibm.com</A>> wrote in =
message=20
<A=20
=
href=3D"news:dsq4kd$u6t$2@utils.eclipse.org">news:dsq4kd$u6t$2@utils.ecli=
pse.org</A>...</DIV>Koen,<BR><BR>I'm=20
not sure what you are referring to. The DeleteCommand just =
removes=20
all references:<BR>
<BLOCKQUOTE><SMALL> public void =
execute()</SMALL><BR><SMALL> =20
{</SMALL><BR><SMALL> =20
super.execute();</SMALL><BR><BR><SMALL> Map =
usages =3D=20
EcoreUtil.UsageCrossReferencer.findAll(collection,=20
domain.getResourceSet());</SMALL><BR><SMALL> =
for=20
(Iterator i =3D usages.entrySet().iterator(); i.hasNext();=20
)</SMALL><BR><SMALL> =20
{</SMALL><BR><SMALL> Map.Entry =
entry =3D=20
=
(Map.Entry)i.next();</SMALL><BR><SMALL> =20
EObject eObject =3D=20
=
(EObject)entry.getKey();</SMALL><BR><SMALL> =
=20
Collection settings =3D=20
=
(Collection)entry.getValue();</SMALL><BR><SMALL> &=
nbsp;=20
for (Iterator j =3D settings.iterator(); j.hasNext();=20
)</SMALL><BR><SMALL> =20
{</SMALL><BR><SMALL> =20
EStructuralFeature.Setting setting =3D=20
=
(EStructuralFeature.Setting)j.next();</SMALL><BR><SMALL>  =
; =20
EObject referencingEObject =3D=20
=
setting.getEObject();</SMALL><BR><SMALL> &nb=
sp; =20
EStructuralFeature eStructuralFeature =3D=20
=
setting.getEStructuralFeature();</SMALL><BR><SMALL> &nbs=
p; =20
if=20
=
(eStructuralFeature.isMany())</SMALL><BR><SMALL> &=
nbsp; =20
=
{</SMALL><BR><SMALL>  =
;=20
appendAndExecute(RemoveCommand.create(domain, =
referencingEObject,=20
eStructuralFeature,=20
=
eObject));</SMALL><BR><SMALL> =20
}</SMALL><BR><SMALL> =20
=
else</SMALL><BR><SMALL> =20
=
{</SMALL><BR><SMALL>  =
;=20
appendAndExecute(SetCommand.create(domain, referencingEObject,=20
eStructuralFeature,=20
=
null));</SMALL><BR><SMALL> =20
}</SMALL><BR><SMALL> =20
}</SMALL><BR><SMALL> =
}</SMALL><BR><SMALL> =20
}</SMALL><BR></BLOCKQUOTE><BR>Koen van Dijken wrote:=20
<BLOCKQUOTE cite=3Dmiddsmsb8$s0o$1@utils.eclipse.org =
type=3D"cite"><PRE wrap=3D"">I noticed that =
org.eclipse.emf.edit.command.DeleteCommand only removes=20
objects from their parent container if these references (in the parent=20
container) are marked as 'children' in the genmodel. Containment =
references=20
which are not 'children' are not removed by DeleteCommand. Is this by =
design=20
or is it a bug?
Koen
=
</PRE></BLOCKQUOTE><BR></BLOCKQUOTE></BLOCKQUOTE><BR></BLOCKQUOTE ></BODY>=
</HTML>
------=_NextPart_000_000C_01C630BC.D2B0E0F0--
|
|
|
| Re: DeleteCommand, children [message #398507 is a reply to message #398493] |
Mon, 13 February 2006 13:37   |
Eclipse User |
|
|
|
This is a multi-part message in MIME format.
--------------020705010104050404040901
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Koen,
I've asked Dave to look at this and respond. (This certainly isn't a
scenario we are expecting.)
Koen van Dijken wrote:
> I created a testcase. I have this ecore model and genmodel
>
>
> <?xml version="1.0" encoding="UTF-8"?>
>
> <ecore:EPackage xmi:version="2.0"
>
> xmlns:xmi="http://www.omg.org/XMI"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>
> xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="pack">
>
> <eClassifiers xsi:type="ecore:EClass" name="class1">
>
> <eStructuralFeatures xsi:type="ecore:EReference" name="class2"
> upperBound="-1"
>
> eType="#//class2" containment="true"/>
>
> </eClassifiers>
>
> <eClassifiers xsi:type="ecore:EClass" name="class2"/>
>
> </ecore:EPackage>
>
>
>
> <?xml version="1.0" encoding="UTF-8"?>
>
> <genmodel:GenModel xmi:version="2.0"
>
> xmlns:xmi="http://www.omg.org/XMI"
> xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore"
>
> xmlns:genmodel="http://www.eclipse.org/emf/2002/GenModel"
> modelDirectory="/Test/src"
>
> modelPluginID="Test" modelName="My"
> importerID="org.eclipse.emf.importer.ecore">
>
> <foreignModel>My.ecore</foreignModel>
>
> <genPackages prefix="Pack" disposableProviderFactory="true"
> ecorePackage="My.ecore#/">
>
> <genClasses ecoreClass="My.ecore#//class1">
>
> <genFeatures property="Readonly" createChild="true"
> ecoreFeature="ecore:EReference My.ecore#//class1/class2"/>
>
> </genClasses>
>
> <genClasses ecoreClass="My.ecore#//class2"/>
>
> </genPackages>
>
> </genmodel:GenModel>
>
>
>
> Note that the containment references to Class2 in Class1 are not
> 'children'. I create all the default stuff, including an editor, and
> with this editor I create an instance file which looks like this
>
>
>
> <?xml version="1.0" encoding="UTF-8"?>
>
> <null:class1 xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"
> xmlns:null="null">
>
> <class2/>
>
> <class2/>
>
> </null:class1>
>
>
>
> Class1 has two containment references to instances of Class2. Then for
> quick testing, I patch the generated editor a bit like this:
>
> public void createModel() {
> // I assume that the input is a file object.
> //
> IFileEditorInput modelFile = (IFileEditorInput) getEditorInput();
>
> try {
> // Load the resource through the editing domain.
> //
> Resource resource =
> editingDomain.loadResource(URI.createPlatformResourceURI(
> modelFile.getFile().getFullPath().toString()).toString());
>
> class1 class1 = (class1) resource.getContents().get(0);
> class2 class2 = (class2) class1.getClass2().get(0);
> Command cmd = DeleteCommand.create(editingDomain,class2);
> editingDomain.getCommandStack().execute(cmd);
> } catch (Exception exception) {
> MyEditorPlugin.INSTANCE.log(exception);
> }
> }
>
> I create a DeleteCommand to delete the first reference to Class2 in
> Class1. When I reopen the instance file created earlier, the
> DeleteCommand is run. To my suprise, the instance file has not
> changed. Or am I overlooking something?
>
>
>
> Koen
>
>
>
>
>
>
>
>
>
> "Ed Merks" <merks@ca.ibm.com <mailto:merks@ca.ibm.com>> wrote in
> message news:dsq7te$5rg$1@utils.eclipse.org...
> Koen,
>
> The expectation is that object being deleted is contained
> somewhere in the tree. Is that not the case in your scenario?
>
>
> Koen van Dijken wrote:
>
>> Yes, that's what I think it is supposed to do, but it turns out
>> that for containment references it only removes them if they are
>> 'children'. This is caused by the call to
>> org.eclipse.emf.edit.provider.ItemProviderAdapter.getAnyChil drenFeatures()
>> as is visible in this stack trace:
>>
>> AllDataProviderItemProvider(ItemProviderAdapter).factorRemov eCommand(EditingDomain,
>> CommandParameter) line: 1052
>> AllDataProviderItemProvider(ItemProviderAdapter).createComma nd(Object,
>> EditingDomain, Class, CommandParameter) line: 787
>> AdapterFactoryEditingDomain.createCommand(Class,
>> CommandParameter) line: 396
>> AdapterFactoryEditingDomain.createCommand(Class,
>> CommandParameter) line: 450
>> RemoveCommand.create(EditingDomain, Object, Object, Collection)
>> line: 98
>> RemoveCommand.create(EditingDomain, Collection) line: 90
>> DeleteCommand.prepare() line: 97
>> DeleteCommand(AbstractCommand).canExecute() line: 113
>> CompoundCommand.appendAndExecute(Command) line: 649
>> SpatialImpl$3.doExecute() line: 1388
>> SpatialImpl$3(AbstractOverrideableCommand).execute() line: 128
>> CompoundCommand.appendAndExecute(Command) line: 653
>> SpatialImpl$1.doExecute() line: 1192
>> SpatialImpl$1(AbstractOverrideableCommand).execute() line: 128
>> BasicCommandStack.execute(Command) line: 91
>> SpatialImpl.removeDataProviderUndoable(IDataProvider, boolean)
>> line: 1329
>> RemoveDataproviderAction.run() line: 36
>> If in the object from which the reference should be deleted there
>> are no references which are 'children' , getAnyChildrenFeatures
>> will return an empty list, and factorRemoveCommand will return
>> UnexecutableCommand.INSTANCE.
>>
>> Koen
>>
>>
>>
>> "Ed Merks" <merks@ca.ibm.com <mailto:merks@ca.ibm.com>> wrote
>> in message news:dsq4kd$u6t$2@utils.eclipse.org...
>> Koen,
>>
>> I'm not sure what you are referring to. The DeleteCommand
>> just removes all references:
>>
>> public void execute()
>> {
>> super.execute();
>>
>> Map usages =
>> EcoreUtil.UsageCrossReferencer.findAll(collection,
>> domain.getResourceSet());
>> for (Iterator i = usages.entrySet().iterator();
>> i.hasNext(); )
>> {
>> Map.Entry entry = (Map.Entry)i.next();
>> EObject eObject = (EObject)entry.getKey();
>> Collection settings = (Collection)entry.getValue();
>> for (Iterator j = settings.iterator(); j.hasNext(); )
>> {
>> EStructuralFeature.Setting setting =
>> (EStructuralFeature.Setting)j.next();
>> EObject referencingEObject = setting.getEObject();
>> EStructuralFeature eStructuralFeature =
>> setting.getEStructuralFeature();
>> if (eStructuralFeature.isMany())
>> {
>> appendAndExecute(RemoveCommand.create(domain,
>> referencingEObject, eStructuralFeature, eObject));
>> }
>> else
>> {
>> appendAndExecute(SetCommand.create(domain,
>> referencingEObject, eStructuralFeature, null));
>> }
>> }
>> }
>> }
>>
>>
>> Koen van Dijken wrote:
>>
>>>I noticed that org.eclipse.emf.edit.command.DeleteCommand only removes
>>>objects from their parent container if these references (in the parent
>>>container) are marked as 'children' in the genmodel. Containment references
>>>which are not 'children' are not removed by DeleteCommand. Is this by design
>>>or is it a bug?
>>>
>>>Koen
>>>
>>>
>>>
>>>
>>>
>>>
>>
>
--------------020705010104050404040901
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">
Koen,<br>
<br>
I've asked Dave to look at this and respond. (This certainly isn't a
scenario we are expecting.)<br>
<br>
<br>
Koen van Dijken wrote:
<blockquote cite="middsq9hq$aui$1@utils.eclipse.org" type="cite">
<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1">
<meta content="MSHTML 6.00.2900.2802" name="GENERATOR">
<div><font face="Arial" size="2">I created a testcase. I have this
ecore model and genmodel</font></div>
<div> </div>
<div><font size="2">
</font>
<p align="left"><font size="2"><?xml version="1.0"
encoding="UTF-8"?></font></p>
<p align="left"><font size="2"><ecore:EPackage xmi:version="2.0"</font></p>
<p align="left"><font size="2">xmlns:xmi=<a class="moz-txt-link-rfc2396E" href="http://www.omg.org/XMI">"http://www.omg.org/XMI"</a>
xmlns:xsi=<a class="moz-txt-link-rfc2396E" href="http://www.w3.org/2001/XMLSchema-instance">"http://www.w3.org/2001/XMLSchema-instance"</a></font></p>
<p align="left"><font size="2">xmlns:ecore=<a class="moz-txt-link-rfc2396E" href="http://www.eclipse.org/emf/2002/Ecore">"http://www.eclipse.org/emf/2002/Ecore"</a>
name="pack"></font></p>
<p align="left"><font size="2"><eClassifiers
xsi:type="ecore:EClass" name="class1"></font></p>
<p align="left"><font size="2"><eStructuralFeatures
xsi:type="ecore:EReference" name="class2" upperBound="-1"</font></p>
<p align="left"><font size="2">eType="#//class2"
containment="true"/></font></p>
<p align="left"><font size="2"></eClassifiers></font></p>
<p align="left"><font size="2"><eClassifiers
xsi:type="ecore:EClass" name="class2"/></font></p>
<p align="left"><font size="2"></ecore:EPackage></font></p>
<p align="left"><font size="2"> </font></p>
<font size="2"><font size="2"></font></font>
<p align="left"><font size="2"><font size="2"><?xml version="1.0"
encoding="UTF-8"?></font></font></p>
<p align="left"><font size="2"><font size="2"><genmodel:GenModel
xmi:version="2.0"</font></font></p>
<p align="left"><font size="2"><font size="2">xmlns:xmi=<a class="moz-txt-link-rfc2396E" href="http://www.omg.org/XMI">"http://www.omg.org/XMI"</a>
xmlns:ecore=<a class="moz-txt-link-rfc2396E" href="http://www.eclipse.org/emf/2002/Ecore">"http://www.eclipse.org/emf/2002/Ecore"</a></font></font></p>
<p align="left"><font size="2"><font size="2">xmlns:genmodel=<a class="moz-txt-link-rfc2396E" href="http://www.eclipse.org/emf/2002/GenModel">"http://www.eclipse.org/emf/2002/GenModel"</a>
modelDirectory="/Test/src"</font></font></p>
<p align="left"><font size="2"><font size="2">modelPluginID="Test"
modelName="My" importerID="org.eclipse.emf.importer.ecore"></font ></font></p>
<p align="left"><font size="2"><font size="2"> <foreignModel>My.ecore</foreignModel&am p;gt; </font></font></p>
<p align="left"><font size="2"><font size="2"><genPackages
prefix="Pack" disposableProviderFactory="true"
ecorePackage="My.ecore#/"></font></font></p>
<p align="left"><font size="2"><font size="2"><genClasses
ecoreClass="My.ecore#//class1"></font></font></p >
<p align="left"><font size="2"><font size="2"><genFeatures
property="Readonly" createChild="true" ecoreFeature="ecore:EReference
My.ecore#//class1/class2"/></font></font></p>
<p align="left"><font size="2"><font size="2"></genClasses></font></font></p>
<p align="left"><font size="2"><font size="2"><genClasses
ecoreClass="My.ecore#//class2"/></font></font></p >
<p align="left"><font size="2"><font size="2"></genPackages></font></font></p>
<p align="left"><font size="2"><font size="2"></genmodel:GenModel></font></font ></p>
<p align="left"><font size="2"><font size="2"> </font></font></p>
<p align="left"><font size="2"><font size="2"><font face="Arial">Note
that the containment references to Class2 in Class1 are not 'children'.
</font><font face="Arial">I create all the default stuff, including
an editor, and with this editor I create an instance file which looks
like this</font></font></font></p>
<p align="left"><font size="2"><font size="2"> </font></font></p>
<font size="2"><font size="2"><font size="2"></font></font></font>
<p align="left"><font size="2"><font size="2"><font size="2"><?xml
version="1.0" encoding="UTF-8"?></font></font></font></p>
<p align="left"><font size="2"><font size="2"><font size="2"><null:class1
xmi:version="2.0" xmlns:xmi=<a class="moz-txt-link-rfc2396E" href="http://www.omg.org/XMI">"http://www.omg.org/XMI"</a>
xmlns:null="null"></font></font></font></p>
<p align="left"><font size="2"><font size="2"><font size="2"><class2/></font></font></font></p >
<p align="left"><font size="2"><font size="2"><font size="2"><class2/></font></font></font></p >
<p align="left"><font size="2"><font size="2"><font size="2"></null:class1></font></font></font ></p>
<p align="left"><font size="2"><font size="2"><font size="2"> </font></font></font></p>
<p align="left"><font size="2"><font size="2"><font size="2"><font
face="Arial">Class1 has two containment references to instances of
Class2. Then for quick testing, I patch the generated editor a bit like
this:</font></font></font></font></p>
<p align="left"><font size="2"><font size="2"><font size="2"><font
face="Arial"> public void createModel() {<br>
// I assume that the input is a file object.<br>
//<br>
IFileEditorInput modelFile = (IFileEditorInput) getEditorInput();<br>
<br>
try {<br>
// Load the resource through the editing domain.<br>
//<br>
Resource resource =
editingDomain.loadResource(URI.createPlatformResourceURI(<br >
modelFile. getFile().getFullPath().toString()).toString()); <br>
<br>
class1 class1 = (class1) resource.getContents().get(0);<br>
class2 class2 = (class2) class1.getClass2().get(0);<br>
Command cmd = DeleteCommand.create(editingDomain,class2);<br>
editingDomain.getCommandStack( ).execute(cmd); <br>
} catch (Exception exception) {<br>
MyEditorPlugin.INSTANCE.log(ex ception); <br>
}<br>
}<br>
</font></font></font></font></p>
<p align="left"><font size="2"><font size="2"><font size="2"><font
face="Arial">I create a DeleteCommand to delete the first reference to
Class2 in Class1. When I reopen the instance file created earlier, the
DeleteCommand is run. To my suprise, the instance file has not changed.
Or am I overlooking something?</font></font></font></font></p>
<p align="left"><font size="2"><font size="2"><font size="2"> </font></font></font></p>
<p align="left"><font size="2"><font size="2"><font size="2"><font
face="Arial">Koen</font></font></font></font></p>
<p align="left"><font size="2"><font size="2"><font size="2"> </font></font></font></p>
<p align="left"><font size="2"><font size="2"><font size="2"><font
face="Arial"> </font></font></font></font></p >
<p align="left"><font size="2"><font size="2"><font size="2"> </font></font></font></p>
<p align="left"><font size="2"><font size="2"><font size="2"> </font></font></font></p>
</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" <<a href="mailto:merks@ca.ibm.com">merks@ca.ibm.com</a>>
wrote in message <a href="news:dsq7te$5rg$1@utils.eclipse.org">news:dsq7te$5rg$1@utils.eclipse.org</a>...</div>
Koen,<br>
<br>
The expectation is that object being deleted is contained somewhere in
the tree. Is that not the case in your scenario?<br>
<br>
<br>
Koen van Dijken wrote:
<blockquote cite="middsq5s2$1mb$1@utils.eclipse.org" type="cite">
<meta content="MSHTML 6.00.2900.2802" name="GENERATOR">
<style></style>
<div><font face="Arial" size="2">Yes, that's what I think it is
supposed to do, but it turns out that for containment references it
only removes them if they are 'children'. This is caused by the call to
org.eclipse.emf.edit.provider.ItemProviderAdapter.getAnyChil drenFeatures()
as is visible in this stack trace:</font></div>
<div> </div>
<div><font face="Arial" size="2"> AllDataProviderItemProvider(ItemProviderAdapter).factorRemov eCommand(EditingDomain,
CommandParameter) line: 1052<br>
AllDataProviderItemProvider(ItemProviderAdapter).createComma nd(Object,
EditingDomain, Class, CommandParameter) line: 787<br>
AdapterFactoryEditingDomain.createCommand(Class, CommandParameter)
line: 396<br>
AdapterFactoryEditingDomain.createCommand(Class, CommandParameter)
line: 450<br>
RemoveCommand.create(EditingDomain, Object, Object, Collection) line: 98<br>
RemoveCommand.create(EditingDomain, Collection) line: 90<br>
DeleteCommand.prepare() line: 97<br>
DeleteCommand(AbstractCommand).canExecute() line: 113<br>
CompoundCommand.appendAndExecute(Command) line: 649<br>
SpatialImpl$3.doExecute() line: 1388<br>
SpatialImpl$3(AbstractOverrideableCommand).execute() line: 128<br>
CompoundCommand.appendAndExecute(Command) line: 653<br>
SpatialImpl$1.doExecute() line: 1192<br>
SpatialImpl$1(AbstractOverrideableCommand).execute() line: 128<br>
BasicCommandStack.execute(Command) line: 91<br>
SpatialImpl.removeDataProviderUndoable(IDataProvider, boolean) line:
1329<br>
RemoveDataproviderAction.run() line: 36<br>
</font></div>
<div><font face="Arial" size="2">If in the object from which the
reference should be deleted there are no references which are
'children' , getAnyChildrenFeatures will return an empty list, and
factorRemoveCommand will return UnexecutableCommand.INSTANCE.</font></div>
<div> </div>
<div><font face="Arial" size="2">Koen</font></div>
<div> </div>
<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" <<a href="mailto:merks@ca.ibm.com">merks@ca.ibm.com</a>>
wrote in message <a href="news:dsq4kd$u6t$2@utils.eclipse.org">news:dsq4kd$u6t$2@utils.eclipse.org</a>...</div>
Koen,<br>
<br>
I'm not sure what you are referring to. The DeleteCommand just removes
all references:<br>
<blockquote><small> public void execute()</small><br>
<small> {</small><br>
<small> super.execute();</small><br>
<br>
<small> Map usages =
EcoreUtil.UsageCrossReferencer.findAll(collection,
domain.getResourceSet());</small><br>
<small> for (Iterator i = usages.entrySet().iterator();
i.hasNext(); )</small><br>
<small> {</small><br>
<small> Map.Entry entry = (Map.Entry)i.next();</small><br>
<small> EObject eObject = (EObject)entry.getKey();</small><br>
<small> Collection settings =
(Collection)entry.getValue();</small><br>
<small> for (Iterator j = settings.iterator();
j.hasNext(); )</small><br>
<small> {</small><br>
<small> EStructuralFeature.Setting setting =
(EStructuralFeature.Setting)j.next();</small><br>
<small> EObject referencingEObject =
setting.getEObject();</small><br>
<small> EStructuralFeature eStructuralFeature =
setting.getEStructuralFeature();</small><br>
<small> if (eStructuralFeature.isMany())</small><br>
<small> {</small><br>
<small>
appendAndExecute(RemoveCommand.create(domain, referencingEObject,
eStructuralFeature, eObject));</small><br>
<small> }</small><br>
<small> else</small><br>
<small> {</small><br>
<small> appendAndExecute(SetCommand.create(domain,
referencingEObject, eStructuralFeature, null));</small><br>
<small> }</small><br>
<small> }</small><br>
<small> }</small><br>
<small> }</small><br>
</blockquote>
<br>
Koen van Dijken wrote:
<blockquote cite="middsmsb8$s0o$1@utils.eclipse.org" type="cite">
<pre wrap="">I noticed that org.eclipse.emf.edit.command.DeleteCommand only removes
objects from their parent container if these references (in the parent
container) are marked as 'children' in the genmodel. Containment references
which are not 'children' are not removed by DeleteCommand. Is this by design
or is it a bug?
Koen
</pre>
</blockquote>
<br>
</blockquote>
</blockquote>
<br>
</blockquote>
</blockquote>
<br>
</body>
</html>
--------------020705010104050404040901--
|
|
|
| Re: DeleteCommand, children [message #398543 is a reply to message #398493] |
Tue, 14 February 2006 13:26  |
Eclipse User |
|
|
|
Koen van Dijken wrote:
> I create a DeleteCommand to delete the first reference to Class2 in
> Class1. When I reopen the instance file created earlier, the
> DeleteCommand is run. To my suprise, the instance file has not changed.
> Or am I overlooking something?
Hi Koen,
I tried out your test case, and I do believe that DeleteCommand is
working as designed, that is:
"This uses one or more RemoveCommands to remove an object from its
parent container and to delete all other references to it from within
the editing domain."
When RemoveCommand is used to remove an object from its parent (this is
the case where no EStructuralFeature is specified) it only considers
features of the parent for which GenFeature.isChildren() is true. If
there is no such feature, then it has no children and so removing a
child makes no sense. Hence, the UnexecutableCommand.
It really is expected that item providers will agree on the child-parent
relationships, i.e. if object A's item provider says object B is its
parent, then B's item provider should say that A is one of its children.
Even without trying to use the DeleteCommand, I saw some weird behaviour
in your test case: when I created the child of class1, class2 was
selected by the command, but since it wassn't showing in the tree, the
selection just went away. I don't really see how having isCreateChild()
true for a feature with isChildren() false makes sense.
DeleteCommand most intentionally removes the object from its parent
using this form of RemoveCommand, and uses it to determine the whole
command's executability. I can see that it might be useful to have a
remove-from-anything kind of command, to use outside of this context,
but I don't think it's something we could change now.
Cheers,
Dave
|
|
|
Goto Forum:
Current Time: Wed Nov 05 08:38:15 EST 2025
Powered by FUDForum. Page generated in 0.03513 seconds
|