use of org.eclipse.jface.text.AbstractInformationControlManager in project eclipse.platform.text by eclipse.
the class HoverTest method triggerCompletionAndRetrieveInformationControlManager.
private AbstractInformationControlManager triggerCompletionAndRetrieveInformationControlManager() {
this.editor.selectAndReveal(2, 0);
final StyledText editorTextWidget = (StyledText) this.editor.getAdapter(Control.class);
new DisplayHelper() {
@Override
protected boolean condition() {
return editorTextWidget.isFocusControl() && editorTextWidget.getSelection().x == 2;
}
}.waitForCondition(editorTextWidget.getDisplay(), 1000);
// sending event to trigger hover computation
editorTextWidget.getShell().forceActive();
editorTextWidget.getShell().setActive();
editorTextWidget.getShell().setFocus();
editorTextWidget.getShell().getDisplay().wake();
Event hoverEvent = new Event();
hoverEvent.widget = editorTextWidget;
hoverEvent.type = SWT.MouseHover;
hoverEvent.x = editorTextWidget.getClientArea().x + 5;
hoverEvent.y = editorTextWidget.getClientArea().y + 5;
hoverEvent.display = editorTextWidget.getDisplay();
hoverEvent.doit = true;
editorTextWidget.getDisplay().setCursorLocation(editorTextWidget.toDisplay(hoverEvent.x, hoverEvent.y));
editorTextWidget.notifyListeners(SWT.MouseHover, hoverEvent);
// Events need to be processed for hover listener to work correctly
DisplayHelper.sleep(editorTextWidget.getDisplay(), 1000);
// retrieving hover content
ITextViewer viewer = (ITextViewer) new Accessor(editor, AbstractTextEditor.class).invoke("getSourceViewer", new Object[0]);
AbstractInformationControlManager textHoverManager = (AbstractInformationControlManager) new Accessor(viewer, TextViewer.class).get("fTextHoverManager");
return textHoverManager;
}
use of org.eclipse.jface.text.AbstractInformationControlManager in project eclipse.platform.text by eclipse.
the class HoverTest method testProblemHover.
@Test
public void testProblemHover() throws Exception {
String problemMessage = "Huston...";
IMarker marker = null;
try {
marker = this.file.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);
marker.setAttribute(MarkerResolutionGenerator.FIXME, true);
AbstractInformationControlManager manager = triggerCompletionAndRetrieveInformationControlManager();
Object hoverData = getHoverData(manager);
assertTrue(hoverData instanceof Map);
assertTrue(((Map<?, ?>) hoverData).containsValue(Collections.singletonList(marker)));
assertTrue(((Map<?, ?>) hoverData).containsValue(AlrightyHoverProvider.LABEL));
assertFalse(((Map<?, ?>) hoverData).containsValue(HelloHoverProvider.LABEL));
// check dialog content
Shell shell = getHoverShell(manager);
assertNotNull(findControl(shell, Label.class, marker.getAttribute(IMarker.MESSAGE, "NONE")));
assertNotNull(findControl(shell, StyledText.class, AlrightyHoverProvider.LABEL));
assertNull(findControl(shell, StyledText.class, HelloHoverProvider.LABEL));
// check quick-fix works
Link link = findControl(shell, Link.class, MarkerResolutionGenerator.FIXME);
assertNotNull(link);
Event event = new Event();
event.widget = link;
event.display = link.getDisplay();
event.doit = true;
event.type = SWT.Selection;
link.notifyListeners(SWT.Selection, event);
final IMarker m = marker;
new DisplayHelper() {
@Override
protected boolean condition() {
return !m.exists();
}
}.waitForCondition(event.display, 1000);
assertFalse(marker.exists());
} finally {
if (marker != null && marker.exists()) {
marker.delete();
}
}
}
Aggregations