KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > debug > ui > actions > AddLibraryAction


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.debug.ui.actions;
12
13
14 import org.eclipse.core.runtime.CoreException;
15 import org.eclipse.jdt.core.IClasspathEntry;
16 import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
17 import org.eclipse.jdt.internal.debug.ui.launcher.IClasspathViewer;
18 import org.eclipse.jdt.internal.debug.ui.launcher.LauncherMessages;
19 import org.eclipse.jdt.launching.IRuntimeClasspathEntry;
20 import org.eclipse.jdt.launching.JavaRuntime;
21 import org.eclipse.jdt.ui.wizards.BuildPathDialogAccess;
22
23 /**
24  * Adds a library to the runtime class path.
25  */

26 public class AddLibraryAction extends RuntimeClasspathAction {
27
28     public AddLibraryAction(IClasspathViewer viewer) {
29         super(ActionMessages.AddLibraryAction_0, viewer);
30     }
31
32     /**
33      * Prompts for folder(s) to add.
34      *
35      * @see org.eclipse.jface.action.IAction#run()
36      */

37     public void run() {
38
39         IClasspathEntry[] newEntries = BuildPathDialogAccess.chooseContainerEntries(getShell(), null, new IClasspathEntry[0]);
40         if (newEntries != null) {
41             IRuntimeClasspathEntry[] res= new IRuntimeClasspathEntry[newEntries.length];
42             for (int i = 0; i < newEntries.length; i++) {
43                 IClasspathEntry entry = newEntries[i];
44                 try {
45                     res[i] = JavaRuntime.newRuntimeContainerClasspathEntry(entry.getPath(), IRuntimeClasspathEntry.STANDARD_CLASSES);
46                 } catch (CoreException e) {
47                     JDIDebugUIPlugin.statusDialog(LauncherMessages.RuntimeClasspathAdvancedDialog_Unable_to_create_new_entry__3, e.getStatus());
48                     return;
49                 }
50             }
51             getViewer().addEntries(res);
52         }
53     }
54         
55     protected int getActionType() {
56         return ADD;
57     }
58 }
59
Popular Tags