In this tutorial, you will use the RSE pop-up menus extension point to create a pop-up menu action that will appear in the context menu for any .jar file, for any connection to any system type. The action will be labeled "Show contents" and will simply run the jar -tvf JDK command when selected, displaying the results in the command console. You could expand this example to copy the file to a local temporary folder, extract the list of file names within the jar, and display those names in an Eclipse table view.
Tip: If you prefer your Java code to use lined-up braces, select the first two options in the Code Formatter preferences page for Java, via Windows->Preferences. This will affect code generated by wizards. The source code shown assumes this option has been set, but this is not required.
<!-- ======================================= -->
<!-- Remote Object Popup Menu Actions -->
<!-- ======================================= -->
<extension point="org.eclipse.rse.ui.popupMenus">
<objectContribution id="actions.jar"
typecategoryfilter="files"
typefilter="file"
namefilter="*.jar">
<action id="actions.jar.show"
enablesFor="1"
label="Show contents"
tooltip="List contents of this file"
class="samples.ui.actions.ShowJarContents">
</action>
</objectContribution>
</extension>
Save and close the file.
IRemoteFile selectedFile = getFirstSelectedRemoteFile();
String cmdToRun = "jar -tvf " + selectedFile.getAbsolutePath();
runCommand(cmdToRun);
Thats it! Now, you can try your new action. Use Run->Run As->Run-time Workbench. Drill down in the RSE to a Jar file in a local or remote connection and right-click to see and run your new action. Notice how it does not appear for files that do not end with the ".jar" extension. This is because of the "namefilter" attribute in our extension point .xml file.