Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 184639
Collapse All | Expand All

(-)src/org/eclipse/linuxtools/rpm/ui/editor/AnnotationHover.java (+99 lines)
Line 0 Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2003 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
11
12
*******************************************************************************/
13
package org.eclipse.linuxtools.rpm.ui.editor;
14
15
import java.util.ArrayList;
16
import java.util.Iterator;
17
18
import org.eclipse.core.resources.IMarker;
19
import org.eclipse.jface.text.BadLocationException;
20
import org.eclipse.jface.text.IDocument;
21
import org.eclipse.jface.text.Position;
22
import org.eclipse.jface.text.source.IAnnotationHover;
23
import org.eclipse.jface.text.source.IAnnotationModel;
24
import org.eclipse.jface.text.source.ISourceViewer;
25
import org.eclipse.ui.texteditor.MarkerAnnotation;
26
27
28
/**
29
 * Class derived from org.eclipse.pde.internal.ui.editor.text.AnnotationHover
30
 * 
31
 */
32
public class AnnotationHover implements IAnnotationHover {
33
34
35
	public String getHoverInfo(ISourceViewer sourceViewer, int lineNumber) {
36
		String[] messages = getMessagesForLine(sourceViewer, lineNumber);
37
38
39
		if (messages.length == 0)
40
			return null;
41
42
43
		StringBuffer buffer = new StringBuffer();
44
		for (int i = 0; i < messages.length; i++) {
45
			buffer.append(messages[i]);
46
			if (i < messages.length - 1)
47
				buffer.append(System.getProperty("line.separator")); //$NON-NLS-1$
48
		}
49
		return buffer.toString();
50
	}
51
52
53
	private String[] getMessagesForLine(ISourceViewer viewer, int line) {
54
		IDocument document = viewer.getDocument();
55
		IAnnotationModel model = viewer.getAnnotationModel();
56
57
58
		if (model == null)
59
			return new String[0];
60
61
62
		ArrayList messages = new ArrayList();
63
64
65
		Iterator iter = model.getAnnotationIterator();
66
		while (iter.hasNext()) {
67
			Object object = iter.next();
68
			if (object instanceof MarkerAnnotation) {
69
				MarkerAnnotation annotation = (MarkerAnnotation) object;
70
				if (compareRulerLine(model.getPosition(annotation),
71
					document,
72
					line)) {
73
					IMarker marker = annotation.getMarker();
74
					String message =
75
						marker.getAttribute(IMarker.MESSAGE, (String) null);
76
					if (message != null && message.trim().length() > 0)
77
						messages.add(message);
78
				}
79
			}
80
		}
81
		return (String[]) messages.toArray(new String[messages.size()]);
82
	}
83
84
85
	private boolean compareRulerLine(
86
		Position position,
87
		IDocument document,
88
		int line) {
89
90
91
		try {
92
			if (position.getOffset() > -1 && position.getLength() > -1) {
93
				return document.getLineOfOffset(position.getOffset()) == line;
94
			}
95
		} catch (BadLocationException e) {
96
		}
97
		return false;
98
	}
99
}
(-)src/org/eclipse/linuxtools/rpm/ui/editor/SpecfileConfiguration.java (+11 lines)
Lines 19-24 Link Here
19
import org.eclipse.jface.text.reconciler.MonoReconciler;
19
import org.eclipse.jface.text.reconciler.MonoReconciler;
20
import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
20
import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
21
import org.eclipse.jface.text.rules.Token;
21
import org.eclipse.jface.text.rules.Token;
22
import org.eclipse.jface.text.source.IAnnotationHover;
22
import org.eclipse.jface.text.source.ISourceViewer;
23
import org.eclipse.jface.text.source.ISourceViewer;
23
import org.eclipse.jface.text.source.SourceViewerConfiguration;
24
import org.eclipse.jface.text.source.SourceViewerConfiguration;
24
import org.eclipse.swt.SWT;
25
import org.eclipse.swt.SWT;
Lines 32-37 Link Here
32
	private ColorManager colorManager;
33
	private ColorManager colorManager;
33
	private SpecfileHover specfileHover;
34
	private SpecfileHover specfileHover;
34
	private SpecfileEditor editor;
35
	private SpecfileEditor editor;
36
	private AnnotationHover annotationHover;
35
37
36
	public SpecfileConfiguration(ColorManager colorManager, SpecfileEditor editor) {
38
	public SpecfileConfiguration(ColorManager colorManager, SpecfileEditor editor) {
37
		this.colorManager = colorManager;
39
		this.colorManager = colorManager;
Lines 171-175 Link Here
171
			return null;
173
			return null;
172
		return new IHyperlinkDetector[] { new URLHyperlinkWithMacroDetector(editor.getSpecfile())};
174
		return new IHyperlinkDetector[] { new URLHyperlinkWithMacroDetector(editor.getSpecfile())};
173
	}
175
	}
176
	
177
	/* (non-Javadoc)
178
	 * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getAnnotationHover(org.eclipse.jface.text.source.ISourceViewer)
179
	 */
180
	public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) {
181
		if (annotationHover == null)
182
			annotationHover = new AnnotationHover();
183
		return annotationHover;
184
	}
174
		
185
		
175
}
186
}

Return to bug 184639