How to get from an EditPart to its Editor in Eclipse? (Eclipse plug-in development) - eclipse

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.

Related

Double clicking a resource in Eclipse Project Explorer does not open the second file

In an Eclipse based application (RCP), when double clicking on a file that appears in the project explorer, for the first file this will work – the associated editor will open. However, when double clicking again on a file, it will not open. If you click somewhere out of the Project Explorer and then return to the Project Explorer, then the second double click will work.
Note that right-clicking on the resource and selecting “Open” always works. In addition, in Package Explorer it always works.
I believe this is related to eclipse bugs 285239 and 256761.
Does anyone know of a way that I can overcome this problem, as the RCP developer. The file editor is a custom editor in one of my plugins.
The problem does not seem to happen to me with java files in standard eclipse for java development.
Thanks,
Eyal.
I solved the problem by implementing a setFocus method on the editor class. In the setFocus, I set the focus to some component. (To be precise in my case the editor was a subclass of SharedHeaderFormEditor so I set the focus to the active page).
The truth is that the specification of the setFocus method in IWorkbenchPart requires you to "assign the focus to one of the controls contained in the part's parent composite". It seems that the default implementation of setFocus in some cases did not do that (I don't know why, maybe I was missing something or for other reason).
Note that also setting focus explicitly to a control from within editor initializing partialy solves the problem.

How do I show all perspectives in my rcp project eclipse perspective bar (coolbar) upon startup?

Upon startup I only have the Open Perspective button and the default perspective that I set in method getInitialWindowPerspectiveId on its right. I want to show all my other perspectives on that coolbar.
Until now i tried:
config.ini file with org.eclipse.ui/PERSPECTIVE_BAR_EXTRAS=id1,id2,id3
plugin_customization.ini with org.eclipse.ui/PERSPECTIVE_BAR_EXTRAS=id1,id2,id3
in class ApplicationWorkbenchAdvisor in the initialize method someone said to do this:
PlatformUI.getPreferenceStore().setDefault(IWorkbenchPreferenceConstants.PERSPECTIVE_BAR_EXTRAS,"id1,id2,id3");
PlatformUI.getPreferenceStore().setValue(IWorkbenchPreferenceConstants.PERSPECTIVE_BAR_EXTRAS,"id1,id2,id3");
Nothing worked.
However i found a workaround:
in class ApplicationWorkbenchWindowAdvisor in the postWindowOpen i manually show all my perspectives. This leaves them opened in the coolbar. However this is not the optimum way and maybe someone knows the proper way to show all my perspective shortcuts on the coolbar.
PlatformUI.getWorkbench().showPerspective("id1", getWindowConfigurer().getWindow());
PlatformUI.getWorkbench().showPerspective("id2", getWindowConfigurer().getWindow());
PlatformUI.getWorkbench().showPerspective("id3", getWindowConfigurer().getWindow());
Thanks
The 'plugin_customization.ini' method should work
The 'plugin_customization.ini' file must be in your RCP plugin
The 'plugin_customization.ini' must be included in the build in the 'build.properties' file.

Jface TreeViewer nodes Link with files

I writing an eclipse plugin to analyze files for some defects, I get the list of java files, their classes and methods in a jface tree view, I need to open the file in the editor when I double click on the file node of the tree view.
please help me with this.
thanks,
Shasinda
You should either use a common navigator framework with corresponding filters that already has the link and open function built-in for Eclipse Resources, however, is much trickier to set up - see the blog post series starting with http://cvalcarcel.wordpress.com/2009/07/08/writing-an-eclipse-plug-in-part-1-what-im-going-to-do/
Alternatively, you could add a double click listener that opens an editor (or checks existing editors of the current workbenchpage) by looking the open editors. For the basic idea, see the corresponding Eclipse FAQ entry.
Use IDE.openEditor to open the editor.

Embedding a text editor within another Eclipse editor

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

How to capture CTRL+CLICK in a custom Text Editor

I got a custom editor by subclassing TextEditor in Eclipse plugin. I am trying to implement a CTRL+CLICK action(like 'open declaration' in java editor) in my custom editor. But I cannot figure out how to capture CTRL+CLICK. I tried to add a KeyListener to the editor's sourceViewer in its constructor or initialzeEditor(), which didn't work. Has anyone have an idea how to do this?
Thank.
Take a look at
extension point 'org.eclipse.ui.workbench.texteditor.hyperlinkDetectors'
classes org.eclipse.jface.text.hyperlink.AbstractHyperlinkDetector, org.eclipse.jface.text.hyperlink.IHyperlinkDetector and org.eclipse.jface.text.hyperlink.IHyperlink
If you need detailed examples, then take a look at plugin.xml of org.eclipse.jdt.ui. (You can get the source for org.eclipse.jdt.ui either from CVS or from Eclipse Classic SDK install)