Bug 473941 - e4Context of PageSite not activated
Summary: e4Context of PageSite not activated
Status: REOPENED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.5   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Platform-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on: 552906
Blocks: 552872
  Show dependency tree
 
Reported: 2015-07-30 11:16 EDT by Stephan Wahlbrink CLA
Modified: 2019-11-26 08:07 EST (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Stephan Wahlbrink CLA 2015-07-30 11:16:59 EDT
The e4Context of a PageSite is not activated, e.g. if a new page is created.

PageSite.e4Context is only activated in PageBookView.partActivated if the view itself is activated (users changed the view).

Maybe it would be appropriate to activate e4Context in PageSite.activate (like the other nested service/context?
Comment 1 Eclipse Genie CLA 2015-10-15 04:12:34 EDT
New Gerrit change created: https://git.eclipse.org/r/58212
Comment 2 Daniel Krügler CLA 2016-06-08 17:45:48 EDT
Today I wanted to open a bug report because for the same reason, because in our company we are using PageSite instances a lot in our own views and we needed quite a while to understand what is going wrong with our programmatically activated handlers. The observation was that for every such handler that implemented IElementUpdater the corresponding method updateElement was *never* called. This caused some serious context menu errors in all the views where we had such handlers activated within PageSite context, so PLEASE fix this bug!

My analysis came to the same conclusion as the submitter that PageSite#activate and PageSite#deactivate are missing to call the corresponding activate/deactivate calls on the internally hold EclipseContext.

Personally I would suggest two slightly improvements of the fix:

a) The activate / deactivate calls on the context should follow the same hierarchic order as the other calls inside PageSite#(de)activate. That means that the new line

e4Context.activate();

should logically be located between line

active = true;

and line

serviceLocator.activate();

b) Not directly related to this issue, but a real minifix should be to adjust PageSite's signature of

Object getAdapter(Class adapter);
boolean hasService(final Class key);

which don't match the recently generified IServiceLocator's methods

<T> T getService(Class<T> api);
boolean hasService(Class<?> api);

Can we please have this interface correction applied as well to PageSite?

I also want to inform those people (like us) who need a working workaround NOW. Fortunately this is possible by a rather good approximation of the ideal solution by introducing a derivative of PageSite as follows (Note the nasty and actually unnecessary type cast in the constructor because of problem (b) mentioned above):

public class MyPageSite extends PageSite {

	private IEclipseContext e4Context;

	public MyPageSite(IViewSite parentViewSite) {
		super(parentViewSite);
		e4Context = (IEclipseContext) getService(IEclipseContext.class);
		Assert.isNotNull(e4Context);
	}

	@Override
	public void activate() {
		e4Context.activate();
		super.activate();
	}

	@Override
	public void deactivate() {
		super.deactivate();
		e4Context.deactivate();
	}

}
Comment 3 Eclipse Genie CLA 2016-06-08 18:10:34 EDT
New Gerrit change created: https://git.eclipse.org/r/74949
Comment 4 Daniel Krügler CLA 2016-06-08 18:12:13 EDT
(In reply to Eclipse Genie from comment #3)
> New Gerrit change created: https://git.eclipse.org/r/74949

An alternative P/R has been provided that uses the correct hierarchic order of activation and deactivation. It doesn't touch problem (b) here, because the problem is orthogonal. I will open a separate bug that requests proper generification of PageSite.
Comment 5 Daniel Krügler CLA 2016-06-08 18:29:12 EDT
(In reply to Daniel Kruegler from comment #4)
> (In reply to Eclipse Genie from comment #3)
> > New Gerrit change created: https://git.eclipse.org/r/74949
> 
> An alternative P/R has been provided that uses the correct hierarchic order
> of activation and deactivation. It doesn't touch problem (b) here, because
> the problem is orthogonal. I will open a separate bug that requests proper
> generification of PageSite.

Stephan, I just noticed that I only cared about PageSite (which we use in our code base), but your fix (correctly) also fixes PageBookView. Would you be willing to improve the ordering problem by your patch suggestion, so that I can withdraw my presented patch?
Comment 7 Karsten Thoms CLA 2019-09-21 17:41:55 EDT
Thanks, Stephan & Daniel!
Comment 8 Eclipse Genie CLA 2019-11-11 13:59:56 EST
New Gerrit change created: https://git.eclipse.org/r/152448
Comment 9 Andrey Loskutov CLA 2019-11-11 14:03:32 EST
(In reply to Eclipse Genie from comment #8)
> New Gerrit change created: https://git.eclipse.org/r/152448

This reverts the fix for this bug, because it causes regression described in bug 552906 comment 18 => reopening this bug again for a better fix.