2006-05-30 15:32:53 +00:00
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
< html >
< head >
< META HTTP-EQUIV = "Content-Type" CONTENT = "text/html; charset=UTF-8" >
< META HTTP-EQUIV = "Content-Style-Type" CONTENT = "text/css" >
2007-06-27 01:52:12 +00:00
< meta name = "copyright" content = "Copyright (c) IBM Corporation and others 2002, 2007. This page is made available under license. For full details see the LEGAL in the documentation book that contains this page." >
2006-05-30 15:32:53 +00:00
< LINK REL = "STYLESHEET" HREF = "../../book.css" TYPE = "text/css" >
< title > ShowJarContents Class After Editing< / title >
< / head >
< body bgcolor = "#ffffff" >
< h1 > ShowJarContents Class After Editing< / h1 >
< pre > < samp >
package samples.ui.actions;
2007-06-27 01:52:12 +00:00
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.eclipse.jface.action.IAction;
2006-12-14 22:04:00 +00:00
import org.eclipse.jface.dialogs.MessageDialog;
2007-06-27 01:52:12 +00:00
import org.eclipse.jface.viewers.IStructuredSelection;
2006-12-14 22:04:00 +00:00
import org.eclipse.rse.core.model.IHost;
2007-06-27 01:52:12 +00:00
import org.eclipse.rse.core.subsystems.ISubSystem;
2006-12-14 22:04:00 +00:00
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;
2007-06-27 01:52:12 +00:00
import org.eclipse.rse.ui.SystemBasePlugin;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;
2006-05-30 15:32:53 +00:00
2007-06-27 01:52:12 +00:00
/**
* 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;
2006-05-30 15:32:53 +00:00
2007-06-27 01:52:12 +00:00
/**
* Constructor for ShowJarContents.
*/
public ShowJarContents() {
_selectedFiles = new ArrayList();
2006-05-30 15:32:53 +00:00
}
2007-06-27 01:52:12 +00:00
protected Shell getShell() {
return SystemBasePlugin.getActiveWorkbenchShell();
2006-12-14 22:04:00 +00:00
}
2007-06-27 01:52:12 +00:00
protected IRemoteFile getFirstSelectedRemoteFile() {
if (_selectedFiles.size() > 0) {
return (IRemoteFile) _selectedFiles.get(0);
2006-12-14 22:04:00 +00:00
}
2007-06-27 01:52:12 +00:00
return null;
2006-12-14 22:04:00 +00:00
}
2007-06-27 01:52:12 +00:00
protected ISubSystem getSubSystem() {
return getFirstSelectedRemoteFile().getParentRemoteFileSubSystem();
}
/* (non-Javadoc)
* @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
2006-05-30 15:32:53 +00:00
*/
2007-06-27 01:52:12 +00:00
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 IRemoteCmdSubSystem getRemoteCmdSubSystem() {
//get the Command subsystem associated with the current host
2006-12-14 22:04:00 +00:00
IHost myHost = getSubSystem().getHost();
IRemoteCmdSubSystem[] subsys = RemoteCommandHelpers.getCmdSubSystems(myHost);
for (int i = 0; i < subsys.length ; i + + ) {
if (subsys[i].getSubSystemConfiguration().supportsCommands()) {
return subsys[i];
}
}
return null;
2006-05-30 15:32:53 +00:00
}
2007-06-27 01:52:12 +00:00
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) {
}
2006-05-30 15:32:53 +00:00
}
< / samp > < / pre >
< / body >
< / html >