Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>First, let's create a popup menu for PackageExplorer View.</p> <pre><code> &lt;plugin&gt; &lt;extension point="org.eclipse.ui.commands"&gt; &lt;command categoryId="TestPopupMenu.commands.category" id="TestPopupMenu.commands.sampleCommand" name="Sample Command"&gt; &lt;/command&gt; &lt;/extension&gt; &lt;extension point="org.eclipse.ui.handlers"&gt; &lt;handler class="testpopupmenu.handlers.SampleHandler" commandId="TestPopupMenu.commands.sampleCommand"&gt; &lt;/handler&gt; &lt;/extension&gt; &lt;extension point="org.eclipse.ui.menus"&gt; &lt;menuContribution locationURI="popup:org.eclipse.jdt.ui.PackageExplorer"&gt; &lt;command commandId="TestPopupMenu.commands.sampleCommand" id="TestPopupMenu.menus.sampleCommand" mnemonic="S"&gt; &lt;visibleWhen&gt; &lt;with variable="activeMenuSelection"&gt; &lt;iterate ifEmpty="false"&gt; &lt;adapt type="org.eclipse.core.resources.IResource"&gt; &lt;test property="org.eclipse.core.resources.name" value="*.*" /&gt; &lt;/adapt&gt; &lt;/iterate&gt; &lt;/with&gt; &lt;/visibleWhen&gt; &lt;/command&gt; &lt;/menuContribution&gt; &lt;/extension&gt; &lt;/plugin&gt; </code></pre> <p>Then, add the following code to <code>execute()</code> method of your handler, it will print out the absolution path in console:</p> <pre><code>IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event); //get selection service ISelectionService service = window.getSelectionService(); //get selection IStructuredSelection structured = (IStructuredSelection) service .getSelection(); //get selected file IFile file = (IFile) structured.getFirstElement(); //get the path IPath path = file.getLocation(); System.out.println(path.toPortableString()); return null; </code></pre> <p>Reference: <a href="http://www.programcreek.com/2013/02/eclipse-rcp-tutorial-add-a-menu-item-to-the-popup-menu-when-right-click-a-file/" rel="nofollow" title="Create a popup menu for Package Explorer View">Create popup menu in Package Explorer view</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload