How to implement Quick Fix / Quick Assist for custom eclipse editor? - eclipse

I have extended org.eclipse.ui.editors.text.TextEditor to implement a custom editor.
For this editor, I have defined a marker type (org.eclipse.core.resources.markers extension point) and an annotation type (org.eclipse.ui.editors.annotationTypes extension point) to mark specific parts of code in my editor. I use a reconciler to update my annotation model.
Now I want to add a quick fix / quick assist feature. I simply want eclipse, to show a box with proposals, when I hover over an annotated part of the code and replace that part with a given string, when I click on a proposal. Just like the quick fix feature for the java editor.
So, what is the best way to implement this behavior?
I read about marker resolution generators and quick assist processors, but I'm still confused how it all works together...
I would be glad, if someone could point me to the right direction.
EDIT: From what I've understood so far, a MarkerResolutionGenerator is responsible for showing quick fixes in the problems view. To get quick fixes in the source viewer, I would have to set a QuickAssistAssistant for my SourceViewer and implement a QuickAssistProcessor which returns CompletionProposals.
Is this the right way to do it?
EDIT2: I'm wondering if I need Markers at all, or only Annotations, I'm confused...

I finally found out how to get Quick Fix to work for my editor.
I use the annotationTypes extension point to register my own annotation type and the markerAnnotationSpecification extension point to specify the look and feel. In my custom SourceViewerConfiguration class I override getAnnotationHover(...) to return a DefaultAnnotationHover object and getTextHover(...) to return a DefaultTextHover object, so the annotations are shown in my source viewer.
Then I override getReconciler(...) to return a MonoReconciler with my own implementation of IReconcilingStrategy to create the annotations in its reconcile(...) method. And finally I override getQuickAssistAssistant(...) to return a QuickAssistAssistant with my own implementation of IQuickAssistProcessor. The computeQuickAssistProposals(...) method in the processor class computes the quick fix proposals which show up, when I press CTRL+1.
I don't create any Marker objects and don't use a MarkerResolutionGenerator, since the marker concept is much more heavyweight than using only annotations and the functionality which annotations provide fits my needs.

You have to register an extension to the extension point org.eclipse.ui.ide.markerResolution. This extension refers to a markerType (using the markerId), and also a resolution generator.
The latter component is responsible for calculating the possible fixes: it reads the marker, it can check the related files, etc., and creates marker resolution instances. These resolution instances basically process the erroneous files, and hopefully fix the original problem.
During marker resolution, you should not worry about removing the markers, as after the fix is executed, sometimes the validation would run again (e.g. during the build, or if no automatic validation is available, then manually - but it is not the task of the marker resolution to update the list of markers).

Related

eclipse RCP4 Add Toolbar to Parts

How to model a toolbar ONCE and render it in some Parts/Views (not in the default place which is the window!)? Using the model level (and maybe Addons?)
I have currently
Eclipse 2022.03-4.23
Application.e4xmi with that Toolbar but
Gets added dynamically using an Addon that listens to "PART_ADDED" event topic which
Leads to a NPE due to other event topic "UIEvents.Part.TOPIC_TOOLBAR" within a framework method in a class called LazyStackRenderer
So the guy before me had written an Addon to dynamically add the Toolbar to the parts. Maybe to make the buttons save/print per part or because the main layout has two stacks and only the parts stack is relevant.
Appreciate any help! I searched a lot but no success!
I solved it so far. The dynamically created MParts were not added as children to the container (in my case the PartStack) in the first place and also had to comment the adding of placeholder objects that carry the same information of the parts. This dynamic step was done as a reaction to the topic #UIEventTopic(UIEvents.UILifeCycle.APP_STARTUP_COMPLETE) in some written Addon.
I am not a 100% sure that discarding the placeholders is safe but still this is the best trail I have ever reached.
I hope this would help others!
Thank you #greg-449

How to make IntelliJ IDEA highlight the implemented methods of an interface

In Eclipse, when I put the caret on an Interface a class is implementing, the methods are marked in the side bar by default (as small colored stripes). This way I can easily see the methods the class is implementing without having to go into the interface itself and check out what methods it contains
I haven't found anything similar in IntelliJ. Is this even possible somehow easily?
(As a side note, I use Kotlin when programming, but I assume that this feature is not found for Java either)
In Java, you can put the caret on the "implements" keyword and press Ctrl-Shift-F7 to highlight methods implemented via an interface (if the class implements multiple interfaces, you get a popup asking you which methods to highlight). An equivalent feature for Kotlin is not implemented at this time (as of Kotlin 1.3).
In the class body, you can indeed see the interface methods highlighted by gutter icons, as the other answer says.
Methods or properties that are overriding or implementing anything of a parent class or interface are marked next to the line numbers, finding out from which class or interface they are coming can be done by hovering over them:
Clicking on it will take you to the parent/interface definition.
The same mark, but with a downwards pointing arrow, is used in the interface/parent class and shows a list of implementations/overrides when clicked on.
All of this also works for java and scala.

