Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Part destruction when parent is removed from application model(Can I trigger the destruction of a Part by removing its parent element?)
Part destruction when parent is removed from application model [message #1359582] Fri, 16 May 2014 11:58 Go to next message
Uwe San is currently offline Uwe SanFriend
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 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
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
Re: Part destruction when parent is removed from application model [message #1359693 is a reply to message #1359632] Fri, 16 May 2014 13:02 Go to previous messageGo to next message
Uwe San is currently offline Uwe SanFriend
Messages: 119
Registered: January 2012
Senior Member
Thanks for your answer, Tom. Using the IPresentationEngine did the job for me. If this is the best solution for my use case, I'll use it instead of the part service call.

Uwe
Re: Part destruction when parent is removed from application model [message #1359718 is a reply to message #1359693] Fri, 16 May 2014 13:16 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Yes this is the only and correct way to bring DISPOSING UIs

Tom

On 16.05.14 15:02, Uwe San wrote:
> Thanks for your answer, Tom. Using the IPresentationEngine did the job
> for me. If this is the best solution for my use case, I'll use it
> instead of the part service call.
>
> Uwe
Re: Part destruction when parent is removed from application model [message #1359727 is a reply to message #1359718] Fri, 16 May 2014 13:24 Go to previous messageGo to next message
Uwe San is currently offline Uwe SanFriend
Messages: 119
Registered: January 2012
Senior Member
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 #1359956 is a reply to message #1359727] Fri, 16 May 2014 15:38 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
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 Go to previous messageGo to next message
Uwe San is currently offline Uwe SanFriend
Messages: 119
Registered: January 2012
Senior Member
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. Wink

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 #1371824 is a reply to message #1360010] Wed, 21 May 2014 15:00 Go to previous messageGo to next message
Eric Moffatt is currently offline Eric MoffattFriend
Messages: 118
Registered: July 2009
Senior Member
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);
Re: Part destruction when parent is removed from application model [message #1371836 is a reply to message #1371824] Wed, 21 May 2014 15:06 Go to previous messageGo to next message
Uwe San is currently offline Uwe SanFriend
Messages: 119
Registered: January 2012
Senior Member
Ah, that's a good pattern, too. Thanks for sharing!
Re: Part destruction when parent is removed from application model [message #1371846 is a reply to message #1371824] Wed, 21 May 2014 15:10 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
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);
>
Re: Part destruction when parent is removed from application model [message #1799573 is a reply to message #1371846] Mon, 10 December 2018 12:31 Go to previous message
Lars Vogel is currently offline Lars VogelFriend
Messages: 1098
Registered: July 2009
Senior Member

https://bugs.eclipse.org/bugs/show_bug.cgi?id=538007
Previous Topic:What is Eclipse 4 model services equivalent in Eclipse Oxygen
Next Topic:CSS styling of MasterDetailsBlocks's DetailsPart
Goto Forum:
  


Current Time: Wed Dec 04 04:10:49 GMT 2024

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

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

Back to the top