Context sensitive menu in eclipse editor - java

If I use eclipse and right click on a part of Java source code, the context menu depends on the syntactic element the user clicks on (like: a method, a variable,...).
How can I implement this kind of behaviour in my own eclipse plugin, e.g. add an item to the context menu only if the user clicks on a method in Java source code. Furthermore, the plugin needs to know which method the user clicks on.
I guess I have to relate the clicking position to the abstract syntax tree that eclipse builds but I have no idea how to do that.

You do this with Eclipse Commands and you can enable them and change their visibility in many ways, depending on selection, global state, etc.
I guess I have to relate the clicking position to the abstract syntax
tree that eclipse builds but I have no idea how to do that.
The good news is you (generally) don't have to do that, Eclipse has done all that heavy lifting for you.
It is quite a broad subject, so I suggest working through some tutorials on Commands first:
Adding menus, toolbar and popup menus to the Eclipse IDE - Tutorial
Eclipse Commands Advanced - Tutorial

Related

How to remove file type submenus from the "new" context menu in Intellij IDEA

I'm particularly interested in removing the "Java Class" submenu as Kotlin is more relevant to my needs. Although I know you can attach keybindings to controls, this would be convenient for me as I prefer to use my mouse to operate the IDE. Is there any way to do this?
I'm using the latest IDE version.
You can't remove it right now, please vote for this request.

Source Editor in Eclipse plug-in

I'm developing an Eclipse plug-in, mostly as a learning exercise, in which I have a wizard page. In this wizard page I would like to have a small text area that behaves like a code editor with the appropriate content assist and information hovers etc, much like the breakpoint properties wizard has for adding conditions.
I'm new to plug-in development and I may not have quite picked up the vocabulary, so I'm not having much luck searching for examples. Can someone please point me in the right direction?
I assume that you are looking for an embeddable Java source editor - and with that you hit a difficult topic.
The source viewer mentioned by Chris Gerken is called JDISourceViewer. It is instantiated and configured in JavaBreakpointConditionEditor::createControl.
If you cannot find the mentioned classes, or if you want to experiment with them, then open the Plug-ins view, find the org.eclipse.jdt.debug.ui plug-in and select Import As > Source Project from the context menu.
Unfortunately - in the beginning - the (Java) editors weren't designed to be embedded outside of the editor area and many editor participants (e.g. actions, formatter, etc) still expect an IEditorPart. Hence it is a quirky and complicated endeavour to use an editor in a dialog or the like.
Moreover, the Java source editing infrastructure is not exposed as public API. It isn't meant to be used by clients and can change at any time without prior notice. You will see respective warnings in yoyur code. For a learning exercise, however, that shouldn't matter much.

Eclipse Plugin Development: Extending default Java Editor/Text Hover

I've been trying develop my custom plugin for Eclipse, and basically I want to make is a "richer" version on the current TextHover. I don't know what widget(?) Eclipse uses to display the hovering text, but I want to use something different, like SWT Image or SWT Browser.
Most of the tutorials that I've read suggest that I have to implement my own Java Editor to do this, but I don't want the user to switch to my custom editor just for a simple feature (and I don't want to implement a whole editor).
Some Tests:
I've already created two Eclipse Plugin Projects. The first one is a extension for the JavaEditorTextHovers, and with this project I managed to show some custom Strings when hovering some random texts, but wasn't able to change the hover appearance. The second project was a editor plugin. With this last one I managed to get a Browser to appear when hovering a random text(this tutorial helped me), but again, this editor had nothing, no syntax coloring, no rules, etc., and for the previous reasons, I couldn't accept this has a solution.
Maybe if there was way to change the (or set a new) SourceViewerConfiguration of the current editor I could pass my custom SourceViewerConfiguration, but I'm not sure if this is possible.

Programmatically call menu item with Eclipse JDT, Plug-In Development

I've been trying to figure out for a while now how to call an Eclipse menu item from within a plug-in that I'm developing. Say, for the sake of this posting, I want to call the eclipse "Format" menu item in the Right Click Menu to format a source, how would I go about doing this by calling that item (i.e. not just mimicking that menu item's effect, actually calling it)?
I'm not looking for how to format code, just simply the idea of calling a menu item.
I was leaning towards the APIs info on IWorkbench, Shell, ToolBar, ToolItem, etc., but I don't really know. I haven't been able to find anything on this topic in the APIs or anywhere else online. Is there a better approach to doing this rather than programmatically?
Eclipse JDT - http://help.eclipse.org/indigo/index.jsp?nav=%2F3
EDIT:
String commandId = "org.eclipse.jdt.ui.edit.text.java.format";
IHandlerService handlerService = (IHandlerService)(IHandlerService ) PlatformUI.getWorkbench().getService(IHandlerService.class);
handlerService.executeCommand(commandId, null);
Simple as that. The hardest part is finding the commandId, which can be easily searched for, as rlegendi mentioned. This is exactly what I wanted. It accesses that plugin via ID, then executes it. Simple and effective. Thanks everyone!
I'm not sure but probably what you want to read about is the Command/Delegate framework.
BTW if you install the Eclipse Platform SDK plugin (available by default), you can actually take a look on the source code of any plugin that is the part of your current Eclipse product (try Ctrl+Shift+T and typing ISourceViewer for instance, there you find the FORMAT it, for which you can do a search with Ctrl+Shift+G), and you can import any of those plugin projects to your own workspace to examine.

How to customize a toolbar in Eclipse?

I am trying to customize Eclipse to speed up development and minimize distractions for Android Java development.
I am using SourceGear Vault for source control and installed the plugin for Eclipse. So to check stuff in/out, I have to right click on the Project/File, go to Team submenu, then pick a source control command (Check In, Check Out, Get Latest, etc...). I find this process slow. I'd like a button on the toolbar and a keyboard shortcut to do these operations.
I tried going to Customize Perspective, but under Team toolbar, there is only Synchronize command.
And I have no idea how to setup a shortcut for the SCC operations either as they are not present in Shortcuts tab.
Am I missing something simple?
(Revised)
Look in the Command Groups Availability tab of the dialog you get when you do the Customize Perspective and you should see an entry related to your VCS; turn this entry on and then go back to the Toolbar Visibility and you should see more stuff (under the name of the VCS). The Team area is not going to have what you want; the commands are grouped by the VCS name, like git, SVN, etc.
Sorry for the initial answer, I mis-read part of your question.
Eclipse Photon
Window
Perspective
Customize Perspective
Now you can check and uncheck checkboxes to customize the buttons that show up.
Tested on Photon Release Candidate 3 (4.8.0RC3).
I find that if you are currently using a base perspective that comes standard with the Eclipse install you need to: "Window -> Save Perspective As..." first. Then you can just customise the tool bar as you please.

Categories

Resources