Bug 483699

Summary: [View Mgmt] Unified API to open parts
Product: [Eclipse Project] Platform Reporter: Andrey Loskutov <loskutov>
Component: UIAssignee: Platform-UI-Inbox <Platform-UI-Inbox>
Status: NEW --- QA Contact:
Severity: enhancement    
Priority: P3 CC: Lars.Vogel
Version: 4.6   
Target Milestone: ---   
Hardware: All   
OS: All   
See Also: https://bugs.eclipse.org/bugs/show_bug.cgi?id=471782
https://git.eclipse.org/r/63757
https://git.eclipse.org/c/platform/eclipse.platform.ui.git/commit/?id=afaba1ebc1615d034fcddf6220d3269b8b341550
https://git.eclipse.org/r/63761
https://bugs.eclipse.org/bugs/show_bug.cgi?id=501539
Whiteboard:

Description Andrey Loskutov CLA 2015-12-04 16:56:51 EST
Follow up on bug 471782 comment 56.

We have different ways and different API's to open legacy/e4 parts. Everyone who wants to open view via id is forced to write the block code below to open a part:

String viewId = viewDescriptor.getElementId();
if (CompatibilityPart.COMPATIBILITY_VIEW_URI.equals(viewDescriptor.getContributionURI())) {
	IWorkbenchPage page = window.getActivePage();
	if (page != null) {
		try {
			page.showView(viewId);
		} catch (PartInitException e) {
			handleViewError(viewId, e);
		}
	}
} else {
	MPart part = partService.findPart(viewId);
	if (part == null) {
		MPlaceholder placeholder = partService.createSharedPart(viewId);
		part = (MPart) placeholder.getRef();
	}
	partService.showPart(part, PartState.ACTIVATE);
}

This code is duplicated now at least 2 times (see ShowViewHandler and ViewElement).

The problems I see for the new API implementation:
1) e4 does not differentiate between views/editors, e3 uses different types for them. If we want return the reference to the opened part, we need some tricks because e3 and e4 return types are different.
2) The code naturally belongs to the EPartService but it seem still require the access to the legacy code in WorkbenchPage.

Ideally it will be something like:

MPart EPartService.openPart(String id, PartState partState). 

For e3 we must provide some utility method to get IWorkbenchPartReference from MPart, may be just adapter to it. May be I'm just missing something obvious and all the code is lying already somewhere and just need to be properly organized.

The code in WorkbenchPage.shiwView(...) and EPartService.showPart(...) should be either deprecated or fixed to properly work via the new API independently if the given id is from e3 or e4, the duplicated code in ShowViewHandler and ViewElement should also be changed to use that new API.
Comment 1 Lars Vogel CLA 2015-12-08 05:47:59 EST
The restriction we have is that e4 code is not allowed to have a dependency to e3 plug-ins.
Comment 2 Eclipse Genie CLA 2016-01-07 12:01:01 EST
New Gerrit change created: https://git.eclipse.org/r/63757
Comment 4 Eclipse Genie CLA 2016-01-07 12:54:51 EST
New Gerrit change created: https://git.eclipse.org/r/63761