KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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.debug.core.ILaunchConfiguration;
16 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
17 import org.eclipse.jdt.debug.ui.launchConfigurations.JavaClasspathTab;
18 import org.eclipse.jdt.internal.debug.ui.launcher.IClasspathViewer;
19 import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
20 import org.eclipse.jdt.launching.JavaRuntime;
21 import org.eclipse.jface.viewers.IStructuredSelection;
22
23 /**
24  * Restores default entries in the runtime classpath.
25  */

26 public class RestoreDefaultEntriesAction extends RuntimeClasspathAction {
27     
28     private JavaClasspathTab fTab;
29     
30     /**
31      * Constructor
32      * @param viewer the associated classpath viewer
33      * @param tab the tab the viewer resides in
34      */

35     public RestoreDefaultEntriesAction(IClasspathViewer viewer, JavaClasspathTab tab) {
36         super(ActionMessages.RestoreDefaultEntriesAction_0, viewer);
37         fTab = tab;
38     }
39
40     /**
41      * Only does work if we are not currently using the default classpath
42      *
43      * @see org.eclipse.jface.action.Action#run()
44      */

45     public void run() {
46         try {
47             ILaunchConfiguration config = fTab.getLaunchConfiguration();
48             if(!config.getAttribute(IJavaLaunchConfigurationConstants.ATTR_DEFAULT_CLASSPATH, false)) {
49                 ILaunchConfigurationWorkingCopy copy = null;
50                 if(config.isWorkingCopy()) {
51                     copy = (ILaunchConfigurationWorkingCopy) config;
52                 }
53                 else {
54                     copy = config.getWorkingCopy();
55                 }
56                 copy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_DEFAULT_CLASSPATH, true);
57                 getViewer().setEntries(JavaRuntime.computeUnresolvedRuntimeClasspath(copy));
58             }
59         }
60         catch (CoreException e) {return;}
61     }
62
63     /**
64      * @see SelectionListenerAction#updateSelection(IStructuredSelection)
65      */

66     protected boolean updateSelection(IStructuredSelection selection) {
67         return true;
68     }
69 }
70
Popular Tags