KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > debug > ui > launcher > SelectDefaultSystemLibraryQuickFix


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.launcher;
12
13
14 import java.lang.reflect.InvocationTargetException JavaDoc;
15
16 import org.eclipse.core.resources.IMarker;
17 import org.eclipse.core.runtime.CoreException;
18 import org.eclipse.core.runtime.IProgressMonitor;
19 import org.eclipse.core.runtime.IStatus;
20 import org.eclipse.core.runtime.Status;
21 import org.eclipse.jdt.debug.ui.IJavaDebugUIConstants;
22 import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
23 import org.eclipse.jdt.launching.IVMInstall;
24 import org.eclipse.jdt.launching.JavaRuntime;
25 import org.eclipse.jface.operation.IRunnableWithProgress;
26 import org.eclipse.ui.PlatformUI;
27
28 /**
29  * Quick fix to select an alternate default JRE.
30  */

31 public class SelectDefaultSystemLibraryQuickFix extends JREResolution {
32     
33     public SelectDefaultSystemLibraryQuickFix() {
34         super();
35     }
36
37     /**
38      * @see org.eclipse.ui.IMarkerResolution#run(org.eclipse.core.resources.IMarker)
39      */

40     public void run(IMarker marker) {
41         try {
42             String JavaDoc title = LauncherMessages.SelectDefaultSystemLibraryQuickFix_Select_Default_System_Library_1;
43             String JavaDoc message = LauncherMessages.SelectDefaultSystemLibraryQuickFix__Select_the_system_library_to_use_by_default_for_building_and_running_Java_projects__2;
44         
45             final IVMInstall vm = chooseVMInstall(title, message);
46             if (vm == null) {
47                 return;
48             }
49
50             IRunnableWithProgress runnable = new IRunnableWithProgress() {
51                 public void run(IProgressMonitor monitor) throws InvocationTargetException JavaDoc {
52                         try {
53                             JavaRuntime.setDefaultVMInstall(vm, monitor);
54                         } catch (CoreException e) {
55                             throw new InvocationTargetException JavaDoc(e);
56                         }
57                 }
58             };
59         
60             try {
61                 PlatformUI.getWorkbench().getProgressService().busyCursorWhile(runnable);
62             } catch (InvocationTargetException JavaDoc e) {
63                 if (e.getTargetException() instanceof CoreException) {
64                     throw (CoreException)e.getTargetException();
65                 }
66                 throw new CoreException(new Status(IStatus.ERROR,
67                     JDIDebugUIPlugin.getUniqueIdentifier(),
68                     IJavaDebugUIConstants.INTERNAL_ERROR,
69                     LauncherMessages.SelectDefaultSystemLibraryQuickFix_An_exception_occurred_while_updating_the_default_system_library__3, e.getTargetException()));
70             } catch (InterruptedException JavaDoc e) {
71                 // canceled
72
}
73         } catch (CoreException e) {
74             JDIDebugUIPlugin.statusDialog(LauncherMessages.SelectDefaultSystemLibraryQuickFix_Unable_to_update_the_default_system_library__4, e.getStatus());
75         }
76     }
77         
78     /**
79      * @see org.eclipse.ui.IMarkerResolution#getLabel()
80      */

81     public String JavaDoc getLabel() {
82         return LauncherMessages.SelectDefaultSystemLibraryQuickFix_Select_default_system_library_5;
83     }
84
85 }
86
Popular Tags