Need an Hello world example of how to add an item in the context/pop-up menu in eclipse plugin development.
(menu should pop-up when we right-click anywhere in the workspace).

Dani AI

Generated

As requested: you can add an Eclipse context-menu item from a plug-in (this is an Eclipse UI contribution, not an OS shell change — 's initial concern). The modern, recommended way is to declare a command + handler and contribute that command to a view's popup menu with the org.eclipse.ui.menus extension. Minimal "Hello world" example (plugin.xml fragments and a tiny handler) follows.

<!-- plugin.xml -->
<extension point="org.eclipse.ui.commands">
  <command id="com.example.helloworld.command" name="Say Hello"/>
</extension>

<extension point="org.eclipse.ui.handlers">
  <handler commandId="com.example.helloworld.command"
           class="com.example.helloworld.handlers.SayHelloHandler"/>
</extension>

<extension point="org.eclipse.ui.menus">
  <menuContribution locationURI="popup:org.eclipse.ui.navigator.ProjectExplorer">
    <command commandId="com.example.helloworld.command" label="Say Hello"/>
  </menuContribution>
</extension>
// SayHelloHandler.java
public class SayHelloHandler extends AbstractHandler {
  @Override
  public Object execute(ExecutionEvent event) throws ExecutionException {
    MessageDialog.openInformation(HandlerUtil.getActiveShell(event), "Hello", "Hello World");
    return null;
  }
}

Quick workflow: create a Plug-in Project in PDE, add the extensions above in plugin.xml, implement the handler class, add required dependencies (e.g., org.eclipse.ui, org.eclipse.core.commands, org.eclipse.jface), then Run As → Eclipse Application to test. Right-click in the Project Explorer to see the menu item.

Troubleshooting / notes: the menu appears only in the view whose popup id you used (here Project Explorer). To show the item in other views add more menuContributions (use each view's locationURI) or use an objectContribution/visibleWhen expressions to match IResource selections. If the item doesn't show, verify the commandId matches across commands/menus/handlers, the plug-in is active, and check the Error Log for classloading/activation errors. As mentioned, there are many tutorials if you need more depth, but the above is a compact, working starting point.

Recommended Answers

All 6 Replies

you mean the Windows popup on right click? how do you think to do something like that as an eclipse plugin?

inside eclipse workspace, if we right click, a pop-up menu appears. There i want to add a menu item upon clicking which my action gets executed.

don't really see how you plan to do this, nor how this would be an eclipse plugin, this is something you'll have to do in your OS.

That is the kind of thing that Eclipse plug-ins do, so I expect its not too hard (although I've never actually done it myself). There's loads of technical info for plugin developers on the Eclipse web site, plus you can look at the source code for existing plugins. It's nothing to do with the OS.

hmmm ... my bad, must 've misunderstood the question.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.