Bug 562916

Summary: Offer a method in EModelService to get the parent of a part / placeholder
Product: [Eclipse Project] Platform Reporter: Lars Vogel <Lars.Vogel>
Component: UIAssignee: Platform-UI-Inbox <Platform-UI-Inbox>
Status: NEW --- QA Contact:
Severity: normal    
Priority: P3 CC: rolf.theunissen
Version: 4.16   
Target Milestone: ---   
Hardware: PC   
OS: Windows 10   
See Also: https://git.eclipse.org/r/162623
Whiteboard:

Description Lars Vogel CLA 2020-05-07 04:58:05 EDT
See https://git.eclipse.org/r/#/c/162592/4/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/StackRenderer.java

We frequently (also in client code) need to access the parent of a part. As any part can be a placeholder, we frequently have to use the pattern of checking if the part.getCurSharedRef() != null and if not null access the parent of the placeholder and if not present access the parent of the part.

I suggest we add a method to the model service:

MUIElement getParentForPart(MPart part)
Comment 1 Eclipse Genie CLA 2020-05-07 05:02:10 EDT
New Gerrit change created: https://git.eclipse.org/r/162623
Comment 2 Rolf Theunissen CLA 2021-03-19 08:56:41 EDT
Shared elements are at least MPart, MArea, MPartSashContainer, MPartStack (those are shown in the model spy). For all these elements a similar method would be beneficial.

Not sure how to name the method though. The parent of a MPlaceholder can and will change. It should be clear that the parent is not the same as the container of an element.

suggestions:

MUIElement getCurrentParent(MUIElement element)
MUIElement getEffectiveParent(MUIElement element)

MUIElement getGuardian(MUIElement element) 
Guardian captures best the nature of what this method does, that is determine which element currently has custody of the element. However, not many people will guess that this method would be around if it has that name.