Search in sources :

Example 1 with AbstractInformationControlManager

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;
}
Also used : AbstractInformationControl(org.eclipse.jface.text.AbstractInformationControl) Control(org.eclipse.swt.widgets.Control) StyledText(org.eclipse.swt.custom.StyledText) AbstractInformationControlManager(org.eclipse.jface.text.AbstractInformationControlManager) Event(org.eclipse.swt.widgets.Event) DisplayHelper(org.eclipse.jface.text.tests.util.DisplayHelper) Accessor(org.eclipse.text.tests.Accessor) ITextViewer(org.eclipse.jface.text.ITextViewer)

Example 2 with AbstractInformationControlManager

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();
        }
    }
}
Also used : Shell(org.eclipse.swt.widgets.Shell) StyledText(org.eclipse.swt.custom.StyledText) AbstractInformationControlManager(org.eclipse.jface.text.AbstractInformationControlManager) Label(org.eclipse.swt.widgets.Label) Event(org.eclipse.swt.widgets.Event) DisplayHelper(org.eclipse.jface.text.tests.util.DisplayHelper) IMarker(org.eclipse.core.resources.IMarker) Map(java.util.Map) Link(org.eclipse.swt.widgets.Link) ScreenshotTest(org.eclipse.ui.workbench.texteditor.tests.ScreenshotTest) Test(org.junit.Test)

Aggregations

AbstractInformationControlManager (org.eclipse.jface.text.AbstractInformationControlManager)2 DisplayHelper (org.eclipse.jface.text.tests.util.DisplayHelper)2 StyledText (org.eclipse.swt.custom.StyledText)2 Event (org.eclipse.swt.widgets.Event)2 Map (java.util.Map)1 IMarker (org.eclipse.core.resources.IMarker)1 AbstractInformationControl (org.eclipse.jface.text.AbstractInformationControl)1 ITextViewer (org.eclipse.jface.text.ITextViewer)1 Control (org.eclipse.swt.widgets.Control)1 Label (org.eclipse.swt.widgets.Label)1 Link (org.eclipse.swt.widgets.Link)1 Shell (org.eclipse.swt.widgets.Shell)1 Accessor (org.eclipse.text.tests.Accessor)1 ScreenshotTest (org.eclipse.ui.workbench.texteditor.tests.ScreenshotTest)1 Test (org.junit.Test)1