Skip to main content



      Home
Home » Eclipse Projects » GEF » How to correctly delete Part
How to correctly delete Part [message #1802900] Mon, 18 February 2019 12:41 Go to next message
Eclipse UserFriend
I'm iterating over a list of models and want to delete the corresponding ModelPart in some special cases.

2 questions about this:
1-How can I access the ModelPart within the Model? When I have the Part I can call part.getContent() to get the Model. Is there any similar method for getting the part from the model?


2-I found a way of getting the corresponding part by iterating over the Parent (root) part, which is a workaround in my opinion. However, even with the correct ModelPart I can't properly delete it. What am I doing wrong?

IRootPart<? extends Node> root = host.getRoot();
DeletionPolicy delPolicy = root.getAdapter(DeletionPolicy.class); 
init(delPolicy); //I'm inside a handler
						            
for (IVisualPart<? extends Node> a : new ArrayList<>(parent.getChildrenUnmodifiable())) {
			if (a instanceof ModelPart) {
											
				delPolicy.delete((IContentPart<? extends Node>) a);

			}
}

commit(delPolicy);

[Updated on: Mon, 18 February 2019 13:53] by Moderator

Re: How to correctly delete Part [message #1802907 is a reply to message #1802900] Mon, 18 February 2019 14:15 Go to previous messageGo to next message
Eclipse UserFriend
Hi Joao,

1) Each Viewer maintains a contentToPartMap where you can query the part that controls certain content.

2) Deletion logic depends on whether your ModelPart is parented at the root part or at another part:

https://github.com/eclipse/gef/blob/171559044bb8dcb7f88fd427f852efd39787978c/org.eclipse.gef.mvc.fx/src/org/eclipse/gef/mvc/fx/policies/DeletionPolicy.java#L134
		if (contentPartToDelete.getParent() instanceof IRootPart) {
			// remove content from viewer contents
			ChangeContentsOperation changeContentsOperation = new ChangeContentsOperation(
					viewer);
			List<Object> newContents = new ArrayList<>(viewer.getContents());
			newContents.remove(contentPartToDelete.getContent());
			changeContentsOperation.setNewContents(newContents);
			getRemoveContentChildrenOperation().add(changeContentsOperation);
		} else {
			// remove from content parent
			ContentPolicy parentContentPolicy = contentPartToDelete.getParent()
					.getAdapter(ContentPolicy.class);
			if (parentContentPolicy != null) {
				parentContentPolicy.init();
				parentContentPolicy
						.removeContentChild(contentPartToDelete.getContent());
				ITransactionalOperation removeFromParentOperation = parentContentPolicy
						.commit();
				if (removeFromParentOperation != null
						&& !removeFromParentOperation.isNoOp()) {
					getRemoveContentChildrenOperation()
							.add(removeFromParentOperation);
				}
			}
		}

If it is parented at the root part, then a ChangeContentsOperation should be created.

Otherwise, the parent part needs to have ContentPolicy bound as an adapter, and it needs to implement doRemoveContentChild() in order to collaborate with DeletionPolicy.

Any way, you should be able to find out what is going wrong by debugging DeletionPolicy.

Best of luck,
Matthias
Re: How to correctly delete Part [message #1802941 is a reply to message #1802907] Tue, 19 February 2019 06:18 Go to previous messageGo to next message
Eclipse UserFriend
Thanks for the answer Matthias!

Where exactly is that contentToPartMap function? I can't see any reference to it.

Regarding point 2, managed to solve it with your advice! Thanks ;)

[Updated on: Tue, 19 February 2019 12:30] by Moderator

Re: How to correctly delete Part [message #1802963 is a reply to message #1802941] Tue, 19 February 2019 13:09 Go to previous messageGo to next message
Eclipse UserFriend
Regarding point 1, for future reference I could do it like this:

Map<Object, IContentPart<? extends Node>> content = getHost().getViewer().getContentPartMap();
						            
	 ModelPart modelPart = (ModelPart) content.get(model);


Thank you very much Matthias!
Re: How to correctly delete Part [message #1803079 is a reply to message #1802963] Thu, 21 February 2019 16:34 Go to previous message
Eclipse UserFriend
You are welcome and faster than me :-)

[Updated on: Thu, 21 February 2019 16:35] by Moderator

Previous Topic:Question for Documentation
Next Topic:Create general handler for creating/deleting parts
Goto Forum:
  


Current Time: Wed Apr 23 02:20:02 EDT 2025

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

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

Back to the top