Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMickael Istria2016-10-11 04:01:06 -0400
committerMickael Istria2016-10-11 10:36:35 -0400
commit8cbe29285e04f0b0e23b0346e953a62f0a8ccd75 (patch)
tree78d3d5725adaf234bcaae0154b8269fe356dc4df
parentd929f218362bd560d9a6e43bf62820b06a1dcf79 (diff)
downloadeclipse.platform.text-8cbe29285e04f0b0e23b0346e953a62f0a8ccd75.tar.gz
eclipse.platform.text-8cbe29285e04f0b0e23b0346e953a62f0a8ccd75.tar.xz
eclipse.platform.text-8cbe29285e04f0b0e23b0346e953a62f0a8ccd75.zip
Bug 503332 - Show pop-up for problems on text on Generic Editor
It's just a regular Hover extension with highest priority Change-Id: Ic01f765f6abae99a18dba5817e26a1a6e8d1cd7a Signed-off-by: Mickael Istria <mistria@redhat.com>
-rw-r--r--org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/HoverTest.java39
-rw-r--r--org.eclipse.ui.genericeditor/plugin.xml10
-rw-r--r--org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/AnnotationHoverDelegate.java73
3 files changed, 115 insertions, 7 deletions
diff --git a/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/HoverTest.java b/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/HoverTest.java
index 37f4f1b09..86f5bae8e 100644
--- a/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/HoverTest.java
+++ b/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/HoverTest.java
@@ -27,6 +27,8 @@ import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
+import org.eclipse.core.resources.IMarker;
+
import org.eclipse.jface.text.AbstractHoverInformationControlManager;
import org.eclipse.jface.text.AbstractInformationControlManager;
import org.eclipse.jface.text.ITextViewer;
@@ -70,13 +72,30 @@ public class HoverTest {
@Test
public void testHover() throws Exception {
- this.editor.selectAndReveal(2, 0);
- // Events need to be processed for hover listener to work correctly
- long timeout = 1000;
- long start = System.currentTimeMillis();
- while (start + timeout > System.currentTimeMillis()) {
- Display.getDefault().readAndDispatch();
+ assertEquals("Alrighty!", getHoverData());
+ }
+
+ @Test
+ public void testProblemHover() throws Exception {
+ String problemMessage = "Huston...";
+ IMarker marker = null;
+ try {
+ marker = GenericEditorTestUtils.getFile().createMarker(IMarker.PROBLEM);
+ marker.setAttribute(IMarker.LINE_NUMBER, 1);
+ marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
+ marker.setAttribute(IMarker.CHAR_START, 0);
+ marker.setAttribute(IMarker.CHAR_END, 5);
+ marker.setAttribute(IMarker.MESSAGE, problemMessage);
+ assertEquals(problemMessage, getHoverData());
+ } finally {
+ if (marker != null) {
+ marker.delete();
+ }
}
+ }
+
+ private Object getHoverData() throws Exception {
+ this.editor.selectAndReveal(2, 0);
// sending event to trigger hover computation
StyledText editorTextWidget = (StyledText) this.editor.getAdapter(Control.class);
editorTextWidget.getShell().forceActive();
@@ -91,6 +110,12 @@ public class HoverTest {
hoverEvent.display = editorTextWidget.getDisplay();
hoverEvent.doit = true;
editorTextWidget.notifyListeners(SWT.MouseHover, hoverEvent);
+ // Events need to be processed for hover listener to work correctly
+ long timeout = 1000; //ms
+ long start = System.currentTimeMillis();
+ while (start + timeout > System.currentTimeMillis()) {
+ Display.getDefault().readAndDispatch();
+ }
// retrieving hover content
Method getSourceViewerMethod= AbstractTextEditor.class.getDeclaredMethod("getSourceViewer");
getSourceViewerMethod.setAccessible(true);
@@ -102,7 +127,7 @@ public class HoverTest {
informationField.setAccessible(true);
Object hoverData = informationField.get(hover);
Thread.sleep(500); // hoverData populated asynchronously
- assertEquals("Alrighty!", hoverData);
+ return hoverData;
}
}
diff --git a/org.eclipse.ui.genericeditor/plugin.xml b/org.eclipse.ui.genericeditor/plugin.xml
index e5a4ad570..5da1470b6 100644
--- a/org.eclipse.ui.genericeditor/plugin.xml
+++ b/org.eclipse.ui.genericeditor/plugin.xml
@@ -70,4 +70,14 @@
</command>
</menuContribution>
</extension>
+ <extension
+ point="org.eclipse.ui.genericeditor.hoverProviders">
+ <hoverProvider
+ isBefore="*"
+ class="org.eclipse.ui.internal.genericeditor.AnnotationHoverDelegate"
+ contentType="org.eclipse.core.runtime.text"
+ id="org.eclipse.ui.genericeditor.annotationsHoverProvider">
+ </hoverProvider>
+ </extension>
+
</plugin>
diff --git a/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/AnnotationHoverDelegate.java b/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/AnnotationHoverDelegate.java
new file mode 100644
index 000000000..7eb4e2e22
--- /dev/null
+++ b/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/AnnotationHoverDelegate.java
@@ -0,0 +1,73 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Red Hat Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * - Mickael Istria (Red Hat Inc.)
+ *******************************************************************************/
+package org.eclipse.ui.internal.genericeditor;
+
+import org.eclipse.jface.text.DefaultTextHover;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.ITextHover;
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.source.Annotation;
+import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.ui.editors.text.EditorsUI;
+import org.eclipse.ui.texteditor.AnnotationPreference;
+
+/**
+ * Delegate to {@link DefaultTextHover}, since we need a parameter-less
+ * constructor.
+ */
+public class AnnotationHoverDelegate implements ITextHover {
+
+ private DefaultTextHover delegate;
+ private ISourceViewer viewer;
+
+ private DefaultTextHover getDelegate(ISourceViewer sourceViewer) {
+ if (this.delegate == null || this.viewer != sourceViewer) {
+ this.delegate = new DefaultTextHover(sourceViewer) {
+ @Override
+ protected boolean isIncluded(Annotation annotation) {
+ AnnotationPreference preference= EditorsUI.getAnnotationPreferenceLookup().getAnnotationPreference(annotation);
+ if (preference == null)
+ return false;
+ String key= preference.getTextPreferenceKey();
+ if (key != null) {
+ if (!EditorsUI.getPreferenceStore().getBoolean(key))
+ return false;
+ } else {
+ key= preference.getHighlightPreferenceKey();
+ if (key == null || !EditorsUI.getPreferenceStore().getBoolean(key))
+ return false;
+ }
+ return true;
+ }
+ };
+ this.viewer = sourceViewer;
+ }
+ return this.delegate;
+ }
+
+ @Override
+ public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) {
+ if (textViewer instanceof ISourceViewer) {
+ return getDelegate((ISourceViewer)textViewer).getHoverInfo(textViewer, hoverRegion);
+ }
+ return null;
+ }
+
+ @Override
+ public IRegion getHoverRegion(ITextViewer textViewer, int offset) {
+ if (textViewer instanceof ISourceViewer) {
+ return getDelegate((ISourceViewer)textViewer).getHoverRegion(textViewer, offset);
+ }
+ return null;
+ }
+
+
+}

Back to the top