Search in sources :

Example 1 with DisplayHelper

use of org.eclipse.jface.text.tests.util.DisplayHelper 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 DisplayHelper

use of org.eclipse.jface.text.tests.util.DisplayHelper 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)

Example 3 with DisplayHelper

use of org.eclipse.jface.text.tests.util.DisplayHelper in project eclipse.platform.text by eclipse.

the class ReconcilerTest method performTestOnEditor.

private void performTestOnEditor(String startingText, ExtensionBasedTextEditor textEditor, String expectedText) throws Exception {
    IDocumentProvider dp = textEditor.getDocumentProvider();
    IDocument doc = dp.getDocument(textEditor.getEditorInput());
    doc.set(startingText);
    new DisplayHelper() {

        @Override
        protected boolean condition() {
            try {
                return doc.get(0, doc.getLineLength(0)).contains(expectedText);
            } catch (BadLocationException e) {
                return false;
            }
        }
    }.waitForCondition(Display.getDefault().getActiveShell().getDisplay(), 2000);
    Assert.assertTrue("file was not affected by reconciler", doc.get().contains(expectedText));
}
Also used : IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) DisplayHelper(org.eclipse.jface.text.tests.util.DisplayHelper) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 4 with DisplayHelper

use of org.eclipse.jface.text.tests.util.DisplayHelper in project eclipse.platform.text by eclipse.

the class CompletionTest method checkCompletionContent.

/**
 * Checks that completion behaves as expected:
 * 1. Computing is shown instantaneously
 * 2. 1st proposal shown instantaneously
 * 3. 2s later, 2nd proposal is shown
 * @param completionProposalList the completion list
 */
private void checkCompletionContent(final Table completionProposalList) {
    // should be instantaneous, but happens to go asynchronous on CI so let's allow a wait
    new DisplayHelper() {

        @Override
        protected boolean condition() {
            return completionProposalList.getItemCount() == 2;
        }
    }.waitForCondition(completionProposalList.getDisplay(), 200);
    assertEquals(2, completionProposalList.getItemCount());
    final TableItem computingItem = completionProposalList.getItem(0);
    // $NON-NLS-1$ //$NON-NLS-2$
    assertTrue("Missing computing info entry", computingItem.getText().contains("Computing"));
    TableItem completionProposalItem = completionProposalList.getItem(1);
    final ICompletionProposal selectedProposal = (ICompletionProposal) completionProposalItem.getData();
    assertTrue("Incorrect proposal content", BarContentAssistProcessor.PROPOSAL.endsWith(selectedProposal.getDisplayString()));
    completionProposalList.setSelection(completionProposalItem);
    // asynchronous
    new DisplayHelper() {

        @Override
        protected boolean condition() {
            return completionProposalList.getItem(0) != computingItem && completionProposalList.getItemCount() == 2;
        }
    }.waitForCondition(completionProposalList.getDisplay(), LongRunningBarContentAssistProcessor.DELAY + 200);
    completionProposalItem = completionProposalList.getItem(0);
    assertTrue("Proposal content seems incorrect", BarContentAssistProcessor.PROPOSAL.endsWith(((ICompletionProposal) completionProposalItem.getData()).getDisplayString()));
    TableItem otherProposalItem = completionProposalList.getItem(1);
    assertTrue("Proposal content seems incorrect", LongRunningBarContentAssistProcessor.PROPOSAL.endsWith(((ICompletionProposal) otherProposalItem.getData()).getDisplayString()));
    assertEquals("Addition of completion proposal should keep selection", selectedProposal, completionProposalList.getSelection()[0].getData());
}
Also used : TableItem(org.eclipse.swt.widgets.TableItem) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) DisplayHelper(org.eclipse.jface.text.tests.util.DisplayHelper)

Example 5 with DisplayHelper

use of org.eclipse.jface.text.tests.util.DisplayHelper in project eclipse.platform.text by eclipse.

the class CompletionTest method testCompletionFreeze_bug521484.

@Test
public void testCompletionFreeze_bug521484() throws Exception {
    final Set<Shell> beforeShells = Arrays.stream(editor.getSite().getShell().getDisplay().getShells()).filter(Shell::isVisible).collect(Collectors.toSet());
    editor.selectAndReveal(3, 0);
    ContentAssistAction action = (ContentAssistAction) editor.getAction(ITextEditorActionConstants.CONTENT_ASSIST);
    action.update();
    action.run();
    waitAndDispatch(100);
    this.completionShell = findNewShell(beforeShells);
    final Table completionProposalList = findCompletionSelectionControl(this.completionShell);
    // should be instantaneous, but happens to go asynchronous on CI so let's allow a wait
    new DisplayHelper() {

        @Override
        protected boolean condition() {
            return completionProposalList.getItemCount() == 2;
        }
    }.waitForCondition(completionShell.getDisplay(), 200);
    assertEquals(2, completionProposalList.getItemCount());
    final TableItem computingItem = completionProposalList.getItem(0);
    // $NON-NLS-1$ //$NON-NLS-2$
    assertTrue("Missing computing info entry", computingItem.getText().contains("Computing"));
    // Some processors are long running, moving cursor can cause freeze (bug 521484)
    // asynchronous
    long timestamp = System.currentTimeMillis();
    emulatePressLeftArrowKey();
    // give time to process events
    DisplayHelper.sleep(editor.getSite().getShell().getDisplay(), 200);
    long processingDuration = System.currentTimeMillis() - timestamp;
    assertTrue("UI Thread frozen for " + processingDuration + "ms", processingDuration < LongRunningBarContentAssistProcessor.DELAY);
}
Also used : Shell(org.eclipse.swt.widgets.Shell) Table(org.eclipse.swt.widgets.Table) TableItem(org.eclipse.swt.widgets.TableItem) ContentAssistAction(org.eclipse.ui.texteditor.ContentAssistAction) DisplayHelper(org.eclipse.jface.text.tests.util.DisplayHelper) Test(org.junit.Test)

Aggregations

DisplayHelper (org.eclipse.jface.text.tests.util.DisplayHelper)6 Shell (org.eclipse.swt.widgets.Shell)3 AbstractInformationControl (org.eclipse.jface.text.AbstractInformationControl)2 AbstractInformationControlManager (org.eclipse.jface.text.AbstractInformationControlManager)2 StyledText (org.eclipse.swt.custom.StyledText)2 Event (org.eclipse.swt.widgets.Event)2 TableItem (org.eclipse.swt.widgets.TableItem)2 Accessor (org.eclipse.text.tests.Accessor)2 Test (org.junit.Test)2 Map (java.util.Map)1 IMarker (org.eclipse.core.resources.IMarker)1 BadLocationException (org.eclipse.jface.text.BadLocationException)1 IDocument (org.eclipse.jface.text.IDocument)1 ITextViewer (org.eclipse.jface.text.ITextViewer)1 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)1 Control (org.eclipse.swt.widgets.Control)1 Label (org.eclipse.swt.widgets.Label)1 Link (org.eclipse.swt.widgets.Link)1 Table (org.eclipse.swt.widgets.Table)1 ContentAssistAction (org.eclipse.ui.texteditor.ContentAssistAction)1