KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.eclipse.core.resources.IMarker;
15 import org.eclipse.core.runtime.IPath;
16 import org.eclipse.core.runtime.Path;
17 import org.eclipse.jdt.core.CorrectionEngine;
18 import org.eclipse.jdt.core.IJavaModelMarker;
19 import org.eclipse.jdt.core.IJavaModelStatusConstants;
20 import org.eclipse.jdt.core.IJavaProject;
21 import org.eclipse.jdt.core.JavaCore;
22 import org.eclipse.jdt.launching.JavaRuntime;
23 import org.eclipse.ui.IMarkerResolution;
24 import org.eclipse.ui.IMarkerResolutionGenerator;
25
26 /**
27  * Generates quick fixes for unbound JREs.
28  */

29 public class JreResolutionGenerator implements IMarkerResolutionGenerator {
30     
31     private final static IMarkerResolution[] NO_RESOLUTION = new IMarkerResolution[0];
32
33     /**
34      * @see org.eclipse.ui.IMarkerResolutionGenerator#getResolutions(org.eclipse.core.resources.IMarker)
35      */

36     public IMarkerResolution[] getResolutions(IMarker marker) {
37         int id = marker.getAttribute(IJavaModelMarker.ID, -1);
38         switch (id) {
39             // unbound classpath container
40
case IJavaModelStatusConstants.CP_CONTAINER_PATH_UNBOUND :
41                 String JavaDoc[] arguments = CorrectionEngine.getProblemArguments(marker);
42                 IPath path = new Path(arguments[0]);
43                 if (path.segment(0).equals(JavaRuntime.JRE_CONTAINER)) {
44                     // unbound JRE_CONTAINER
45
if (JREResolution.getAllVMs().length > 0) {
46                         IJavaProject project = getJavaProject(marker);
47                         return new IMarkerResolution[]{new SelectSystemLibraryQuickFix(path, project)};
48                     }
49                     // define a new JRE
50
return new IMarkerResolution[]{new DefineSystemLibraryQuickFix()};
51                 }
52                 break;
53
54             // unbound classpath variable
55
case IJavaModelStatusConstants.CP_VARIABLE_PATH_UNBOUND :
56                 arguments = CorrectionEngine.getProblemArguments(marker);
57                 path = new Path(arguments[0]);
58                 if (path.segment(0).equals(JavaRuntime.JRELIB_VARIABLE)) {
59                     // unbound JRE_LIB
60
if (JREResolution.getAllVMs().length > 0) {
61                         return new IMarkerResolution[]{new SelectDefaultSystemLibraryQuickFix()};
62                     }
63                     // define a new default JRE
64
return new IMarkerResolution[]{new DefineSystemLibraryQuickFix()};
65                 }
66                 break;
67             // deprecated JRE library variables
68
case IJavaModelStatusConstants.DEPRECATED_VARIABLE :
69                 arguments = CorrectionEngine.getProblemArguments(marker);
70                 path = new Path(arguments[0]);
71                 if (path.segment(0).equals(JavaRuntime.JRELIB_VARIABLE) ||
72                         path.segment(0).equals(JavaRuntime.JRE_CONTAINER)) {
73                     IJavaProject project = getJavaProject(marker);
74                     return new IMarkerResolution[] {new SelectSystemLibraryQuickFix(path, project)};
75                 }
76                 break;
77         }
78         return NO_RESOLUTION;
79     }
80
81     /**
82      * Returns the java project from the specified marker, or <code>null</code> if the marker
83      * does not have an associated java project
84      * @param marker
85      * @return the associated java project or <code>null</code>
86      */

87     protected IJavaProject getJavaProject(IMarker marker) {
88         return JavaCore.create(marker.getResource().getProject());
89     }
90 }
91
Popular Tags