How to extend Eclipse's compare context menu? - java

I want to create a plugin that displays additional information about Eclipse's compare results. For example, clicking a difference in Eclipse will bring up additional meta-information in my new view about who made the change, when it was made, what are the related changes, etc. I've got everything else figured out except how to call the view from the compare editor. I am thinking of using a context menu.
I was able to implement a context menu for the text editor. I used a targetID of targetID="#TextEditorContext and the action to inherit from IViewActionDelegate. But somehow the compare editor is not the same as the normal text editor. What targetID should I use? Is this even possible? Or if someone has a better idea than context menu, do share.

I was able to add additional commands (Handlers) to the compare view's context menu using the popup menu id popup:org.eclipse.compare.CompareEditor?after=additions

Related

getTitleTooltip method is not getting called once we mouse over in an Eclipse Editor

I have a RCP application where I implemented an Editor by following way-
public class CheckView extends EditorPart implements IMessageView,IViewPart {
Now I override the method getTitleToolTip() method and did some operation which will give different tooltips on different conditions. But the problem is , only once the getTooltip method is getting called , when we launch the RCP tool. But it should always get called whenever we mouseover the editor.
Whats going wrong here?
The documantation of IWorkbenchPart#getTitleToolTip() is quite specific:
Returns the title tool tip text of this workbench part. An empty string result indicates no tool tip. If this value changes the part must fire a property listener event with PROP_TITLE.
The tool tip text is used to populate the title bar of this part's visual container.

How do I show quick fixes when I hover over an error in my custom editor

I've written an eclipse editor for my own DSL. When an editor is opened or saved I check the contents and create problem markers for any syntax errors. The markers show up in my editor as expected, and also in the Problems view.
I've got an extension point org.eclipse.ui.ide.markerResolution and provide an implementation of IMarkerResolutionGenerator which creates resolutions for problem markers. This works fine; when I right click a problem in the Problems view the Quick Fix option shows in the context menu and works fine.
My editor extends SourceViewerConfiguration and I override getQuickAssistAssistant(), returning an extension of QuickAssistAssistant. This allows me to right click a problem in the editor and see the Quick Fix option in the menu.
I'd really like to get the quick fix resolutions to appear when I hover over the problem in the editor, just like in the java editor. Currently just the problem text appears in the tooltip. Is there a seperate hook into this or should it be covered in two quick fix hooks I've already implemented?
I had the same problem and found a solution for myself: How to implement Quick Fix / Quick Assist for custom eclipse editor?
From what I've understood, Markers show up in the Problems View and Annotations show up in the editor (on the ruler and on mouse hover).
I use the org.eclipse.ui.editors.annotationTypes extension point to register my own annotation type and the org.eclipse.ui.editors.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.
To create annotations, you could use org.eclipse.ui.texteditor.SimpleMarkerAnnotation, you can construct a SimpleMarkerAnnotation passing a marker object to the constructor.
Then you need to add the annotation to the annotation model. You can use getAnnotationModel() on your SourceViewer and then addAnnotation(Annotation annotation, Position position) on the AnnotationModel. All annotations in the model will be shown in the editor.
You could also use org.eclipse.ui.texteditor.AbstractMarkerAnnotationModel as your annotation model. Then you won't need to create annotation objects first, since AbstractMarkerAnnotationModel provides a method addMarkerAnnotation(IMarker marker).
Have a look at the IAnnotationModel interface.

CNF: Remove SOME popup options (from the ones that are platform contributions)

I need to modify popup menus using CNF. I already read documentation about using action providers and about using "allowsPlatformContribution" to restrict options that are platform contributions. I already used some of these concepts sucessfully to add/remove popup options. But there is one thing I need to do and I don't know how:
Related to PLATFORM CONTRIBUTIONS, I mean declared by org.eclipse.ui.popupMenus (in my case they are standard options: "Validate", "Run As", "Debug As", "Profile As",
"Team", "Compare With", "Restore from Local History...", "Java EE Tools", "Source", "Configure") I just want to show two of them: "Team" and "Compare With" (with all their suboptions).
If using "allowsPlatformContribution=false", then ALL options are removed !. The only idea I have right know is to set this to false and to create an actionProvider for each of both options I need to show, but it seems a bit hard, because I have to add all the suboptions
in it (invoking the appropriate Eclipse action) !. Is that a good way to solve my problem ?. There is another way easier and better ?... I hope so.
Please help. Thanks a lot.
Rosa.
You can use Activities to show/hide elements in the user interface (including menus).
What you have to do is create an Activity and bind it to the UI element. Then, when you enable/disable your activity the platform will automatically show/hide the element bind to it.
For more details on the exact implementation, check out this page:
Eclipse Activities – Hide / Display certain UI elements

How do I get the caller(s) of a method without running this system (written in JAVA)

In java, How can I get the caller(s) of a method without running this system.
My purpose is to find the callers of some methods (around 150 methods) and want to get
the name of all callers of each method. Is it possible to do that?
Is there possible way to do it ( that is not to use call hierarchy or reference in Eclipse because I need to find the callers of many methods and record it to my excel file.)?
Thank you very much.
In Eclipse, you can do this by right-clicking the method, and choosing "Open Call Hierarchy".
Also, in Eclipse, you can do this by right-clicking the method, and choosing "references" -> "XXX"
As David mentioned, this is called the Call Hierarchy. You can access it from the right-click menu, or just use the keyboard shortcut: put your cursor on the method name, then press Ctrl + Alt + H.
In Eclipse, you can do this by right-clicking the method, and choosing "Open Call Hierarchy".
See 5 options given on right side top of that panel (Refresh) (Cancel Current Search) (Show Caller Hierarchy) (Show Callee Hierarchy) (Show History List)
For You the 3rd option will work..
In eclipse you can right click on the method name and click 'Open Call Hierarchy'. Another panel opens and select 'Open caller hierarchy'
Bit late to the party, but based on your updated question and comment, you want to retrieve the names of all callers of multiple methods in one go (and not have to do the same thing, i.e. open Call Hierarchy, 150 times) and end up with something in a format you can use in a spreadsheet.
Here's how to do that with Eclipse for anyone facing the same issue (as I did recently):
Get all the methods whose callers you're interested in into the same view. If they're all in the same class, the Outline view will do, otherwise do a search and get all your methods to show in the Search results view - you can specify all sorts of interesting criteria in there, in your case you might want to search for methods in selected resources (select your classes in the Package Explorer first).
Select all the methods whose callers you're interested in in that view. Hold down Ctrl and click to multi-select, or do Ctrl+A to Select all and then de-select the ones you don't want with Ctrl+Shift+Click.
Open the Call Hierarchy on all those methods. Either drag those selected methods onto the Call Hierarchy view, or use Ctrl+Alt+H, or use the context menu. This will show all the callers of all those methods. (If you want to dive deeper, expand as required to retrieve callers of callers, etc.)
Select all in the Call Hierarchy view. Just do Ctrl+A while the view has focus.
Copy the methods' qualified names to the clipboard. There's no keyboard shortcut for this by default, but you can right-click on the selected files and select Copy Qualified Name. You'll end up with a bunch of lines of the format <package name>.<class name>.<method name>().
Paste into your favourite text editor or spreadsheet and manipulate as required.
Tested in Eclipse neon.
In Netbeans, right click on the method and go to "find usages". Alternatively, click on the method name and then hit alt+F7.
EDIT: Oops, just seen this is tagged for eclipse and not netbeans. Still, I'll leave it here in case it's useful.

Eclipse RCP update a View after changes in the editor

i am new to Eclipse RCP and have the following Scenario:
One plugin which is the Application
Another witch is a view and does show
some Data
And a third which is the
editor.
in the view I can right click on a record and choose edit what does open the Editor and lets me change the data.
No I'd like to refresh the View when I save the Editor. I think this is a classical scenario to implement a Whiteboard pattern. Unfortunately I am not really familiar with it, may be some one could show a simple example how to implement it in Eclipse RCP.
Thanks in Advance
Johannes
Your view needs to implements IPartListener2 (http://help.eclipse.org/helios/index.jsp?topic=/org.eclipse.platform.doc.isv/reference/api/org/eclipse/ui/IPartListener2.html)
you can override the method partInputChanged(IWorkbenchPartReference partRef) to refresh thw view in two ways:
1) If the plug-in with view has dependency to plugin with editor
If (partRef instanceOf YourEditorClass){
YourData yourData = editor.getInput().getxxx();
}
2) If the plug-in with view doesn't have dependency to plugin with editor
you need to use an adapter. You override the getAdapter method in the editor to return the Data that you need and the view get the data from the adapter
If (partRef instanceOf EditorPart){
YourData yourData = Platform.getAdapterManager().getAdapter(this, YourData.class);
}
Two codes are just an example to show the idea!
I hope I helped you
The view has to listen to the editor or - even better - to the edited model. If it listens to the editor, look for some "save" events. Personally I would make the model itself observable and notify listeners (like your view) of actual changes.
The view then needs some logic to extract its information from the model. So instead of a whitboard - the observer pattern should be the right choice for your design.
This is worth a try: add an IPropertyListener to the IEditorPart instance of your editor and wait for property changes. The IEditorPart.PROP_DIRTY property should change from "is dirty" to "is not dirty" after a save. Snippets/code example for eclipse rcp stuff are hard to develop and to communicate. Use the buzzwords from my answer for some searches on the eclipse help, API and on google. And: good luck ;) - btw, consider buying some good books on eclipse plugin/rcp development, they're worth every €/$ spent.

Categories

Resources