adding icons to custom Eclipse editor hovers

I've created my own extension to DefaultTextHover within my custom Eclipse editor, and wanted to add icons to the hover -- similar to what the JDT does when I hover over a program element.
Currently, my implementation of getHoverInfo returns the appropriate String for the hover itself. But I would like the hover to also contain an icon -- similar to what I'm already using in my editor's outline.
How can I do this?
You need to make your extension to DefaultTextHover implement ITextHoverExtension which adds the new method getHoverControlCreator. This method returns a IInformationControlCreator which is used to create the IInformationControl which is used to display the hover information.
IInformationControl creates the hover and can interpret the hover text any way it wishes (as HTML for example).
There is a DefaultInformationControl implementation of IInformationControl available which does a lot of the work for you. This requires you to provide a class implementing DefaultInformationControl.IInformationPresenter and DefaultInformationControl.IInformationPresenterExtension.
There is an internal JFace class HTMLTextPresenter which can be used as an example for implementing the information presenter (since this is internal you should not use it directly).

Using an EditorPart inside a Composite

I'm new to RCP and I'm trying to create a new View or Editor. At the current state I'm extending ViewPart.
The Layout I want to achieve is a SashForm where both sides have a CTabFolder. One of the sides of the SashForm is basically a MultiPageEditorPart. One of it's tabs should be an editor for a specific language with syntax highlighting and similar features. From what I understand I could extend AbstractTextEditor for that (and maybe use it as one tab of a MultiPageEditorPart).
If I try to achieve this layout with a ViewPart as top level container which contains a SashForm, I can't add an EditorPart to one of the sides of the SashForm. Of course I could implement this editor from scratch as Composite but I want to avoid that.
I am also willing to use an EditorPart or MultiPageEditorPart as top level container but then I'd have to find a way to get the SashForm layout working. The whole editor should be splited first and then each side should have tabs.
Does anyone have an idea how to solve this?
If anything is unclear please ask. I've got the feeling I've put this into words a little complicatedly.
I think you should just make a ViewPart that has a text editing component of some kind on the left, instead of trying to find a way to use an EditorPart. All that EditorPart is really buying you is dirty flag management and Save support; syntax highlight and so forth you can add to the text editing component yourself (I was surprised at how few drop-in text components I found while poking around the internet just now; I expected to find "a few" and instead I found "basically none").
You can see one way to do very rudimentary syntax highlighting with a StyledText component here: JavaSourceCodeViewer
To see a more robust implementation of things like syntax highlight and autocomplete, take a look at the class that Eclipse uses for the editing of Java source code: CompilationUnitEditor
I think what you are trying to achieve is quite complicated and might require a lot of extra work. See an editor is not just different controls laid out in some order, but it has a lot of additional features that any editor class expects to work. These include things like selection service and action bars etc, that you will need to hook in to ensure smooth running.
That said, it should be possible to achieve what you are hoping for. You can have a look at the source code of the MultiPageEditorPart itself to see how it converts a single editor into a multi page editor, which is capable of hosting a completely independent editor on each of its pages. You would need to achieve something similar if you want your editor to host two MultiPageEditorParts separated by a sash. If you want to carry on, you should start implementing some stuff and if you run into any problems, post them here. You would be able to get a lot better help then.
You need something like MultiPageEditorSite. Use it for inspiration when implementing an EditorSiteDelegate. MultiPageEditorSite has support for separate keybindings between the pages, for example.
class ChildEditorSite implements IEditorSite {
IEditorSite parent;
public Object method() {
return parent.method();
}
}
Using this class, you can easily do the following in your main EditorPart:
class MyCoolPart extends EditorPart {
public void createControl(Composite parent) {
EditorPart child1 = new MyChild();
child1.init(new ChildEditorSite(getEditorSite()), myInput);
EditorPart child2 = new MyChild();
child2.init(new ChildEditorSite(getEditorSite()), myInput);
child1.createPartControl(parent);
child2.createPartControl(parent);
}
}
Be sure to also dispose of your children correctly when you dispose of your MyCoolPart. Please note that this only works in the most basic of cases. An EditorPart that is a DocumentEditor or that relies on IPersistablePart or implements listeners/adapters for confirming a save is probably going to require a lot more Lifecycle management...

Show annotation in custom views

First off - I'm not using MapKit. I'm using my own controls for something entirely different. But the annotation view is something I'd like to mimmic. I've seen other applications with similar views to indicate state or actions on other controls. However, scanning through the class library I can't find a view already in the SDK. Do I have to create my own custom view that mimics this look and behavior or does the iPhone provide a standard way of showing these annotations?
You have to create your own (or find an open source implementation). The annotation views are actually drawn by the map view so they don't work outside of a map.
Well I couldn't find an open source solution so I built my own. To save anyone else the trouble, the source can be found at
http://github.com/appsinyourpants/Pants-Framework/tree/master/Classes/Views/