Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » hidePart during shutdown leaves something behind(lifecycle event hidePart)
hidePart during shutdown leaves something behind [message #1410863] Thu, 21 August 2014 20:40 Go to next message
John Bodkin is currently offline John BodkinFriend
Messages: 39
Registered: November 2011
Member
How do I destroy certain parts during shutdown?

I have a part descriptor (multiples allowed and tagged "removeOnHide" and my personal tag "closeOnExit") that is used to create a part when the user double clicks a file name in a different view part in my compatibility layered rcp app.

I added a lifecycleuri to my product and that class subscribes to the UIEvents.UILifeCycle.APP_SHUTDOWN_STARTED event. I used the following article to get me this far: http://www.vogella.com/tutorials/Eclipse4LifeCycle/article.html

In my new EventHandler() I search to find all the parts tagged "closeOnExit" to be closed on exit and call hidePart(part, true); as described in the answer to this question http://stackoverflow.com/questions/16693443/eclipse-rcp4-close-part-on-exit-disable-persistence-of-a-part

The handler is executed during the shutdown of the app and the part(s) is/are hidden. However on restart of my app there is an undesired area with nothing in it except for the min max buttons.

I also added a menu item to the app that calls hidePart(part, true); and the part is closed normally without leaving behind that area with just the min max buttons.

I tried setting the part visibility to false during the shutdown which eliminates the undesired artifact on subsequent startup but it also prevents the user from being able to create new parts as needed. So I tried setVisible(true) during the creation of this part to counter the setVisible(false) during shutdown but that didn't work. I backed out this approach since it was obviously incorrect.

Have I stumbled onto a bug?

Is there a better way for me to achieve the desired result?

Re: hidePart during shutdown leaves something behind [message #1411017 is a reply to message #1410863] Fri, 22 August 2014 07:14 Go to previous messageGo to next message
Paweł Doleciński is currently offline Paweł DolecińskiFriend
Messages: 44
Registered: January 2014
Member
Hi,

does your area has "NoAutoCollapse" tag applied? I guess it does not as your action from menu item works.

I am not sure but could be that after the lifecycle event there is not time to clean up. So basically for hiding empty containers the CleanUpAddon is responsible.
Could you check if after hiding your parts, correct events are published and received?
If not, then you have no other choice but after removing a part to check if its container is empty and hide it manually.

Cheers
Paweł
Re: hidePart during shutdown leaves something behind [message #1411030 is a reply to message #1411017] Fri, 22 August 2014 08:02 Go to previous messageGo to next message
Christoph Keimel is currently offline Christoph KeimelFriend
Messages: 482
Registered: December 2010
Location: Germany
Senior Member
I don't know when UIEvents.UILifeCycle.APP_SHUTDOWN_STARTED is sent. Maybe its already to late and the model has already been saved?
Have you tried to process your model on @PreSave in your life cycle handler instead of listening to the event? This is called before the application model is saved, so you can modify the model before it is persisted.
Re: hidePart during shutdown leaves something behind [message #1411186 is a reply to message #1411030] Fri, 22 August 2014 16:03 Go to previous messageGo to next message
John Bodkin is currently offline John BodkinFriend
Messages: 39
Registered: November 2011
Member
The parts are not tagged "NoAutoCollapse" according to the e4 spy tool.

I tried adding the following code to my EventHandler that would get the parent of the part being closed with hidePart(part, true):

EPartService peService = part.getContext().get(EPartService.class);
peService.switchPerspective(eModelService.getPerspectiveFor(part));
MElementContainer<MUIElement> parent = part.getParent();
peService.hidePart(part, true);
if ( parent.getChildren().isEmpty() ) {
  parent.setToBeRendered(false);
  parent.setVisible(false);
}


This almost worked but instead of leaving behind an area with only a min max button it just leaves behind a blank space where the part used to exist. The surrounding parts respect their former neighbors space even though it is gone.

I also tried adding a @PreSave method to my lifecycle class. The @PostContextCreate method is still being called which subscribes to the app shutdown event. The @PreSave method isn't called. I'm running on Win 7 64 bit Eclipse 4.4 Luna target.
https://bugs.eclipse.org/bugs/show_bug.cgi?id=320831
That bug is reolved though.

I also added @ProcessAdditons and @ProcessRemovals to my lifecycle class. These methods are called during the startup. The splash screen appears and these methods are called before the progress bar on the splash screen appears.

I tried to remove the parts from the model in the @ProcessRemovals method and it did better than anything so far. If two parts are in the same space it leaves behind the artifact but if it was alone it cleans up nicely.

@ProcessRemovals
void processRemovals(MApplication app) {
  List<String> tags = new ArrayList<String>();
  tags.add(TAG_TO_CLOSE);
  List<MPart> elementsWithTags = eModelService.findElements(
                                   app, null, MPart.class, tags);
  for (MPart part : elementsWithTags) {
    try {
	MElementContainer<MUIElement> parent = part.getParent();
	parent.getChildren().remove(part);
        // if this worked I would have added recursive method
	if ( parent.getChildren().isEmpty() ) {
		MElementContainer<MUIElement> grandParent = parent.getParent();
		grandParent.getChildren().remove(parent);
	}
    } catch (Exception e) {
	e.printStackTrace();
    }
  }
}


Re: hidePart during shutdown leaves something behind [message #1411234 is a reply to message #1411186] Fri, 22 August 2014 19:13 Go to previous messageGo to next message
John Bodkin is currently offline John BodkinFriend
Messages: 39
Registered: November 2011
Member
I was able to get it to work once I added in the recursive method as follows:

@ProcessRemovals
void processRemovals(MApplication app) {
  List<String> tags = new ArrayList<String>();
  tags.add(TAG_TO_CLOSE);
  List<MPart> elementsWithTags = eModelService.findElements(app, null, MPart.class, tags);

  for (MPart part : elementsWithTags) {
    try {
	MElementContainer<MUIElement> parent = part.getParent();
	parent.getChildren().remove(part);
	if ( parent.getChildren().isEmpty() ) {
	  removeEmptyContainers(parent.getParent(), parent);
	}
    } catch (Exception e) {
	e.printStackTrace();
    }
  }

}
	
private void removeEmptyContainers(MElementContainer<MUIElement> parent, MElementContainer<MUIElement> child) {
  parent.getChildren().remove(child);
  if ( parent.getChildren().isEmpty() ) {
    removeEmptyContainers(parent.getParent(), parent);
  }
}
Re: hidePart during shutdown leaves something behind [message #1411237 is a reply to message #1411234] Fri, 22 August 2014 19:18 Go to previous message
John Bodkin is currently offline John BodkinFriend
Messages: 39
Registered: November 2011
Member
However this creates a new problem. An error dialog pops up stating:

Workbench Auto-Save Job
An internal error has occurred.
The selected element org.eclipse.e4.ui.model.application.ui.basic.impl.PartStackImpl@5060e945 (elementId: PartStack@606c027c, tags: [active], contributorURI: null) (widget: null, renderer: null, toBeRendered: true, onTop: false, visible: true, containerData: 5000, accessibilityPhrase: null) is not a child of this container


Obviously I didn't remove everything I needed to remove in order to keep this Job happy.
Previous Topic:Adding menu contributions to e4view's toolbar
Next Topic:Eclipse Kepler got slow
Goto Forum:
  


Current Time: Fri Mar 29 05:48:40 GMT 2024

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

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

Back to the top