Search in sources :

Example 36 with ITextViewer

use of org.eclipse.jface.text.ITextViewer in project KaiZen-OpenAPI-Editor by RepreZen.

the class Mocks method mockTextViewer.

public static ITextViewer mockTextViewer(SwaggerDocument document) {
    ITextViewer viewer = mock(ITextViewer.class);
    when(viewer.getDocument()).thenReturn(document);
    return viewer;
}
Also used : ITextViewer(org.eclipse.jface.text.ITextViewer)

Example 37 with ITextViewer

use of org.eclipse.jface.text.ITextViewer in project KaiZen-OpenAPI-Editor by RepreZen.

the class Mocks method mockTextViewer.

public static ITextViewer mockTextViewer(OpenApi3Document document, int offset) {
    ITextViewer viewer = mock(ITextViewer.class);
    ISelectionProvider selectionProvider = mockSelectionProvider();
    ITextSelection selection = mockSelection();
    when(viewer.getDocument()).thenReturn(document);
    when(viewer.getSelectedRange()).thenReturn(new Point(0, 0));
    when(viewer.getSelectionProvider()).thenReturn(selectionProvider);
    when(selectionProvider.getSelection()).thenReturn(selection);
    when(selection.getOffset()).thenReturn(offset);
    return viewer;
}
Also used : ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) Point(org.eclipse.swt.graphics.Point) ITextSelection(org.eclipse.jface.text.ITextSelection) ITextViewer(org.eclipse.jface.text.ITextViewer)

Example 38 with ITextViewer

use of org.eclipse.jface.text.ITextViewer in project KaiZen-OpenAPI-Editor by RepreZen.

the class Mocks method mockTextViewer.

public static ITextViewer mockTextViewer(SwaggerDocument document, int offset) {
    ITextViewer viewer = mock(ITextViewer.class);
    ISelectionProvider selectionProvider = mockSelectionProvider();
    ITextSelection selection = mockSelection();
    when(viewer.getDocument()).thenReturn(document);
    when(viewer.getSelectedRange()).thenReturn(new Point(0, 0));
    when(viewer.getSelectionProvider()).thenReturn(selectionProvider);
    when(selectionProvider.getSelection()).thenReturn(selection);
    when(selection.getOffset()).thenReturn(offset);
    return viewer;
}
Also used : ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) Point(org.eclipse.swt.graphics.Point) ITextSelection(org.eclipse.jface.text.ITextSelection) ITextViewer(org.eclipse.jface.text.ITextViewer)

Example 39 with ITextViewer

use of org.eclipse.jface.text.ITextViewer in project eclipse.platform.text by eclipse.

the class ShowWhitespaceCharactersAction method installPainter.

/**
 * Installs the painter on the editor.
 */
private void installPainter() {
    Assert.isTrue(fWhitespaceCharPainter == null);
    ITextViewer viewer = getTextViewer();
    if (viewer instanceof ITextViewerExtension2) {
        if (fStore != null) {
            fWhitespaceCharPainter = new WhitespaceCharacterPainter(viewer, fShowLeadingSpaces, fShowEnclosedSpaces, fShowTrailingSpaces, fShowLeadingIdeographicSpaces, fShowEnclosedIdeographicSpaces, fShowTrailingIdeographicSpace, fShowLeadingTabs, fShowEnclosedTabs, fShowTrailingTabs, fShowCarriageReturn, fShowLineFeed, fAlpha);
        } else {
            fWhitespaceCharPainter = new WhitespaceCharacterPainter(viewer);
        }
        ((ITextViewerExtension2) viewer).addPainter(fWhitespaceCharPainter);
    }
}
Also used : ITextViewerExtension2(org.eclipse.jface.text.ITextViewerExtension2) ITextViewer(org.eclipse.jface.text.ITextViewer) WhitespaceCharacterPainter(org.eclipse.jface.text.WhitespaceCharacterPainter)

Example 40 with ITextViewer

use of org.eclipse.jface.text.ITextViewer in project eclipse.platform.text by eclipse.

the class TextViewerDeleteLineTarget method clipToVisibleRegion.

/**
 * Clips the given start and end offset to the visible viewer region.
 *
 * @param startOffset the start offset
 * @param endOffset the end offset
 * @return the clipped region
 * @since 3.3.2
 */
private IRegion clipToVisibleRegion(int startOffset, int endOffset) {
    ITextViewer viewer = fClipboard.getViewer();
    IRegion visibleRegion;
    if (viewer instanceof ITextViewerExtension5)
        visibleRegion = ((ITextViewerExtension5) viewer).getModelCoverage();
    else
        visibleRegion = viewer.getVisibleRegion();
    int visibleStart = visibleRegion.getOffset();
    int visibleLength = visibleRegion.getLength();
    startOffset = Math.max(startOffset, visibleStart);
    endOffset = Math.min(endOffset, visibleStart + visibleLength);
    return new Region(startOffset, endOffset - startOffset);
}
Also used : ITextViewerExtension5(org.eclipse.jface.text.ITextViewerExtension5) Region(org.eclipse.jface.text.Region) IRegion(org.eclipse.jface.text.IRegion) IRegion(org.eclipse.jface.text.IRegion) ITextViewer(org.eclipse.jface.text.ITextViewer)

Aggregations

ITextViewer (org.eclipse.jface.text.ITextViewer)75 BadLocationException (org.eclipse.jface.text.BadLocationException)13 IDocument (org.eclipse.jface.text.IDocument)13 Region (org.eclipse.jface.text.Region)13 StyledText (org.eclipse.swt.custom.StyledText)13 IRegion (org.eclipse.jface.text.IRegion)11 ArrayList (java.util.ArrayList)9 Point (org.eclipse.swt.graphics.Point)9 Test (org.junit.Test)9 ITextSelection (org.eclipse.jface.text.ITextSelection)8 IEditorPart (org.eclipse.ui.IEditorPart)8 ITextViewerExtension5 (org.eclipse.jface.text.ITextViewerExtension5)6 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)6 Document (org.eclipse.jface.text.Document)5 IHyperlink (org.eclipse.jface.text.hyperlink.IHyperlink)5 ISourceViewer (org.eclipse.jface.text.source.ISourceViewer)5 Display (org.eclipse.swt.widgets.Display)5 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)5 List (java.util.List)4 ITextViewerExtension (org.eclipse.jface.text.ITextViewerExtension)4