问题
I want to open a text editor in eclipse 4.4 programmatically. I've tried it using IDE class but it is not accessible in eclipse 4.4. How can I do this?
回答1:
e4 only has parts, not editors and views. It also doesn't have any predefined text editors.
Assuming you want to have several editor parts open at the same time you need to define a 'Part Descriptor' in the application model for the editor.
You then create a part from the descriptor using:
@Inject
EPartService partService;
MPart part = partService.createPart("descriptor id");
You now need to add this to the application model. Usually this will be a child of an 'MPartStack':
@Inject
EModelService modelService;
@Inject
MApplication app;
MPartStack editorStack = (MPartStack)modelService.find("part stack id", app);
editorStack.getChildren().add(part);
Finally show the part:
partService.showPart(part, PartState.ACTIVATE);
The class you specify in the part descriptor for the editor will have to implement the text editor. You can use the JFace text editor classes but not the 'org.eclipse.ui.xxx' editor classes.
For a very simple text editor the TextViewer
and Document
classes are enough.
来源:https://stackoverflow.com/questions/28604569/how-to-open-a-text-editor-in-eclipse-4-4-programmatically