blob: e3b0ced04de91c5be7f8bee35d9408d0a2a2b03b [file] [log] [blame]
package org.eclipse.jdt.internal.debug.ui.actions;
/*
* (c) Copyright IBM Corp. 2000, 2001.
* All Rights Reserved.
*/
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.jdt.internal.debug.ui.launcher.RuntimeClasspathViewer;
import org.eclipse.jdt.launching.IRuntimeClasspathEntry;
import org.eclipse.jdt.launching.JavaRuntime;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.FileDialog;
/**
* Adds an external jar to the runtime class path.
*/
public class AddExternalJarAction extends RuntimeClasspathAction {
public AddExternalJarAction(RuntimeClasspathViewer viewer) {
super(ActionMessages.getString("AddExternalJar.Add_E&xternal_JARs_1"), viewer); //$NON-NLS-1$
}
/**
* Prompts for a project to add.
*
* @see IAction#run()
*/
public void run() {
String lastUsedPath= ""; //$NON-NLS-1$
if (lastUsedPath == null) {
lastUsedPath= ""; //$NON-NLS-1$
}
FileDialog dialog= new FileDialog(getShell(), SWT.MULTI);
dialog.setText(ActionMessages.getString("AddExternalJar.Jar_Selection_3")); //$NON-NLS-1$
dialog.setFilterExtensions(new String[] {"*.jar;*.zip"}); //$NON-NLS-1$
dialog.setFilterPath(lastUsedPath);
String res= dialog.open();
if (res == null) {
return;
}
String[] fileNames= dialog.getFileNames();
int nChosen= fileNames.length;
IPath filterPath= new Path(dialog.getFilterPath());
IRuntimeClasspathEntry[] elems= new IRuntimeClasspathEntry[nChosen];
for (int i= 0; i < nChosen; i++) {
IPath path= filterPath.append(fileNames[i]).makeAbsolute();
elems[i]= JavaRuntime.newArchiveRuntimeClasspathEntry(path);
}
//fDialogSettings.put(IUIConstants.DIALOGSTORE_LASTEXTJAR, filterPath.toOSString());
getViewer().addEntries(elems);
}
/**
* @see SelectionListenerAction#updateSelection(IStructuredSelection)
*/
protected boolean updateSelection(IStructuredSelection selection) {
return getViewer().isEnabled();
}
}