1 11 package org.eclipse.jdt.internal.debug.ui.actions; 12 13 14 import java.util.ArrayList ; 15 16 import org.eclipse.core.runtime.IPath; 17 import org.eclipse.core.runtime.Path; 18 import org.eclipse.jdt.internal.debug.ui.launcher.IClasspathViewer; 19 import org.eclipse.jdt.launching.IRuntimeClasspathEntry; 20 import org.eclipse.jdt.launching.JavaRuntime; 21 import org.eclipse.jface.dialogs.MessageDialog; 22 import org.eclipse.swt.SWT; 23 import org.eclipse.swt.widgets.FileDialog; 24 25 import com.ibm.icu.text.MessageFormat; 26 27 30 public class AddExternalJarAction extends OpenDialogAction { 31 32 public AddExternalJarAction(IClasspathViewer viewer, String dialogSettingsPrefix) { 33 super(ActionMessages.AddExternalJar_Add_E_xternal_JARs_1, viewer, dialogSettingsPrefix); 34 } 35 36 41 public void run() { 42 43 String lastUsedPath = getDialogSetting(LAST_PATH_SETTING); 44 if (lastUsedPath == null) { 45 lastUsedPath = ""; } 47 FileDialog dialog = new FileDialog(getShell(), SWT.MULTI); 48 dialog.setText(ActionMessages.AddExternalJar_Jar_Selection_3); 49 dialog.setFilterExtensions(new String [] {"*.jar;*.zip"}); dialog.setFilterPath(lastUsedPath); 51 String res = dialog.open(); 52 if (res == null) { 53 return; 54 } 55 String [] fileNames = dialog.getFileNames(); 56 int nChosen = fileNames.length; 57 58 IPath filterPath = new Path(dialog.getFilterPath()); 59 ArrayList list = new ArrayList (); 60 IPath path = null; 61 for (int i= 0; i < nChosen; i++) { 62 path = filterPath.append(fileNames[i]).makeAbsolute(); 63 if(path.toFile().exists()) { 64 list.add(JavaRuntime.newArchiveRuntimeClasspathEntry(path)); 65 } 66 else { 67 MessageDialog.openError(getShell(), ActionMessages.AddExternalJarAction_error_box_title, MessageFormat.format(ActionMessages.AddExternalJarAction_error_box_message, new String [] {path.makeAbsolute().toOSString()})); 68 } 69 } 70 if(list.size() > 0) { 71 setDialogSetting(LAST_PATH_SETTING, filterPath.toOSString()); 72 getViewer().addEntries((IRuntimeClasspathEntry[]) list.toArray(new IRuntimeClasspathEntry[list.size()])); 73 } 74 } 75 } 76 | Popular Tags |