Abhishek Choudhary
Abhishek Choudhary

Reputation: 8395

Attaching an Eclipse detached view programmatically

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

Upvotes: 2

Views: 977

Answers (2)

Paul Webster
Paul Webster

Reputation: 10654

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.

Upvotes: 2

Mario Marinato
Mario Marinato

Reputation: 4617

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 );

Upvotes: 2

Related Questions