How to transfer an object from one part to another part of Eclispe e4 RCP?

I am building an application with eclipse e4 RCP. I have a navigator (similar to the Navigator in the eclipse IDE) and I would like to associate it with an editor (similar to how a file in Navigator in the eclipse IDE is associated with an editor). I am currently using EPartService to open my part of the editor (by creating a new instance) when the user double-clicks the file in the Navigator tree. But I would like to pass it a parameter (String or Object) to tell him which file to open in the editor. I want to be able to open several editors for different nodes of the Navigator tree. I did a lot of research on the Internet, but could not find a solution. I think that his common problem and the e4 system should provide a mechanism for transferring such parameters from one part to another. The current code is as follows:

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);
            }
        }
    });

- part2.setParameter( "PARAM_NAME", "FILE_NAME" );

+4
1

MPart, :

MPart mpart = ...

MyClass myClass = (MyClass)mpart.getObject();

(, "URI " Application.e4xmi). , .

" " :

mpart.getTransientData().put("key", "data");

Object data = mpart.getTransientData().get("key");
+3

All Articles