1 /*******************************************************************************
2 * Copyright (c) 2000, 2008 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
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package org.eclipse.jdt.internal.ui.text.correction.proposals;
13 import org.eclipse.swt.graphics.Image;
14 import org.eclipse.swt.graphics.Point;
16 import org.eclipse.core.runtime.CoreException;
18 import org.eclipse.core.resources.IMarker;
20 import org.eclipse.jface.text.IDocument;
21 import org.eclipse.jface.text.contentassist.IContextInformation;
23 import org.eclipse.ui.IMarkerResolution;
24 import org.eclipse.ui.IMarkerResolution2;
26 import org.eclipse.jdt.internal.corext.util.Messages;
28 import org.eclipse.jdt.ui.text.java.IJavaCompletionProposal;
30 import org.eclipse.jdt.internal.ui.JavaPlugin;
31 import org.eclipse.jdt.internal.ui.JavaPluginImages;
32 import org.eclipse.jdt.internal.ui.text.correction.CorrectionMessages;
34 public class MarkerResolutionProposal implements IJavaCompletionProposal {
36 private IMarkerResolution fResolution;
37 private IMarker fMarker;
40 * Constructor for MarkerResolutionProposal.
41 * @param resolution the marker resolution
42 * @param marker the marker
44 public MarkerResolutionProposal(IMarkerResolution resolution, IMarker marker) {
45 fResolution= resolution;
50 * @see org.eclipse.jface.text.contentassist.ICompletionProposal#apply(org.eclipse.jface.text.IDocument)
52 public void apply(IDocument document) {
53 fResolution.run(fMarker);
57 * @see org.eclipse.jface.text.contentassist.ICompletionProposal#getAdditionalProposalInfo()
59 public String getAdditionalProposalInfo() {
60 if (fResolution instanceof IMarkerResolution2) {
61 return ((IMarkerResolution2) fResolution).getDescription();
63 if (fResolution instanceof IJavaCompletionProposal) {
64 return ((IJavaCompletionProposal) fResolution).getAdditionalProposalInfo();
67 String problemDesc= (String) fMarker.getAttribute(IMarker.MESSAGE);
68 return Messages.format(CorrectionMessages.MarkerResolutionProposal_additionaldesc, problemDesc);
69 } catch (CoreException e) {
76 * @see org.eclipse.jface.text.contentassist.ICompletionProposal#getContextInformation()
78 public IContextInformation getContextInformation() {
83 * @see org.eclipse.jface.text.contentassist.ICompletionProposal#getDisplayString()
85 public String getDisplayString() {
86 return fResolution.getLabel();
90 * @see org.eclipse.jface.text.contentassist.ICompletionProposal#getImage()
92 public Image getImage() {
93 if (fResolution instanceof IMarkerResolution2) {
94 return ((IMarkerResolution2) fResolution).getImage();
96 if (fResolution instanceof IJavaCompletionProposal) {
97 return ((IJavaCompletionProposal) fResolution).getImage();
99 return JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
103 * @see org.eclipse.jdt.internal.ui.text.java.IJavaCompletionProposal#getRelevance()
105 public int getRelevance() {
106 if (fResolution instanceof IJavaCompletionProposal) {
107 return ((IJavaCompletionProposal) fResolution).getRelevance();
113 * @see org.eclipse.jface.text.contentassist.ICompletionProposal#getSelection(org.eclipse.jface.text.IDocument)
115 public Point getSelection(IDocument document) {
116 if (fResolution instanceof IJavaCompletionProposal) {
117 return ((IJavaCompletionProposal) fResolution).getSelection(document);