简体   繁体   English

Eclipse 4重用工具栏用于不同部分

[英]Eclipse 4 reuse toolbar for different parts

I've build about 10-15 Parts in differenet PartStacks. 我已经在differenet PartStacks中构建了大约10-15个零件。 Every Part should have some Handled Tool Item, 4 of them are identical. 每个零件都应有一些“处理工具”,其中四个是相同的。 Because of this I want to reuse this 4 toolbar-items without adding them manually to every part. 因此,我想重用这4个工具栏项目,而不必手动将它们添加到每个零件中。

In Eclipse 3.x we had build these toolbars via inheritance - each view, which should have this toolbar-items extends a class, which adds these items. 在Eclipse 3.x中,我们通过继承构建了这些工具栏-每个视图(应具有此工具栏项)扩展了一个类,该类添加了这些项。

Is there a proper way to have a "toolbar-template"? 是否有适当的方法来拥有“工具栏模板”?

Any ideas wanted ;) 任何想法想要;)

Cheers, Steffen 干杯,斯特芬

SOLUTION : (thanks greg) 解决方案 :(感谢greg)

Thank you Greg, the Processor worked. 谢谢您,格雷格,处理器的工作。

Here is the corresponding code: 这是相应的代码:

@Inject
@Named("de.test.myperspective")
private MPerspective perspective;

@Inject
private MApplication application;

@Execute
public void execute(EModelService modelService) {
    if (perspective != null) {
        List<MPart> parts = modelService.findElements(perspective, null,
                MPart.class, null);
        for (MPart part : parts) {
            MUIElement snip = modelService.cloneSnippet(application,
                    "de.test.mytoolbarsnippet", null);
            MToolBar toolbar = (MToolBar) snip;
            part.getToolbar().getChildren()
                    .addAll(0, toolbar.getChildren());
        }
    }
}

In the fragment.xmi I added a new ModelFragment to Application->Snippets and added a Toolbar with ID "de.test.mytoolbarsnippet" there. 在fragment.xmi中,我向Application-> Snippets添加了一个新的ModelFragment,并在其中添加了ID为“ de.test.mytoolbarsnippet”的工具栏。

You could use a Snippet in your application model. 您可以在应用程序模型中使用Snippet

Use the EModelService cloneSnippet method to create the controls from the snippet. 使用EModelService cloneSnippet方法可从代码段创建控件。

You might do this in a Processor running on the application model - see the org.eclipse.e4.workbench.model extension point processor element. 您可以在应用程序模型上运行的处理器中执行此操作-请参阅org.eclipse.e4.workbench.model扩展点processor元素。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM