| 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 OpenDialogAction { |
| |
| public AddExternalJarAction(RuntimeClasspathViewer viewer, String dialogSettingsPrefix) { |
| super(ActionMessages.getString("AddExternalJar.Add_E&xternal_JARs_1"), viewer, dialogSettingsPrefix); //$NON-NLS-1$ |
| } |
| |
| /** |
| * Prompts for a project to add. |
| * |
| * @see IAction#run() |
| */ |
| public void run() { |
| |
| String lastUsedPath= getDialogSetting(LAST_PATH_SETTING); |
| 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); |
| } |
| setDialogSetting(LAST_PATH_SETTING, filterPath.toOSString()); |
| |
| getViewer().addEntries(elems); |
| } |
| |
| /** |
| * @see SelectionListenerAction#updateSelection(IStructuredSelection) |
| */ |
| protected boolean updateSelection(IStructuredSelection selection) { |
| return getViewer().isEnabled(); |
| } |
| |
| } |