]> git.uio.no Git - ifi-stolz-refaktor.git/blob - case-study/jdt-before/ui/org/eclipse/jdt/internal/ui/text/correction/proposals/MarkerResolutionProposal.java
Some talks, mostly identical.
[ifi-stolz-refaktor.git] / case-study / jdt-before / ui / org / eclipse / jdt / internal / ui / text / correction / proposals / MarkerResolutionProposal.java
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
7  *
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package org.eclipse.jdt.internal.ui.text.correction.proposals;
12
13 import org.eclipse.swt.graphics.Image;
14 import org.eclipse.swt.graphics.Point;
15
16 import org.eclipse.core.runtime.CoreException;
17
18 import org.eclipse.core.resources.IMarker;
19
20 import org.eclipse.jface.text.IDocument;
21 import org.eclipse.jface.text.contentassist.IContextInformation;
22
23 import org.eclipse.ui.IMarkerResolution;
24 import org.eclipse.ui.IMarkerResolution2;
25
26 import org.eclipse.jdt.internal.corext.util.Messages;
27
28 import org.eclipse.jdt.ui.text.java.IJavaCompletionProposal;
29
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;
33
34 public class MarkerResolutionProposal implements IJavaCompletionProposal {
35
36         private IMarkerResolution fResolution;
37         private IMarker fMarker;
38
39         /**
40          * Constructor for MarkerResolutionProposal.
41          * @param resolution the marker resolution
42          * @param marker the marker
43          */
44         public MarkerResolutionProposal(IMarkerResolution resolution, IMarker marker) {
45                 fResolution= resolution;
46                 fMarker= marker;
47         }
48
49         /* (non-Javadoc)
50          * @see org.eclipse.jface.text.contentassist.ICompletionProposal#apply(org.eclipse.jface.text.IDocument)
51          */
52         public void apply(IDocument document) {
53                 fResolution.run(fMarker);
54         }
55
56         /* (non-Javadoc)
57          * @see org.eclipse.jface.text.contentassist.ICompletionProposal#getAdditionalProposalInfo()
58          */
59         public String getAdditionalProposalInfo() {
60                 if (fResolution instanceof IMarkerResolution2) {
61                         return ((IMarkerResolution2) fResolution).getDescription();
62                 }
63                 if (fResolution instanceof IJavaCompletionProposal) {
64                         return ((IJavaCompletionProposal) fResolution).getAdditionalProposalInfo();
65                 }
66                 try {
67                         String problemDesc= (String) fMarker.getAttribute(IMarker.MESSAGE);
68                         return Messages.format(CorrectionMessages.MarkerResolutionProposal_additionaldesc, problemDesc);
69                 } catch (CoreException e) {
70                         JavaPlugin.log(e);
71                 }
72                 return null;
73         }
74
75         /* (non-Javadoc)
76          * @see org.eclipse.jface.text.contentassist.ICompletionProposal#getContextInformation()
77          */
78         public IContextInformation getContextInformation() {
79                 return null;
80         }
81
82         /* (non-Javadoc)
83          * @see org.eclipse.jface.text.contentassist.ICompletionProposal#getDisplayString()
84          */
85         public String getDisplayString() {
86                 return fResolution.getLabel();
87         }
88
89         /* (non-Javadoc)
90          * @see org.eclipse.jface.text.contentassist.ICompletionProposal#getImage()
91          */
92         public Image getImage() {
93                 if (fResolution instanceof IMarkerResolution2) {
94                         return ((IMarkerResolution2) fResolution).getImage();
95                 }
96                 if (fResolution instanceof IJavaCompletionProposal) {
97                         return ((IJavaCompletionProposal) fResolution).getImage();
98                 }
99                 return JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
100         }
101
102         /* (non-Javadoc)
103          * @see org.eclipse.jdt.internal.ui.text.java.IJavaCompletionProposal#getRelevance()
104          */
105         public int getRelevance() {
106                 if (fResolution instanceof IJavaCompletionProposal) {
107                         return ((IJavaCompletionProposal) fResolution).getRelevance();
108                 }
109                 return 10;
110         }
111
112         /* (non-Javadoc)
113          * @see org.eclipse.jface.text.contentassist.ICompletionProposal#getSelection(org.eclipse.jface.text.IDocument)
114          */
115         public Point getSelection(IDocument document) {
116                 if (fResolution instanceof IJavaCompletionProposal) {
117                         return ((IJavaCompletionProposal) fResolution).getSelection(document);
118                 }
119                 return null;
120         }
121
122 }