Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Sirius » delete element recursively
delete element recursively [message #1728215] Fri, 01 April 2016 00:03 Go to next message
Frank Sorek is currently offline Frank SorekFriend
Messages: 22
Registered: February 2016
Junior Member
Hello,

I work with Containers and need a custom delete element Feature.

In my model a container can have unlimited children and these children can also have unlimited children and so on.

The Relation between a container and its child is described with a containment-element which has the features: "contained Node"(parent) and "containing Node"(child).

If I delete a parent (without delete element feature), the relating containment-element is not deleted.

So I need the custom delete Element Tool.

But here is the problem. If I want to delete a container, which contains other containers (which contains other containers and so on) I have to do it recursively... Therefore I want to use this implemented algorithm:

public void deleteContainer(EObject container){
     if(container instanceof ExampleImpl){
		ExampleImpl example = (ExampleImpl) container;	
		if(!example.getChildren().isEmpty()){
			for(Containment containment : example.getChildren()){
				deleteContainer(containment.getContainedNode());
			}               
			// Delete Containment and Container
		}	
	}
}


Where the comment stands, I could use the method: example.eBasicRemoveFromContainer(null), but if I do so, the deletion of a containment can not be undone.

Is there another method to delete an element, with which the deletion can be undone like the Remove-feature I can use in the odesign ?

Another way would be to use the Remove-feature, but I didn't find a way to do the recursion.

For Example I can do Change Context var:element, then If aql:self.children->notEmpty(), then For (expression: aql:self.children) child. But there is no way to put the child (or the contained node) back to the Change Context and the If - Feature. Or am I wrong?

I really hope my problem is understandable

Regards
Re: delete element recursively [message #1728651 is a reply to message #1728215] Wed, 06 April 2016 09:15 Go to previous messageGo to next message
Florian Barbin is currently offline Florian BarbinFriend
Messages: 270
Registered: August 2010
Senior Member
Hello,

From what I understand, you want to delete an element and all its
contained children in your EMF model?

In that case there is no need to delete recursively all its
sub-elements. Deleting an EObject means detaching it from its parent and
removing it from all the feature referencing it (see
org.eclipse.emf.ecore.util.EcoreUtil.delete(EObject)).

If the sub-elements are displayed out of the parent container in the
diagram, they should also be deleted from the diagram automatically.

Regards,


--
Florian - Obeo

Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Re: delete element recursively [message #1728652 is a reply to message #1728651] Wed, 06 April 2016 09:26 Go to previous messageGo to next message
Florian Barbin is currently offline Florian BarbinFriend
Messages: 270
Registered: August 2010
Senior Member
Maybe you have references toward those sub-elements. In that case
calling org.eclipse.emf.ecore.util.EcoreUtil.delete(EObject eObject,
boolean recursive) with recursive true will also remove sub-elements
from features referencing them.

On 04/06/2016 11:15 AM, Florian Barbin wrote:
> Hello,
>
> From what I understand, you want to delete an element and all its
> contained children in your EMF model?
>
> In that case there is no need to delete recursively all its
> sub-elements. Deleting an EObject means detaching it from its parent and
> removing it from all the feature referencing it (see
> org.eclipse.emf.ecore.util.EcoreUtil.delete(EObject)).
>
> If the sub-elements are displayed out of the parent container in the
> diagram, they should also be deleted from the diagram automatically.
>
> Regards,
>
>


--
Florian - Obeo

Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Re: delete element recursively [message #1729240 is a reply to message #1728652] Tue, 12 April 2016 11:02 Go to previous messageGo to next message
Frank Sorek is currently offline Frank SorekFriend
Messages: 22
Registered: February 2016
Junior Member
Florian Barbin wrote on Wed, 06 April 2016 09:26
Maybe you have references toward those sub-elements. In that case
calling org.eclipse.emf.ecore.util.EcoreUtil.delete(EObject eObject,
boolean recursive) with recursive true will also remove sub-elements
from features referencing them.

On 04/06/2016 11:15 AM, Florian Barbin wrote:
> Hello,
>
> From what I understand, you want to delete an element and all its
> contained children in your EMF model?
>
> In that case there is no need to delete recursively all its
> sub-elements. Deleting an EObject means detaching it from its parent and
> removing it from all the feature referencing it (see
> org.eclipse.emf.ecore.util.EcoreUtil.delete(EObject)).
>
> If the sub-elements are displayed out of the parent container in the
> diagram, they should also be deleted from the diagram automatically.
>
> Regards,
>
>


--
Florian - Obeo

Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius


It doesn't work as it should.
The selected element is deleted from model and representation, but the contained elements are only removed in the representation and not in the model. The elements referencing to the selected element are not touched and stay in both, model and representation.

To explain it again. The Container-Elements are not diretly connected to each other.
The Container-elements have 2 features : children and containers.
The Containment-elements have 2 features: Contained Node and Containing Node.

For Example:
- 2 Container: father, son
- 1 Containment: parent
- Container father contains Container son
Container father.children : Containment parent
Container father.containers : -
Container son.children : -
Container son.containers: Containment parent
Containment parent.contained_node : Container son
Containment parent.containing_node : Container father

If I delete the Container father with org.eclipse.emf.ecore.util.EcoreUtil.delete(EObject eObject,
boolean recursive) (recursive = true), the Container father is deleted from model and representation, Container son is deleted from representation. Containment parent is not deleted, only Container son is removed from the feature Containing Node.
Re: delete element recursively [message #1730510 is a reply to message #1729240] Tue, 26 April 2016 13:06 Go to previous messageGo to next message
Maxime Porhel is currently offline Maxime PorhelFriend
Messages: 516
Registered: July 2009
Location: Nantes, France
Senior Member
Hi Frank,

Le 12/04/2016 13:02, Frank Sorek a écrit :
> It doesn't work as it should. The selected element is deleted from model
> and representation, but the contained elements are only removed in the
> representation and not in the model. The elements referencing to the
> selected element are not touched and stay in both, model and
> representation.
> To explain it again. The Container-Elements are not diretly connected to
> each other. The Container-elements have 2 features : children and
> containers. The Containment-elements have 2 features: Contained Node and
> Containing Node.

If those EReferences are not containment reference (check the
containment attribute in your ecore model) then there is no containment
between your EObjects and that explains your delete tool behavior and
why your children elements are not deleted.

If your model had real containment of EObject, removing the selected
EObject from its container would also remove its children from the model
as they will only be able to retrieve it by calling eContainer() but if
you call eResource() or a loop of eContainer(), it will return null.

Then for all detached object, Sirius use its inverse cross referencer
adapter to clean the model and delete all references pointing to those
detached object (as a precommit listener of the EMF transaction) to
avoid dangling references.

If you have no containment references between you parent element and
your children elements, then in your delete service, you have to
retrieve all children elements and to remove them from their container
or from the resource if they are roots of the resource.


> For Example: - 2 Container: father, son
> - 1 Containment: parent
> - Container father contains Container son
> Container father.children : Containment parent
> Container father.containers : -
> Container son.children : -
> Container son.containers: Containment parent
> Containment parent.contained_node : Container son
> Containment parent.containing_node : Container father




>
> If I delete the Container father with
> org.eclipse.emf.ecore.util.EcoreUtil.delete(EObject eObject, boolean
> recursive) (recursive = true), the Container father is deleted from
> model and representation, Container son is deleted from representation.
> Containment parent is not deleted, only Container son is removed from
> the feature Containing Node.

Regards

--
Maxime - Obeo

Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius


Maxime Porhel - Obeo

Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Re: delete element recursively [message #1730815 is a reply to message #1730510] Thu, 28 April 2016 16:37 Go to previous message
Frank Sorek is currently offline Frank SorekFriend
Messages: 22
Registered: February 2016
Junior Member
Thanks a lot for your response,

I managed to solve the problem with a java class. I collect with my own methods all elements to be deleted and delete them afterwards with org.eclipse.emf.ecore.util.EcoreUtil.delete(EObject))
Previous Topic:Export/Generate Doc from Documentation Fields in Specification
Next Topic:Example not working
Goto Forum:
  


Current Time: Thu Apr 25 19:59:04 GMT 2024

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

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

Back to the top