Fry123
Fry123

Reputation: 38

Open DialectEditor programmatically outside of main editor area (E3/E4 hybrid)

what I want to do:

In my RCP an E3/E4 hybrid I have a project and library based on sirius tree. The User can drag an drop item from the library tree to the project tree. This works fine and was no great problem to build in. So now I want to make the UI more usable. It should looks like this layout:

enter image description here what works:

After application startup I open my library presentation with the DialectUIManager.

final DialectEditor editor = (DialectEditor) 
DialectUIManager.INSTANCE.openEditor(siriusSession, description, monitor);

Okay, this works. But it open it in the editor in the part market as org.eclipse.ui.editorss. This it not what I want

enter image description here

what does not work:

I want to show it in the "Library Part". I can move it manually with the mouse after open the editor, but how can i tell DialectUIManager to open it direct there. Or how can I programmatically it move there.

I do a lot of google research but i don't found a solution. The only thing I found was a hint Pierre-Charles David https:// www. eclipse.org/forums/index.php?t=msg&th=998476&goto=1631138&#msg_1631138

If you need is simply to show the editor outside of the main editor area, this is possible since Eclipse 4.2 (e4 does not really treat the main editor area as something special), so you can have your editor "around" another editor in the middle of other views.

But at this step I stuck. I also ask it in the Sirius Forum but they say its a Eclipse E4 problem

Thanks for help, code snippets or links to correct part of manual.

Upvotes: 1

Views: 280

Answers (1)

Fry123
Fry123

Reputation: 38

I've found a solution. It's not very nice, but it works. I execute these code here after the editors have opened.

What the code does:

He is looking for the MPlaceholder which has the ID: org. eclipse. ui. editorss. There he descends until he is with the parts. These are in the Compatibly editor mode. Then he chooses the part we wants to move out of and Attach them to the MPartStack target.

  public static void movePart(MApplication application, 
            EModelService modelService) {

    MPart partToMove = null;
    MUIElement muiElement = 
            modelService.find("org.eclipse.ui.editorss", application);

    if (muiElement instanceof MPlaceholder) {
      MPlaceholder placeholder = (MPlaceholder) muiElement;
      MUIElement ref = placeholder.getRef();

      if (ref instanceof MArea) {
        MArea area = (MArea) ref;
        List<MPartSashContainerElement> children = area.getChildren();

        for (MPartSashContainerElement mPartSashContainerElement 
                                                       : children) {

          if (mPartSashContainerElement instanceof MPartStack) {
            MPartStack partStack = (MPartStack) mPartSashContainerElement;
            List<MStackElement> children2 = partStack.getChildren();
            for (MStackElement mStackElement : children2) {
              if (mStackElement instanceof MPart) {
                MPart part = (MPart) mStackElement;
                // Library is the Editor Name wiche I want to move
                if (part.getLabel().equals("Library")) {
                  partToMove = part;
                  break;
                }
              }
            }
          }
        }

      }
    }

    if (partToMove != null) {
      moveElement(modelService, application, partToMove);
    }
  }

  private static void moveElement(EModelService modelService, 
                    MApplication application, MPart part) {
    // target PartStack
    MUIElement find = modelService.find("de.bsg.onesps.rcp.
                               partstack.library", application);

    if (find instanceof MPartStack) {
      MPartStack mPartStack = (MPartStack) find;

      mPartStack.getChildren().add(part);
      mPartStack.setSelectedElement(part);
    }
  }

Upvotes: 0

Related Questions