Part destruction when parent is removed from application model [message #1359582] |
Fri, 16 May 2014 11:58  |
Eclipse User |
|
|
|
Hi,
my E4 application model consists of a Window with a Perspective Stack to/from which I dynamically add and remove Perspectives. Whenever a new Perspective is added, the old one will be removed, such that the Stack contains only one Perspective at a time.
All of my Perspectives are stored as Snippets. They each contain a Part Sash Container as the root control element which is used to hold different sets of Placeholders. For instance:
+ Snippets
+ Perspective
+ Controls
+ PartSashContainer (vertical)
+ Placeholder
+ Placeholder
+ Perspective
+ Controls
+ PartSashContainer (horizontal)
+ Placeholder
+ Placeholder
+ Placeholder
By default, the Placeholders have no reference to any other element. When a Perspective is added to the Stack, I add references to Parts for all the Placeholders in the Perspective. The Parts are defined in the sharedElements attribute of the Window.
So far, so good.
My trouble begins when I remove a Perspective in order to add another. I remove simply by calling
perspectiveStack.getChildren().clear();
before I add the new perspective by calling
partService.switchPerspective(perspective);
I assumed this would cause the current Parts to be destroyed, but their @PreDestroy methods are never called, although their container elements were removed from the model.
I can force the Part destruction by explicitly hiding all Parts before I remove their Perspective:
for (MPart part : parts) {
partService.hidePart(part);
}
Is there a more elegant way to remove and destroy the Perspective along with its Parts in this scenario? I suspect I could try other approaches (using Part Descriptors instead of Parts, or defining my Parts as Snippets instead of Shared Elements), but I'm not sure what would be the best approach here. The documentation is not great in this regard.
Any help would be highly appreciated.
Thanks,
Uwe
|
|
|
Re: Part destruction when parent is removed from application model [message #1359632 is a reply to message #1359582] |
Fri, 16 May 2014 12:26   |
Eclipse User |
|
|
|
The problem with a simple remove from the model is that e.g. a move (ie
the new dnd feature) is also a remove/add and we can not distinguish
between:
a) a remove
b) a remove & add
What you need to call is IPresentationEngine#removeGUI which will walk
the containment tree destroying the children.
The only other change would be to rely on GC and in the finalizer remove
the GUI but that is not we really want, right?
Tom
On 16.05.14 13:58, Uwe San wrote:
> Hi,
>
> my E4 application model consists of a Window with a Perspective Stack
> to/from which I dynamically add and remove Perspectives. Whenever a new
> Perspective is added, the old one will be removed, such that the Stack
> contains only one Perspective at a time.
>
> All of my Perspectives are stored as Snippets. They each contain a Part
> Sash Container as the root control element which is used to hold
> different sets of Placeholders. For instance:
>
>
> + Snippets
> + Perspective
> + Controls
> + PartSashContainer (vertical)
> + Placeholder
> + Placeholder
> + Perspective
> + Controls
> + PartSashContainer (horizontal)
> + Placeholder
> + Placeholder
> + Placeholder
>
>
> By default, the Placeholders have no reference to any other element.
> When a Perspective is added to the Stack, I add references to Parts for
> all the Placeholders in the Perspective. The Parts are defined in the
> sharedElements attribute of the Window.
>
> So far, so good.
> My trouble begins when I remove a Perspective in order to add another. I
> remove simply by calling
> perspectiveStack.getChildren().clear();
> before I add the new perspective by calling
> partService.switchPerspective(perspective);
>
> I assumed this would cause the current Parts to be destroyed, but their
> @PreDestroy methods are never called, although their container elements
> were removed from the model.
>
> I can force the Part destruction by explicitly hiding all Parts before I
> remove their Perspective:
>
> for (MPart part : parts) {
> partService.hidePart(part);
> }
>
>
> Is there a more elegant way to remove and destroy the Perspective along
> with its Parts in this scenario? I suspect I could try other approaches
> (using Part Descriptors instead of Parts, or defining my Parts as
> Snippets instead of Shared Elements), but I'm not sure what would be the
> best approach here. The documentation is not great in this regard.
>
> Any help would be highly appreciated.
>
> Thanks,
> Uwe
|
|
|
|
|
|
Re: Part destruction when parent is removed from application model [message #1359956 is a reply to message #1359727] |
Fri, 16 May 2014 15:38   |
Eclipse User |
|
|
|
I don't know because I know ;-) but I guess if you think about it the
reasoning of doing this way (a remove from the model does not
automatically lead to a dispose) makes sense, right?
Maybe it would be good to have a EModelService#delete method?
Tom
On 16.05.14 15:24, Uwe San wrote:
> Good to know. Just out of curiosity, is this documented somewhere? Cause
> I had never seen a reference to this interface before you mentioned it
> here.
>
> Uwe
|
|
|
Re: Part destruction when parent is removed from application model [message #1360010 is a reply to message #1359956] |
Fri, 16 May 2014 16:09   |
Eclipse User |
|
|
|
It completely makes sense. I was simply surprised I had never seen this aspect anywhere else. There's a lot of E4 documentation that talks about manipulations of application model elements using the EModelService, the EPartService etc., but the IPresentationEngine does not seem to have many fans out there. 
An EModelService#delete method might actually make sense, because a common user of the E4 framework may expect to have this functionality in one of the standard services instead of the IPresentationEngine.
|
|
|
|
|
Re: Part destruction when parent is removed from application model [message #1371846 is a reply to message #1371824] |
Wed, 21 May 2014 15:10   |
Eclipse User |
|
|
|
Wouldn't you agree that EModelService.deleteElement() would be the most
natural choice?
Tom
On 21.05.14 17:00, Eric Moffatt wrote:
> The pattern we use in the IDE is similar but doesn't directly call the
> IPresentationEngine:
>
> someElement.setToBeRendered(false); // Causes the rendering engine to
> call 'removeGui'
> someElement.getParent().getChildren().remove(someElement);
>
|
|
|
|
Powered by
FUDForum. Page generated in 0.04410 seconds