小编Jeh*_*Zeb的帖子

如何在 Eclispe e4 RCP 中将对象从一个部分传递到另一部分?

我正在使用 eclipse e4 RCP 构建一个应用程序。我有一个导航器(类似于 eclipse IDE 中的导航器),我想将其链接到编辑器(类似于 eclipse IDE 中的导航器中的文件链接到编辑器的方式)。目前,当用户双击导航器树中的文件时,我正在使用 EPartService 打开编辑器部分(通过创建新实例)。但我想向它传递一个参数(字符串或对象),让它知道要在编辑器中打开哪个文件。我希望能够为导航树的不同节点打开多个编辑器。我在互联网上做了很多研究,但找不到解决方案。我认为这是一个常见问题,e4 框架应该提供一种机制将此类参数从一个部分传递到另一个部分。当前代码如下:

viewer.addDoubleClickListener(event -> {
        final IStructuredSelection selection = (IStructuredSelection) event.getSelection();
        FileNode file = null;
        boolean partExists = false;
        if (selection.getFirstElement() instanceof FileNode ) {
            file = (FileNode ) selection.getFirstElement();
            for (MPart part1 : partService.getParts()) {
                if (part1.getLabel().equals(file.getName())) {

                    partService.showPart(part1, PartState.ACTIVATE);
                    partExists = true;
                    break;
                }
            }
            if (!partExists) {
                MPart part2 = partService
                        .createPart("com.parts.partdescriptor.fileeditor");
                part2.setLabel(file.getName());
                partService.showPart(part2, PartState.ACTIVATE);
            }
        }
    });
Run Code Online (Sandbox Code Playgroud)

是否可以这样说:part2.setParameter("PARAM_NAME", "FILE_NAME"); ?

eclipse eclipse-rcp e4

5
推荐指数
1
解决办法
1412
查看次数

标签 统计

e4 ×1

eclipse ×1

eclipse-rcp ×1