So you used internal API

Inspired by a question that was asked twiced on the newsgroup about internal “API” that is missing in Eclipse 4.x although the feature is still there when interacting with the IDE

The API in question was:

… I needed an ability to allow a user to, upon request, launch a view either attached as a tab in my main window or else detached in its own window … In 3.7, I was able to meet this goal by using the internal APIs to make a call like


So somehow the IDE has preserved this feature but the internal API is gone. The reason is that detaching is now part of the low level Eclipse 4 Application Platform (EAP) which means the Eclipse 4 Workbench has no idea of this feature, hence the internal API is gone.

As outlined many times before the EAP does everything through services. The 2 most important ones are:

  • EPartService
  • EModelService

if you inspect them you find out that EModelService has a method named detach(MPartSashContainerElement mPartSashContainerElement, int x, int y,int width, int height) which sounds very promosing.

So now we somehow have to get access to the EModelService and Model-Element (MPart) which represents the ViewPart which if you know it is quite easy because you can access them through getSite().getService(...).

So if we want to detach a ViewPart by clicking on a button within the view the code looks like this:

public class SampleView extends ViewPart {

  public static final String ID = "test.detach.views.SampleView";
  private Button b;

  public void createPartControl(Composite parent) {
    parent.setLayout(new GridLayout());
    b = new Button(parent, SWT.PUSH);
    b.setText("Detach me");
    b.addSelectionListener(new SelectionAdapter() {
      public void widgetSelected(SelectionEvent e) {
      EModelService s = (EModelService) getSite().getService(EModelService.class);
      MPartSashContainerElement p = (MPart) getSite().getService(MPart.class);
      if (p.getCurSharedRef() != null)
        p = p.getCurSharedRef();

        s.detach(p, 100, 100, 300, 300);

  public void setFocus() {

The only mystery here is the call to getCurSharedRef() which is needed in eclipse because views are shared between multiple areas (read perspectives).

This entry was posted in e4. Bookmark the permalink.

5 Responses to So you used internal API

  1. Mike says:

    What is the point of the line below? It seems that it is never referenced in the rest of the code. You never pass which viewpart you wanted to detach.

    public static final String ID = “test.detach.views.SampleView”;

  2. Puneet Patwari says:

    I want to split my editor area to show two editors programatically. I can see some links that share the code to do it but they do not work in Eclipse Kepler, because the internal API’s have been hidden, as you have mentioned. So Can you please help me achieve my need. I am not able to do it.
    Thanks in advance 🙂

    • Tom Schindl says:

      Please ask at a newsgroup

      • Venkatesh S says:

        MUIElement relToElement = null;
        final EModelService service = PlatformUI.getWorkbench().getService(EModelService.class);
        final MPart dragElement = ((PartSite) workbenchPage.getActiveEditor().getSite()).getModel();
        relToElement = getRelativeElement(dragElement, service);
        MPartSashContainerElement toInsert = (MPartSashContainerElement) dragElement;
        final MStackElement stackElement = (MStackElement) dragElement;
        final MPartStack newStack = BasicFactoryImpl.eINSTANCE.createPartStack();
        toInsert = newStack;
        service.insert(toInsert, (MPartSashContainerElement) relToElement, verticalSplit ? 3 : 1, 0.5f);

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.