Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Papyrus » Need explanation about getBeforeDestroyElementCommand and getBeforeDestroyDependentsCommand
Need explanation about getBeforeDestroyElementCommand and getBeforeDestroyDependentsCommand [message #1833770] Fri, 23 October 2020 15:18 Go to next message
Yoann Farré is currently offline Yoann FarréFriend
Messages: 152
Registered: November 2017
Senior Member
Hello,

I'm trying to manage deletion events in a Papyrus model (using a custom profile). I defined *.elementtypesconfiguration file and EditHelperAdvice classes to custom the behavior of these new types during their lifecycles.

After some time using the EditHelperAdvice classes, I can't figure out the good practices to use getBefore/AfterDestroyElementCommand() and getBefore/afterDestoryDependentsCommand()

I just made a small test on a stereotyped interface owning two stereotyped operations. The EditHelperAdvice class for the interface contains :
	@Override
	protected ICommand getBeforeDestroyElementCommand(final DestroyElementRequest request) {
		EObject eObj = request.getElementToDestroy();
		System.out.println("Detroy Element : " + eObj);
		return super.getBeforeDestroyElementCommand(request);
	}

	@Override
	protected ICommand getBeforeDestroyDependentsCommand(final DestroyDependentsRequest request) {
		EObject eObj = request.getElementToDestroy();
		System.out.println("Detroy Dependents : " + eObj);
		return super.getBeforeDestroyDependentsCommand(request);
	}


The EditHelperAdvice for the Operation contains :

	@Override
	protected ICommand getBeforeDestroyDependentsCommand(final DestroyDependentsRequest request) {
		EObject eObj = request.getElementToDestroy();
		System.out.println("Destroy Operation : " + eObj);
		return super.getBeforeDestroyDependentsCommand(request);
	}


When I delete the interface I get :
Detroy Element : OperationImpl@29c12fe4 (name: Operation1, ...
Destroy Operation : OperationImpl@29c12fe4 (name: Operation1, ...
Detroy Element : OperationImpl@31c67262 (name: Operation2, ...
Destroy Operation : OperationImpl@31c67262 (name: Operation2, ...
Detroy Dependents : InterfaceImpl@4a4ebf86 (name: I_Test, ...

I can't understand why :
- the method request.getElementToDestroy() in getBeforeDestroyDependentsCommand of the interface EditHelperAdvice return the Interface (identical question for the EditHelperAdvice of the operation)
- the method request.getElementToDestroy() in getBeforeDestroyElementCommand of the interface EditHelperAdvice return the the Operation.

Shouldn't it be the opposite?
Is there something wrong with my understanding of these methods? potentially in my settings? in the API?

Thanks for reading.
Regards.
Yoann.
Re: Need explanation about getBeforeDestroyElementCommand and getBeforeDestroyDependentsCommand [message #1833777 is a reply to message #1833770] Fri, 23 October 2020 16:53 Go to previous messageGo to next message
Christian Damus is currently offline Christian DamusFriend
Messages: 1235
Registered: July 2009
Location: Canada
Senior Member

Hi, Yoann,

There are two different things happening here: recursive destruction of the model sub-tree and destroy-dependents.

The operations are being destroyed because the GMF run-time, when destroying the interface, recursively destroys the entire sub-tree rooted at that interface from the bottom up. That is why you see that first, for each operation, the interface that owns it is asked for destroy advice and also the operation itself is asked for destroy-dependents advice. Only after the sub-tree is processed (here being only the operations), then the interface edit-helper is asked for advice to destroy its dependents.

What you don't see is the edit-helper for the interface's owner (maybe a package) being asked for advice in destruction of the interface, because I guess you didn't put printfs in that.

So, I think that perhaps what was confusing you was that destruction proceeds recursively bottom-up and the owner of an element is asked how to destroy that element, not the element, itself. This aligns with the owner of an element being asked how to add a new owned element to itself.

It is worth mentioning, perhaps, that the sub-tree of the object being destroyed are all implicitly (structural) dependents and so don't need to be covered by the destroy-dependents advice. It is primarily intended for objects related "side-ways" in the model by arbitrarily complex means.

HTH,
Christian
Re: Need explanation about getBeforeDestroyElementCommand and getBeforeDestroyDependentsCommand [message #1833848 is a reply to message #1833777] Mon, 26 October 2020 08:25 Go to previous messageGo to next message
Yoann Farré is currently offline Yoann FarréFriend
Messages: 152
Registered: November 2017
Senior Member
Hi Christian,

Thank you. Your explanation reassures me of the usage I have of these methods as I manage the deletion of additional elements through getDetroyDependentElementsCommand().

I get another linked question from your answer. If the deletion of an operation leads to a confirmation dialog, if I delete the interface each operation deletion will cause a confirmation dialog. If I would only one confirmation dialog for the interface, what would be a good way? Is there a mean to know if the deletion request was direct or indirect?

Thank you for your help.
Yoann.

Re: Need explanation about getBeforeDestroyElementCommand and getBeforeDestroyDependentsCommand [message #1833850 is a reply to message #1833848] Mon, 26 October 2020 08:40 Go to previous messageGo to next message
Yoann Farré is currently offline Yoann FarréFriend
Messages: 152
Registered: November 2017
Senior Member
I think I find the solution to this second question.
In the map of parameters of the request, there is a key: DestroyElementRequest.initialElementToDestroy if it can help someone else.
Yoann.
Re: Need explanation about getBeforeDestroyElementCommand and getBeforeDestroyDependentsCommand [message #1833854 is a reply to message #1833850] Mon, 26 October 2020 11:18 Go to previous message
Christian Damus is currently offline Christian DamusFriend
Messages: 1235
Registered: July 2009
Location: Canada
Senior Member

Hi, Yoann,

Yes, there is the initial element, but it may not be sufficient in case of deletion of a multiple selection of elements. In that case, I think the request parameters are still propagated from one sub-tree to the next in the selection, so a confirmation dialog could still cache its result to short-circuit any further interaction. (I haven't actually looked in the code to confirm any of this)

Christian
Previous Topic:Adding a Classifier Behavior in SysML
Next Topic:Looking for public demo models (UML, SysML, BPMN, RobotML etc.)
Goto Forum:
  


Current Time: Wed Jan 20 03:48:58 GMT 2021

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

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

Back to the top