Question

I have programmatically detached a view from eclipse. now I want to attach it back. What is the best efficient way to do that.

Was it helpful?

Solution

The matching operation for detach(*) is org.eclipse.e4.ui.workbench.modeling.EModelService.insert(MPartSashContainerElement, MPartSashContainerElement, int, float).

The only working example I found was in the DND support SplitDropAgent, but it's not easy to read. I suspect you need to find the part that you have previously detached.

OTHER TIPS

You have to do some cast-validity and null-validity checks but here's the deal:

PartSite partSite = (PartSite)yourDetachedView.getViewSite();
PartPane partPane = partSite.getPane();
ViewStack viewStack = (ViewStack)partPane.getContainer();
ViewPane viewPane = (ViewPane)viewStack.getSelection();
viewPane.doAttach();

EDIT: Here's another way.

PartSite site = (PartSite)yourDetachedView.getSite();
WorkbenchPage workbenchPage = (WorkbenchPage)site.getPage();
String viewId = site.getId();
String secondaryId = yourDetachedView.getViewSite().getSecondaryId();
IViewReference viewReference = workbenchPage.findViewReference( viewId, secondaryId );
Perspective activePerspective = workbenchPage.getActivePerspective();
PerspectiveHelper presentation = activePerspective.getPresentation();
presentation.attachPart( viewReference );
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top