1 11 package org.eclipse.jdt.internal.ui.text.correction; 12 13 import org.eclipse.core.resources.IMarker; 14 import org.eclipse.core.runtime.CoreException; 15 16 import org.eclipse.swt.graphics.Image; 17 import org.eclipse.swt.graphics.Point; 18 19 import org.eclipse.jface.text.IDocument; 20 import org.eclipse.jface.text.contentassist.IContextInformation; 21 22 import org.eclipse.ui.IMarkerResolution; 23 import org.eclipse.ui.IMarkerResolution2; 24 25 import org.eclipse.jdt.internal.corext.util.Messages; 26 27 import org.eclipse.jdt.ui.text.java.IJavaCompletionProposal; 28 29 import org.eclipse.jdt.internal.ui.JavaPlugin; 30 import org.eclipse.jdt.internal.ui.JavaPluginImages; 31 32 34 public class MarkerResolutionProposal implements IJavaCompletionProposal { 35 36 private IMarkerResolution fResolution; 37 private IMarker fMarker; 38 39 42 public MarkerResolutionProposal(IMarkerResolution resolution, IMarker marker) { 43 fResolution= resolution; 44 fMarker= marker; 45 } 46 47 50 public void apply(IDocument document) { 51 fResolution.run(fMarker); 52 } 53 54 57 public String getAdditionalProposalInfo() { 58 if (fResolution instanceof IMarkerResolution2) { 59 return ((IMarkerResolution2) fResolution).getDescription(); 60 } 61 if (fResolution instanceof IJavaCompletionProposal) { 62 return ((IJavaCompletionProposal) fResolution).getAdditionalProposalInfo(); 63 } 64 try { 65 String problemDesc= (String ) fMarker.getAttribute(IMarker.MESSAGE); 66 return Messages.format(CorrectionMessages.MarkerResolutionProposal_additionaldesc, problemDesc); 67 } catch (CoreException e) { 68 JavaPlugin.log(e); 69 } 70 return null; 71 } 72 73 76 public IContextInformation getContextInformation() { 77 return null; 78 } 79 80 83 public String getDisplayString() { 84 return fResolution.getLabel(); 85 } 86 87 90 public Image getImage() { 91 if (fResolution instanceof IMarkerResolution2) { 92 return ((IMarkerResolution2) fResolution).getImage(); 93 } 94 if (fResolution instanceof IJavaCompletionProposal) { 95 return ((IJavaCompletionProposal) fResolution).getImage(); 96 } 97 return JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE); 98 } 99 100 103 public int getRelevance() { 104 if (fResolution instanceof IJavaCompletionProposal) { 105 return ((IJavaCompletionProposal) fResolution).getRelevance(); 106 } 107 return 10; 108 } 109 110 113 public Point getSelection(IDocument document) { 114 if (fResolution instanceof IJavaCompletionProposal) { 115 return ((IJavaCompletionProposal) fResolution).getSelection(document); 116 } 117 return null; 118 } 119 120 } 121 | Popular Tags |