Eclipse 4 related

List<MToolBar> toolbarElements = modelService.findElements(application,
                MToolBar.class,
                EModelService.ANYWHERE | EModelService.IN_PART, new Selector() {
                    @Override
                    public boolean select(MApplicationElement element) {
                        System.out.println(element);
                        return (element instanceof MToolBar);
                    }
                });
MToolBar viewMenu = (MToolBar)modelService.find(TOOLBAR_ID, application);

        MPart part = partService.createPart("your part id");

        //find your container
        List<MPartStack> stacks = modelService.findElements(application, STACK_ID, MPartStack.class, null);
        if (stacks.size() < 1) {
            MessageDialog.openError(shell, "Error ", 
                    "Part stack not found. Is the following ID correct?" + STACK_ID);
            return;
        } 

        //add your part into container
        stacks.get(0).getChildren().add(part);
        // activates the part
        partService.showPart(part, PartState.ACTIVATE);

E4:
http://wiki.eclipse.org/Eclipse4/RCP/Dependency_Injection
http://wiki.eclipse.org/E4/Snippets
http://wiki.eclipse.org/Eclipse4/RCP/FAQ
http://wiki.eclipse.org/E4/Contexts

org.eclipse.e4.ui.workbench.renderers.swt.SWTPartRenderer class is the parent of all e4 renderer
org.eclipse.e4.ui.workbench.renderers.swt.WBWRenderer is the renderer of MWindow
in one words, e4 is using EMF model to map the detail SWT composite, the EMF model is friend to xml
org.eclipse.e4.ui.model.application.ui.MUIElement class is the base class for e4 EMF model
TrimmedWindow is map to Shell, Window is also map to Shell, and use the same layout(TrimmedPartLayout)

AbstractPartRenderer.processContents method will map the config to real swt composite

TrimBar is just a composite with TrimBarLayout
MTrimBar is map to Composite, exchange information with Widget’s setData and getData, MTrimBar is set to Widget using setData

猜你喜欢

转载自blog.csdn.net/lantianjialiang/article/details/81187024
今日推荐