Part destruction when parent is removed from application model [message #1359582] |
Fri, 16 May 2014 11:58 |
Uwe San Messages: 119 Registered: January 2012 |
Senior Member |
|
|
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 |
Thomas Schindl Messages: 6651 Registered: July 2009 |
Senior Member |
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03506 seconds