diff --git a/rse/doc/org.eclipse.rse.doc.isv/guide/tutorial/ShowJarContents1.html b/rse/doc/org.eclipse.rse.doc.isv/guide/tutorial/ShowJarContents1.html index 90e137bc22a..e49235490b2 100755 --- a/rse/doc/org.eclipse.rse.doc.isv/guide/tutorial/ShowJarContents1.html +++ b/rse/doc/org.eclipse.rse.doc.isv/guide/tutorial/ShowJarContents1.html @@ -10,34 +10,36 @@

ShowJarContents Class After Creation

-


 package samples.ui.actions;
 
-import org.eclipse.rse.files.ui.actions.SystemAbstractRemoteFilePopupMenuExtensionAction;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.ui.IObjectActionDelegate;
+import org.eclipse.ui.IWorkbenchPart;
 
-public class ShowJarContents
-	extends SystemAbstractRemoteFilePopupMenuExtensionAction
-{
+public class ShowJarContents implements IObjectActionDelegate {
 
-	/**
-	 * Constructor for ShowJarContents.
-	 */
-	public ShowJarContents()
-	{
-		super();
+	public ShowJarContents() {
+		// TODO Auto-generated constructor stub
 	}
 
-	/**
-	 * @see org.eclipse.rse.ui.actions.SystemAbstractPopupMenuExtensionAction#run()
-	 */
-	public void run()
-	{
+	public void setActivePart(IAction action, IWorkbenchPart targetPart) {
+		// TODO Auto-generated method stub
+
+	}
+
+	public void run(IAction action) {
+		// TODO Auto-generated method stub
+
+	}
+
+	public void selectionChanged(IAction action, ISelection selection) {
+		// TODO Auto-generated method stub
+
 	}
 
 }
-
 
-

diff --git a/rse/doc/org.eclipse.rse.doc.isv/guide/tutorial/ShowJarContents2.html b/rse/doc/org.eclipse.rse.doc.isv/guide/tutorial/ShowJarContents2.html index a316ea3ddae..0ef682951a3 100755 --- a/rse/doc/org.eclipse.rse.doc.isv/guide/tutorial/ShowJarContents2.html +++ b/rse/doc/org.eclipse.rse.doc.isv/guide/tutorial/ShowJarContents2.html @@ -4,49 +4,79 @@ - + ShowJarContents Class After Editing

ShowJarContents Class After Editing

-


 package samples.ui.actions;
 
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.jface.action.IAction;
 import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.rse.core.model.IHost;
-import org.eclipse.rse.files.ui.actions.SystemAbstractRemoteFilePopupMenuExtensionAction;
+import org.eclipse.rse.core.subsystems.ISubSystem;
 import org.eclipse.rse.shells.ui.RemoteCommandHelpers;
 import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile;
 import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteCmdSubSystem;
+import org.eclipse.rse.ui.SystemBasePlugin;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IObjectActionDelegate;
+import org.eclipse.ui.IWorkbenchPart;
 
-public class ShowJarContents2 extends SystemAbstractRemoteFilePopupMenuExtensionAction {
+/**
+ * An action that runs a command to display the contents of a Jar file.
+ * The plugin.xml file restricts this action so it only appears for .jar files.
+ */
+public class ShowJarContents implements IObjectActionDelegate {
+	private List _selectedFiles;
 
-	public ShowJarContents2() {
-		super();
+	/**
+	 * Constructor for ShowJarContents.
+	 */
+	public ShowJarContents() {
+		_selectedFiles = new ArrayList();
 	}
 
-	public void run() {
+	protected Shell getShell() {
+		return SystemBasePlugin.getActiveWorkbenchShell();
+	}
+
+	protected IRemoteFile getFirstSelectedRemoteFile() {
+		if (_selectedFiles.size() > 0) {
+			return (IRemoteFile) _selectedFiles.get(0);
+		}
+		return null;
+	}
+
+	protected ISubSystem getSubSystem() {
+		return getFirstSelectedRemoteFile().getParentRemoteFileSubSystem();
+	}
+
+	/* (non-Javadoc)
+	 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
+	 */
+	public void run(IAction action) {
 		IRemoteFile selectedFile = getFirstSelectedRemoteFile();
-		String cmdToRun = "jar -tvf " + selectedFile.getAbsolutePath();
-		runCommand(cmdToRun);
-	}
-
-	private void runCommand(String command) {
-		IRemoteCmdSubSystem cmdss = getRemoteCmdSubSystem();
-		if (cmdss != null && cmdss.isConnected()) {
-			RemoteCommandHelpers.runUniversalCommand(getShell(), command, ".", cmdss);
-		} else {
-			MessageDialog.openError(getShell(), "No command subsystem", "Found no command subsystem");
+		String cmdToRun = "jar -tvf " + selectedFile.getAbsolutePath(); //$NON-NLS-1$
+		try {
+			runCommand(cmdToRun);
+		} catch (Exception e) {
+			String excType = e.getClass().getName();
+			MessageDialog.openError(getShell(), excType, excType + ": " + e.getLocalizedMessage()); //$NON-NLS-1$
+			e.printStackTrace();
 		}
 	}
-	
-	/**
-	 * Gets the Command subsystem associated with the current host
-	 */
-	private IRemoteCmdSubSystem getRemoteCmdSubSystem() {
+
+	public IRemoteCmdSubSystem getRemoteCmdSubSystem() {
+		//get the Command subsystem associated with the current host
 		IHost myHost = getSubSystem().getHost();
 		IRemoteCmdSubSystem[] subsys = RemoteCommandHelpers.getCmdSubSystems(myHost);
 		for (int i = 0; i < subsys.length; i++) {
@@ -57,8 +87,31 @@ public class ShowJarContents2 extends SystemAbstractRemoteFilePopupMenuExtension
 		return null;
 	}
 
+	public void runCommand(String command) throws Exception {
+		IRemoteCmdSubSystem cmdss = getRemoteCmdSubSystem();
+		if (cmdss != null && cmdss.isConnected()) {
+			// Run the command in a visible shell
+			RemoteCommandHelpers.runUniversalCommand(getShell(), command, ".", cmdss); //$NON-NLS-1$
+		} else {
+			MessageDialog.openError(getShell(), "No command subsystem", "Found no command subsystem");
+		}
+	}
+
+	public void selectionChanged(org.eclipse.jface.action.IAction action, org.eclipse.jface.viewers.ISelection selection) {
+		_selectedFiles.clear();
+		// store the selected jars to be used when running
+		Iterator theSet = ((IStructuredSelection) selection).iterator();
+		while (theSet.hasNext()) {
+			Object obj = theSet.next();
+			if (obj instanceof IRemoteFile) {
+				_selectedFiles.add(obj);
+			}
+		}
+	}
+
+	public void setActivePart(IAction action, IWorkbenchPart targetPart) {
+	}
 }
 
-

diff --git a/rse/doc/org.eclipse.rse.doc.isv/guide/tutorial/popup.html b/rse/doc/org.eclipse.rse.doc.isv/guide/tutorial/popup.html index aa9562451f2..10efece442a 100755 --- a/rse/doc/org.eclipse.rse.doc.isv/guide/tutorial/popup.html +++ b/rse/doc/org.eclipse.rse.doc.isv/guide/tutorial/popup.html @@ -22,12 +22,6 @@ 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. -

Step-by-Step: Creating an RSE Remote Resource Pop-up Menu Action

    @@ -42,7 +36,7 @@ This will affect code generated by wizards. The source code shown assumes this o <extension point="org.eclipse.ui.popupMenus"> <objectContribution objectClass="org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile" - namefilter="*.jar"´ + nameFilter="*.jar" id="actions.jar"> <action label="Show contents" @@ -58,39 +52,63 @@ This will affect code generated by wizards. The source code shown assumes this o Save and close the file.
  1. -Create the Java package: right-click on the src source folder and select New->Package to open the New - Java Package wizard. Enter "samples.ui.actions" for the name of the package and press Finish.
  2. -
  3. -Create the Java class: right-click on the new "samples.ui.actions" package folder and select New->Class to open the New -Java Class wizard. Enter "ShowJarContents" for the Name -and "org.eclipse.rse.files.ui.actions.SystemAbstractRemoteFilePopupMenuExtensionAction" -for the Superclass. Select the Constructors from superclass check box, as shown -here. -Press Finish to create the ShowJarContents class. +Right-click on the project and use the New... action to create a new package in this project named samples.ui.actions.
  4. -
  5. Edit the generated ShowJarContents.java file as follows: +
  6. +Create the Java class: right-click on the new samples.ui.actions package folder and select New->Class to open the New +Java Class wizard. +Enter "ShowJarContents" for the Name, add IObjectActionDelegate +to the Interfaces that are implemented, and check the constructors from superclass checkbox as shown +here. +Click Finish to create the ShowJarContents class. +
  7. +
  8. Edit the generated ShowJarContents.java file as follows. +Use the "Source -> Organize Imports" context menu item to add the appropriate import statements as you edit.
      -
    1. Add the following three statements to the body of the run() method:
    2. -
      
      -		IRemoteFile selectedFile = getFirstSelectedRemoteFile();
      -		String cmdToRun = "jar -tvf " + selectedFile.getAbsolutePath();
      -		runCommand(cmdToRun);  
      -  
      -
    3. Add the following two methods to find the subsystem and run the command:
    4. -
      
      -	private void runCommand(String command) {
      +
    5. Add an instance variable to hold a list of remote files and initialize it in the constructor.
    6. +
      
      +	private List _selectedFiles;
      +
      +	/**
      +	 * Constructor for ShowJarContents.
      +	 */
      +	public ShowJarContents() {
      +		_selectedFiles = new ArrayList();
      +	}	  
      +
      +
    7. Add the following three utility methods
    8. +
      
      +	protected Shell getShell() {
      +		return SystemBasePlugin.getActiveWorkbenchShell();
      +	}
      +
      +	protected IRemoteFile getFirstSelectedRemoteFile() {
      +		if (_selectedFiles.size() > 0) {
      +			return (IRemoteFile)_selectedFiles.get(0);
      +		}
      +		return null;
      +	}
      +
      +	protected ISubSystem getSubSystem() {
      +		return getFirstSelectedRemoteFile().getParentRemoteFileSubSystem();
      +	}
      +
      +
    9. Add the following methods to find the subsystem and run the command:
    10. +
      
      +	public void runCommand(String command) {
       		IRemoteCmdSubSystem cmdss = getRemoteCmdSubSystem();
       		if (cmdss != null && cmdss.isConnected()) {
      -			RemoteCommandHelpers.runUniversalCommand(getShell(), command, ".", cmdss);
      +			// Run the command in a visible shell
      +			RemoteCommandHelpers.runUniversalCommand(getShell(), command, ".", cmdss); //$NON-NLS-1$
       		} else {
       			MessageDialog.openError(getShell(), "No command subsystem", "Found no command subsystem");
       		}
       	}
      -	
      +
       	/**
       	 * Gets the Command subsystem associated with the current host
       	 */
      -	private IRemoteCmdSubSystem getRemoteCmdSubSystem() {
      +	public IRemoteCmdSubSystem getRemoteCmdSubSystem() {
       		IHost myHost = getSubSystem().getHost();
       		IRemoteCmdSubSystem[] subsys = RemoteCommandHelpers.getCmdSubSystems(myHost);
       		for (int i = 0; i < subsys.length; i++) {
      @@ -100,16 +118,46 @@ Press Finish to create the ShowJarC
       		}
       		return null;
       	}
      -  
      -
    11. User the "Source -> Organize Imports" context menu item to add the appropriate import statements.
    12. +
      +
    13. Finally, flesh out the methods that were created as stubs
    14. +
      
      +	public void run(IAction action) {
      +		IRemoteFile selectedFile = getFirstSelectedRemoteFile();
      +		String cmdToRun = "jar -tvf " + selectedFile.getAbsolutePath(); //$NON-NLS-1$
      +		try {
      +			runCommand(cmdToRun);
      +		} catch (Exception e) {
      +			String excType = e.getClass().getName();
      +			MessageDialog.openError(getShell(), excType, excType + ": " + e.getLocalizedMessage()); //$NON-NLS-1$
      +			e.printStackTrace();
      +		}
      +	}
      +
      +	public void selectionChanged(org.eclipse.jface.action.IAction action, org.eclipse.jface.viewers.ISelection selection) {
      +		_selectedFiles.clear();
      +		// store the selected jars to be used when running
      +		Iterator theSet = ((IStructuredSelection) selection).iterator();
      +		while (theSet.hasNext()) {
      +			Object obj = theSet.next();
      +			if (obj instanceof IRemoteFile) {
      +				_selectedFiles.add(obj);
      +			}
      +		}
      +	}
      +
      +	public void setActivePart(IAction action, IWorkbenchPart targetPart) {
      +	}
      +
    The final result after editing is shown here.
-

Thats it! Now, you can try your new action. Use Run->Run As->Run-time Workbench. Drill +

+Now, you can try your new action. Use Run->Run As->Eclipse Application. + 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 +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. diff --git a/rse/doc/org.eclipse.rse.doc.isv/guide/tutorial/popup_newClass.gif b/rse/doc/org.eclipse.rse.doc.isv/guide/tutorial/popup_newClass.gif index 1e097dc6b0a..dc00bb12cbd 100755 Binary files a/rse/doc/org.eclipse.rse.doc.isv/guide/tutorial/popup_newClass.gif and b/rse/doc/org.eclipse.rse.doc.isv/guide/tutorial/popup_newClass.gif differ diff --git a/rse/examples/org.eclipse.rse.examples.tutorial/src/samples/ui/actions/ShowJarContents.java b/rse/examples/org.eclipse.rse.examples.tutorial/src/samples/ui/actions/ShowJarContents.java index fecca34a435..ebe33a563df 100644 --- a/rse/examples/org.eclipse.rse.examples.tutorial/src/samples/ui/actions/ShowJarContents.java +++ b/rse/examples/org.eclipse.rse.examples.tutorial/src/samples/ui/actions/ShowJarContents.java @@ -12,6 +12,7 @@ * * Contributors: * Martin Oberhuber (Wind River) - Adapted original tutorial code to Open RSE. + * David Dykstal (IBM) - formatting for tutorial ********************************************************************************/ package samples.ui.actions; @@ -47,49 +48,42 @@ import org.eclipse.ui.IWorkbenchPart; * An action that runs a command to display the contents of a Jar file. * The plugin.xml file restricts this action so it only appears for .jar files. */ -public class ShowJarContents implements IObjectActionDelegate -{ +public class ShowJarContents implements IObjectActionDelegate { private List _selectedFiles; - + /** * Constructor for ShowJarContents. */ - public ShowJarContents() - { + public ShowJarContents() { _selectedFiles = new ArrayList(); } - protected Shell getShell() - { + protected Shell getShell() { return SystemBasePlugin.getActiveWorkbenchShell(); } - - protected IRemoteFile getFirstSelectedRemoteFile() - { - if (_selectedFiles.size() > 0) - { - return (IRemoteFile)_selectedFiles.get(0); + + protected IRemoteFile getFirstSelectedRemoteFile() { + if (_selectedFiles.size() > 0) { + return (IRemoteFile) _selectedFiles.get(0); } return null; } - - protected ISubSystem getSubSystem() - { + + protected ISubSystem getSubSystem() { return getFirstSelectedRemoteFile().getParentRemoteFileSubSystem(); } - - + /* (non-Javadoc) - * @see org.eclipse.rse.ui.actions.SystemAbstractPopupMenuExtensionAction#run() + * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction) */ public void run(IAction action) { IRemoteFile selectedFile = getFirstSelectedRemoteFile(); String cmdToRun = "jar -tvf " + selectedFile.getAbsolutePath(); //$NON-NLS-1$ try { runCommand(cmdToRun); - } catch(Exception e) { + } catch (Exception e) { String excType = e.getClass().getName(); - MessageDialog.openError(getShell(), excType, excType+": "+e.getLocalizedMessage()); //$NON-NLS-1$ + MessageDialog.openError(getShell(), excType, excType + ": " + e.getLocalizedMessage()); //$NON-NLS-1$ e.printStackTrace(); } } @@ -98,20 +92,17 @@ public class ShowJarContents implements IObjectActionDelegate //get the Command subsystem associated with the current host IHost myHost = getSubSystem().getHost(); IRemoteCmdSubSystem[] subsys = RemoteCommandHelpers.getCmdSubSystems(myHost); - for (int i=0; i0 && result[0] instanceof IRemoteCommandShell) { - IRemoteCommandShell cs = (IRemoteCommandShell)result[0]; + if (result.length > 0 && result[0] instanceof IRemoteCommandShell) { + IRemoteCommandShell cs = (IRemoteCommandShell) result[0]; while (cs.isActive()) { Thread.sleep(1000); } Object[] output = cs.listOutput(); - for (int i=0; i