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?
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.
Related
I am working on Graphical Editor i.e (GEF Editor). Files having .graph extensions opens in Graphical Editor and on save action of editor it generates some xml and properties files. Now, my use-case is to achieve the same functionality to generate ".graph" related xml and properties files even if anyone edits ".graph" file using eclipse default text or xml editor.
Is there any way to achieve it?
You can use ResourceChangeListener
IResourceChangeListener listener = new IResourceChangeListener() {
#Override
public void resourceChanged(IResourceChangeEvent arg0) {
System.out.println("Text changed");
}
};
ResourcesPlugin.getWorkspace().addResourceChangeListener(listener);
I have an eclipse RCP application that uses and Editor Area. I have a few things that I would like to do programatically but cannot find any documentation:
1) Do not restore editor sash layout. I.e., I like to use rcp saveAndRestore functionality, but for my perspectives, views, and other momentos. I do not however want to restore the editor area multiple tab groups at all. I choose not to implement the IPersistableEditor interface, and therefore my editor sessions are not restored, but when my application restarts, it still has split windows (swt sashes for multiple tab groups), etc, and i wish it was just 1 editor area tab group like default.
2) I would like to programaticaly split/duplicate an editor into another tab group, for example I would like a button that says "Split Horizontal" and that opens a new editor in a new tab group beside the current one.
Any help is much appreciated! Happy Coding!
/P
1) Funny, seems like a bug in the platform.
You can explicitly close all editors upon workbench window close. One option to do this would be to override the preWindowShellClose method in your WorkbenchWindowAdvisor:
public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor {
#Override
public boolean preWindowShellClose() {
getWindowConfigurer().getWindow().getActivePage().closeAllEditors(true);
return super.preWindowShellClose();
}
}
If you don't have access to the ApplicationWorkbenchWindowAdvisor, you can try to do the same with the IPerspectiveListenerX
2) I think there is no public API for this. The editor area behavior is defined in the presentation factory (see org.eclipse.ui.presentationFactories extension-point). You could clone the RCP standard presentation and implement the desired split-editor-area-on-demand functionality.
Is it possible to embed a text editor (with syntax coloring and content assist) within my own custom Eclipse editor? I am under the impression that a text editor (with features like syntax coloring) needs to extend IEditorPart or one of its subclasses, but am I correct in thinking that an IEditorPart subclass can't be embedded because it's not part of Eclipse SWT? And if that's true, is there another way to get that functionality?
To expand on this "custom Eclipse editor": I'm referring to an editor with multiple tabs, and in one of the tabs I want to embed a text editor with syntax coloring, and possibly content assist.
Yes, using a MultiPageEditorPart, where every page is either an IEditorPart or an SWT control. Keep in mind that the text editor you're embedding has to have been written to still function correctly in that situation.
Right, you cannot embed IEditorPart, instead you could inherit your editor from a concrete IEditorPart implementor and override custom aspects thereof.
You can add your editor to MultiPageEditPArt.
final IEditorPart = new YourEditor();
int editorIndex = addPage(formJSEditor, editorInput);
setPageText(editorIndex, "Your Editor");
I am trying to implement an Eclipse editor which consists of a design part, Palette part and the Properties part for the selected palette item. All in the same editor page.
After a long time of googling, I have come to know that there are no proper articles or examples for this issue. Is there some solution that I could get from anyone here?
The SWT Design editor implements this feature in its editor. However, I am unable to access its source.
To access the properties view, you have to have three things:
Your editor must define its SelectionProvider (getSite().setSelectionProvider()). A SelectionProvider is either a JFace Viewer, or can be any class that return a corresponding ISelection interface.
The objects returned by the ISelection must either implement IPropertySource or return an IPropertySource adapter using the getAdapter(IPropertySource.class).
In multi-page editors you have to make sure, that the SelectionProvider also returns what expected.
For details about the first two point, see the following Eclipse Corner article: Take control of your properties, or if you would like to use the Tabbed properties view seen in GMF editors, The Eclipse Tabbed Properties View.
I am writing an eclipse plug-in that extends editor. Inside the editor I put some EditParts. From some of these edit parts I need a reference to their encapsulating editor (so that for example, when clicking an instance of MyEditPart, I want to programmatically close the editor).
Please advise on the API to get from an EditPart instance to the Editor it is in.
Thanks.
You can try:
IEditorPart editor = ((DefaultEditDomain) getViewer().getEditDomain()).getEditorPart();
from the EditPart.