Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 303218 - Active part no longer seems to be queryable from the application's context
Summary: Active part no longer seems to be queryable from the application's context
Status: RESOLVED FIXED
Alias: None
Product: e4
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 1.0   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 1.0 M4   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-02-18 12:50 EST by Remy Suen CLA
Modified: 2010-02-18 16:15 EST (History)
1 user (show)

See Also:


Attachments
Active part bug tests patch (1.81 KB, patch)
2010-02-18 12:50 EST, Remy Suen CLA
no flags Details | Diff
Patch (5.03 KB, patch)
2010-02-18 16:13 EST, Oleg Besedin CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Remy Suen CLA 2010-02-18 12:50:20 EST
Created attachment 159461 [details]
Active part bug tests patch

Some change introduced by bug 299529's attachment 159241 [details] has caused active parts to no longer be queryable from the application's context.

The attached test will reproduce the problem. I have not yet been able to create a smaller test case.
Comment 1 Remy Suen CLA 2010-02-18 13:13:13 EST
The code below will fail. If I pass in null as a scheduling strategy, it also fails pre-attachment 159241 [details]. So perhaps bug 299529 is a red herring?

--------------

MApplication application = MApplicationFactory.eINSTANCE
		.createApplication();
MWindow window = MApplicationFactory.eINSTANCE.createWindow();
application.getChildren().add(window);
application.setSelectedElement(window);

MPart partA = MApplicationFactory.eINSTANCE.createPart();
MPart partB = MApplicationFactory.eINSTANCE.createPart();
window.getChildren().add(partA);
window.getChildren().add(partB);
window.setSelectedElement(partA);

IEclipseContext applicationContext = E4Application
		.createDefaultContext();
applicationContext.set(MApplication.class.getName(), application);
application.setContext(applicationContext);
Workbench.processHierarchy(application);

IEclipseContext windowContext = EclipseContextFactory.create(
		applicationContext, null);
window.setContext(windowContext);
windowContext.set(MWindow.class.getName(), window);

IEclipseContext partContextA = EclipseContextFactory.create(
		windowContext, null);
partA.setContext(partContextA);
partContextA.set(MPart.class.getName(), partA);

IEclipseContext partContextB = EclipseContextFactory.create(
		windowContext, null);
partB.setContext(partContextB);
partContextB.set(MPart.class.getName(), partB);

applicationContext.set(IContextConstants.ACTIVE_CHILD, windowContext);
windowContext.set(IContextConstants.ACTIVE_CHILD, partContextA);

window.getContext().set(IContextConstants.ACTIVE_CHILD,
		partB.getContext());
Object o = applicationContext.get(IServiceConstants.ACTIVE_PART);
assertEquals(partB, o);

window.getContext().set(IContextConstants.ACTIVE_CHILD,
		partA.getContext());
o = applicationContext.get(IServiceConstants.ACTIVE_PART);
assertEquals(partA, o);
Comment 2 Remy Suen CLA 2010-02-18 13:44:15 EST
To be honest, the tests may not actually test the incorrect behaviour in question. The best way is to just start up the e4 IDE application and try to save. Ctrl+S does nothing because the system cannot find an active part. Just alter the canExecute(MPart)'s parameter to be @Optional and you will see that it is getting nulls.
Comment 3 Oleg Besedin CLA 2010-02-18 16:13:41 EST
Created attachment 159482 [details]
Patch

This is caused by the wrong code in the ActivePartLookupFunction.

The ActivePartLookupFunction depends on MWindow/MApplication.getContext() result:

		IEclipseContext current = window.getContext();

That is the value stored outside of the context. It is not set originally so there is not dependency on IContextConstants.ACTIVE_CHILD created.

When it is set later, the context is not notified as no dependecy were created.

I'll fix the ordering so that context is set on MApplication before the class is added to the context.

The patch also fixes a problem in the context eventing that was exposed by the change.
Comment 4 Oleg Besedin CLA 2010-02-18 16:15:07 EST
Patch applied to CVS Head. I'll add comment to the bug 295003 on the ActivePartLookupFunction.