1 /******************************************************************************* 2 * Copyright (c) 2000, 2011 IBM Corporation and others. 3 * 4 * This program and the accompanying materials 5 * are made available under the terms of the Eclipse Public License 2.0 6 * which accompanies this distribution, and is available at 7 * https://www.eclipse.org/legal/epl-2.0/ 8 * 9 * SPDX-License-Identifier: EPL-2.0 10 * 11 * Contributors: 12 * IBM Corporation - initial API and implementation 13 *******************************************************************************/ 14 package org.eclipse.jdt.internal.debug.ui.actions; 15 16 17 import org.eclipse.core.runtime.CoreException; 18 import org.eclipse.jdt.core.IClasspathEntry; 19 import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin; 20 import org.eclipse.jdt.internal.debug.ui.launcher.IClasspathViewer; 21 import org.eclipse.jdt.internal.debug.ui.launcher.LauncherMessages; 22 import org.eclipse.jdt.launching.IRuntimeClasspathEntry; 23 import org.eclipse.jdt.launching.JavaRuntime; 24 import org.eclipse.jdt.ui.wizards.BuildPathDialogAccess; 25 26 /** 27 * Adds a library to the runtime class path. 28 */ 29 public class AddLibraryAction extends RuntimeClasspathAction { 30 AddLibraryAction(IClasspathViewer viewer)31 public AddLibraryAction(IClasspathViewer viewer) { 32 super(ActionMessages.AddLibraryAction_0, viewer); 33 } 34 35 /** 36 * Prompts for folder(s) to add. 37 * 38 * @see org.eclipse.jface.action.IAction#run() 39 */ 40 @Override run()41 public void run() { 42 43 IClasspathEntry[] newEntries = BuildPathDialogAccess.chooseContainerEntries(getShell(), null, new IClasspathEntry[0]); 44 if (newEntries != null) { 45 IRuntimeClasspathEntry[] res= new IRuntimeClasspathEntry[newEntries.length]; 46 for (int i = 0; i < newEntries.length; i++) { 47 IClasspathEntry entry = newEntries[i]; 48 try { 49 res[i] = JavaRuntime.newRuntimeContainerClasspathEntry(entry.getPath(), IRuntimeClasspathEntry.STANDARD_CLASSES); 50 } catch (CoreException e) { 51 JDIDebugUIPlugin.statusDialog(LauncherMessages.RuntimeClasspathAdvancedDialog_Unable_to_create_new_entry__3, e.getStatus()); 52 return; 53 } 54 } 55 getViewer().addEntries(res); 56 } 57 } 58 59 @Override getActionType()60 protected int getActionType() { 61 return ADD; 62 } 63 } 64