KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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.IPath;
15 import org.eclipse.core.runtime.Path;
16 import org.eclipse.jdt.internal.debug.ui.launcher.IClasspathViewer;
17 import org.eclipse.jdt.launching.IRuntimeClasspathEntry;
18 import org.eclipse.jdt.launching.JavaRuntime;
19 import org.eclipse.swt.SWT;
20 import org.eclipse.swt.widgets.DirectoryDialog;
21
22 /**
23  * Adds an external folder to the runtime class path.
24  */

25 public class AddExternalFolderAction extends OpenDialogAction {
26
27     public AddExternalFolderAction(IClasspathViewer viewer, String JavaDoc dialogSettingsPrefix) {
28         super(ActionMessages.AddExternalFolderAction_Add_External_Folder_1, viewer, dialogSettingsPrefix);
29     }
30
31     /**
32      * Prompts for a folder to add.
33      *
34      * @see IAction#run()
35      */

36     public void run() {
37                             
38         String JavaDoc lastUsedPath= getDialogSetting(LAST_PATH_SETTING);
39         if (lastUsedPath == null) {
40             lastUsedPath= ""; //$NON-NLS-1$
41
}
42         DirectoryDialog dialog= new DirectoryDialog(getShell(), SWT.MULTI);
43         dialog.setText(ActionMessages.AddExternalFolderAction_Folder_Selection_3);
44         dialog.setFilterPath(lastUsedPath);
45         String JavaDoc res= dialog.open();
46         if (res == null) {
47             return;
48         }
49             
50         IPath filterPath= new Path(dialog.getFilterPath());
51         IRuntimeClasspathEntry[] elems= new IRuntimeClasspathEntry[1];
52         IPath path= new Path(res).makeAbsolute();
53         elems[0]= JavaRuntime.newArchiveRuntimeClasspathEntry(path);
54
55         setDialogSetting(LAST_PATH_SETTING, filterPath.toOSString());
56         
57         getViewer().addEntries(elems);
58     }
59 }
60
Popular Tags