adding icons to custom Eclipse editor hovers - eclipse

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).

Related

How to add elements to Outline panel in custom extension?

I have a VS Code extension for ST language support. Right now it provides only syntax highlights and some snippets. I wanted to create a tree structure of the document showing programs, functions and their parameters in the Outline panel. But I cannot find an example of how to do that.
Can you refer me to the right direction but not to LSP as it is too complicated for now I want to make it programmatically.
The outline view is populated by a DocumentSymbolProvider (see also: registerDocumentSymbolProvider()). In the language server protocol, this corresponds to the textDocument/documentSymbol request.
All in all, it currently provides the data for all of these:
Outline view
Breadcrumbs
Go to Symbol in File
You can find an example implementation of one here, though you'll want it to return DocumentSymbol rather than SymbolInformation instances. Only the former supports the hierarchy needed for the outline view via it's children property.

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.

How to add an Eclipse CompareEditor inside a View?

How can I open an Eclipse CompareEditor inside a View?
More specifically, I want the view to contain a SashForm. In the left sash I put some information about the commit, and in the right sash I want to put a compare editor that compares the commit to its parent. Is there such a thing even possible?
I've succeeded in using a GitCompareEditorInput from eGit and the CompareUI class to open a separate compare editor or a dialog with the compare editor (that compares a certain commit to its parent). But now I am interested in putting that compare editor inside another view, as detailed above.
Thanks
Update:
I have tried CompareEditorInput.createContents(compositeParent) but I only get two empty rectangles.
The key to hosting a CompareEditorInput class appears to be providing a class which implements org.eclipse.compare.ICompareContainer. Once you have this you connect it to the input using CompareEditorInput.setContainer(container).
org.eclipse.compare.internal.CompareContainer provides a partial implementation of the container but this is internal so should only be used as a guide rather than used directly.

GWT Editors for readonly and edit mode

GWT's Editor framework is really handy and it can not only be used for editing POJOs but also for read-only display.
However I am not entirely sure what the best practice is for doing inline edits.
Let's assume I have a PersonProxy and I have one Presenter-View pair for displaying and editing the PersonProxy. This Presenter-View should by default display the PersonProxy in read-only mode and if the user presses on a edit button it should allow the user to edit the PersonProxy object.
The solution I came up with was to create two Editors (PersonEditEditor and PersonDisplayEditor) that both added via UiBinder to the View. The PersonEditEditor contains
ValueBoxEditorDecorators and the PersonDisplayEditor contains normal Labels.
Initially I display the PersonDisplayEditor and hide PersonEditEditor.
In the View I create two RequestFactoryEditorDriver for each Editor and make it accessable from the Presenter via the View interface. I also define a setState() method in the View interface.
When the Presenter is displayed for the first time I call PersonDisplayDriver.display() and setState(DISPLAYING).
When the user clicks on the Edit button I call PersonEditDriver.edit() and setState(EDITING) from my Presenter.
setState(EDITING) will hide the PersonDisplayEditor and make the PersonEditEditor visible.
I am not sure if this is the best approach. If not what's the recommended approach for doing inline edits? What's the best way to do unit-testing on the Editors?
If you can afford developing 2 distinct views, then go with it, it gives you the most flexibility.
What we did in our app, where we couldn't afford the cost of developing and maintaining two views, was to bake the two states down into our editors, e.g. a custom component that can be either a label or a text box (in most cases, we simply set the text box to read-only and applied some styling to hide the box borders).
To detect which mode we're in, because we use RequestFactoryEditorDriver (like you do), we have our editors implement HasRequestContext: receiving a null value here means the driver's display() method was used, so we're in read-only mode. An alternative would be to use an EditorVisitor along with some HasReadOnly interface (which BTW is exactly what RequestFactoryEditorDriver does to pass the RequestContext down to HasRequestContext editors).
Yes,Presenter-View pair should be. But Here two ways to achieve this feature if you like to go with:
1) Integrate Edit/View code design in one ui.xml i.e.Edit code in EDitHorizonatlPanel and View code in ViewHorizontalPanel.The panel has different id. By using id, show/hide panel with display method. if getView().setState() ==Displaying then show ViewHorizontalPanel and if getView().setState()==Editing then show EditHorizontalPanel.
2) Instead of using labels, Use textboxes only. set Enable property is false when you need it in view mode otherwise true
You have created two Presenter/view but I think if Edit/View function has similar code so no need to rewrite similar code again and again for view purpose.
If a big project has so many Edit/View function and you will create such type of multiple View/Presenter than your project size become so huge unnecessary.
I think that whatever I have suggest that might be not good approach but a way should be find out which help to avoid code replication.

Toolbar items dynamically

I need to create dynamically buttons in main toolbar. I found a solution, but I can create just one button (dynamic contribution item - class extending ContributionItem). But I need to create more than one button, but I cannot find the solution.
I'm fighting with task to create plugin, which parses a XML file containing structure of menu and toolbars. We've already done this plugin for Visual Studio. Its quite easy in principle, but I found swiftly, that not for Eclipse. There is one small but critical otherness. Plugins are implemented declaratively in Eclipse. The file plugin.xml is the gist of plugin's infrastructure, Java code is just ancillary.
The customer wants to refresh the menu and toolbar whenever the selected project is changed. Eclipse lacks several features needed to get the task done. Main menu and main toolbar are cteated at Eclipse's start-up and then they can be hardly rebuilt.
In the most cases the conditions defined at enabledWhen/visibleWhen elements are sufficient to filter contributions according to the context (active part, selected object, whatever else).
If you need to have more freedom, please try E4 ToolControl that allows you to implement your own UI elements:
#PostConstruct
public void createControls(Composite parent) {
//your custom code here
}
More details here https://www.vogella.com/tutorials/EclipseRCP/article.html#toolcontrols
From my understanding you want to have different buttons on the main toolbar depending on the selection of the project explorer (eg. 1 project is java project, the other is javascript etc.). First you will have to contribute to the main toolbar. I think there are some tutorial available so google will help.
The main steps are:
1. create a command (org.eclipse.ui.commmands)
2. create a handler (org.eclipse.ui.handlers) with the previously declared command id
3. contribute to the main toolbar (org.eclipse.ui.menus) with menucontribution and commandId with the following locationURI: toolbar:org.eclipse.ui.main.toolbar?after=misc
showing/hiding, enabling/disabling a menu item/button also can be done declaratively or "mixed". Declaratively means eg. using enabledWhen/visibleWhen...
Mixed means using property tester (org.eclipse.core.expressions.propertyTester). With this you can define your "enablement logic" in Java code.
In Eclipse e4 the UI is generated from a, EMF based, model. The Application.e4xmi serves as a base for that model. Contributions to the model can be done via fragments, which are again XML, or via processors. Processors are written in Java and use e4 services, like the part service, to modify the model at runtime.
I think you want to write a processor that parses your custom XML and modifies the eclipse e4 model accordingly.