Search in sources :

Example 71 with ITextViewer

use of org.eclipse.jface.text.ITextViewer in project mylyn.docs by eclipse.

the class FileRefHyperlinkDetectorTest method testDeeperNestedFolderStructure.

@Test
public void testDeeperNestedFolderStructure() throws CoreException {
    IFolder folder = project.getFolder("AsciiDoctor Tutorial");
    if (!folder.exists()) {
        folder.create(IResource.NONE, true, new NullProgressMonitor());
    }
    IFolder nestedResourcesFolder = folder.getFolder("resources");
    if (!nestedResourcesFolder.exists()) {
        nestedResourcesFolder.create(IResource.NONE, true, new NullProgressMonitor());
    }
    IFile fileInNestedFolder = nestedResourcesFolder.getFile("nested-document.adoc");
    if (!fileInNestedFolder.exists()) {
        fileInNestedFolder.create(new ByteArrayInputStream("include::../../article.adoc[]".getBytes()), true, new NullProgressMonitor());
    }
    IFile articleFile = project.getFile("article.adoc");
    if (!articleFile.exists()) {
        articleFile.create(new ByteArrayInputStream("== Overview".getBytes()), true, new NullProgressMonitor());
    }
    ImmutableList<String> fileRefPatterns = ImmutableList.of("include::(.+)\\[\\]", "image::(.+)\\[\\]");
    FileRefHyperlinkDetector fileRefHyperlinkDetector = new FileRefHyperlinkDetector(fileInNestedFolder.getParent(), fileRefPatterns);
    ITextViewer mockTextViewer = mock(ITextViewer.class);
    when(mockTextViewer.getDocument()).thenReturn(new Document("include::../../article.adoc[]"));
    IHyperlink[] detectHyperlinks = fileRefHyperlinkDetector.detectHyperlinks(mockTextViewer, new Region(9, 17), false);
    assertThat(detectHyperlinks.length, is(1));
    IHyperlink hyperlink = detectHyperlinks[0];
    hyperlink.open();
    IEditorPart activeEditor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
    IEditorInput editorInput = activeEditor.getEditorInput();
    if (editorInput instanceof IFileEditorInput) {
        IFile editorFile = ((IFileEditorInput) editorInput).getFile();
        assertThat(articleFile, equalTo(editorFile));
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) IEditorPart(org.eclipse.ui.IEditorPart) Document(org.eclipse.jface.text.Document) ITextViewer(org.eclipse.jface.text.ITextViewer) FileRefHyperlinkDetector(org.eclipse.mylyn.internal.wikitext.ui.editor.syntax.FileRefHyperlinkDetector) ByteArrayInputStream(java.io.ByteArrayInputStream) IHyperlink(org.eclipse.jface.text.hyperlink.IHyperlink) IFileEditorInput(org.eclipse.ui.IFileEditorInput) Region(org.eclipse.jface.text.Region) IEditorInput(org.eclipse.ui.IEditorInput) IFolder(org.eclipse.core.resources.IFolder) Test(org.junit.Test)

Example 72 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) {
    ITextViewer viewer = mock(ITextViewer.class);
    when(viewer.getDocument()).thenReturn(document);
    return viewer;
}
Also used : ITextViewer(org.eclipse.jface.text.ITextViewer)

Example 73 with ITextViewer

use of org.eclipse.jface.text.ITextViewer in project jbosstools-hibernate by jbosstools.

the class DynamicSQLPreviewView method setCurrentEditor.

private void setCurrentEditor(HQLEditor editor) {
    if (editor == currentEditor) {
        updateText(currentEditor);
        return;
    }
    if (currentEditor != null) {
        reconciler.uninstall();
    }
    currentEditor = editor;
    if (currentEditor != null) {
        ITextViewer editorViewer = currentEditor.getTextViewer();
        reconciler.install(editorViewer);
    }
    updateText(currentEditor);
}
Also used : ITextViewer(org.eclipse.jface.text.ITextViewer)

Example 74 with ITextViewer

use of org.eclipse.jface.text.ITextViewer in project erlide_eclipse by erlang.

the class ErlTextHover method getHoverInfoForOffset.

public static ErlangBrowserInformationControlInput getHoverInfoForOffset(final int offset, final ErlangEditor editor) {
    final ITextViewer textViewer = editor.getViewer();
    final IRegion region = ErlTextHover.internalGetHoverRegion(offset, editor);
    if (region != null) {
        return ErlTextHover.internalGetHoverInfo(editor, textViewer, region);
    }
    return null;
}
Also used : IRegion(org.eclipse.jface.text.IRegion) ITextViewer(org.eclipse.jface.text.ITextViewer)

Example 75 with ITextViewer

use of org.eclipse.jface.text.ITextViewer in project erlide_eclipse by erlang.

the class ToggleCommentHandler method doAction.

@Override
protected void doAction(final ISelection sel, final ITextEditor textEditor) {
    final IDocument document = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput());
    final ITextSelection selection = ErlangAbstractHandler.extendSelectionToWholeLines(document, (ITextSelection) sel);
    final ITextSelection getSelection = getTextSelection(document, selection, textEditor);
    String text;
    OtpErlangObject r1 = null;
    try {
        text = document.get(getSelection.getOffset(), getSelection.getLength());
        // call erlang, with selection within text
        r1 = callErlang(selection.getOffset() - getSelection.getOffset(), selection.getLength(), text);
    } catch (final Exception e) {
        ErlLogger.error(e);
    }
    final String newText = Util.stringValue(r1);
    if (newText == null) {
        final String msg = "call to " + getClass().getSimpleName() + " timed out; try a smaller selection.";
        final Status status = new Status(IStatus.ERROR, ErlangCore.PLUGIN_ID, ErlangStatus.INTERNAL_ERROR.getValue(), msg, null);
        ErlLogger.error("INTERNAL ERROR: " + msg);
        ErrorDialog.openError(textEditor.getSite().getShell(), ActionMessages.IndentAction_error_message, "Internal error", status);
        return;
    }
    final Display display = textEditor.getEditorSite().getShell().getDisplay();
    display.syncExec(() -> {
        final ITextOperationTarget target1 = textEditor.getAdapter(ITextOperationTarget.class);
        if (target1 instanceof ITextViewer) {
            final ITextViewer textViewer = (ITextViewer) target1;
            try {
                if (!document.get(selection.getOffset(), selection.getLength()).equals(newText)) {
                    document.replace(selection.getOffset(), selection.getLength(), newText);
                    textViewer.setSelectedRange(selection.getOffset(), newText.length());
                }
            } catch (final BadLocationException e) {
                ErlLogger.warn(e);
            }
        }
    });
}
Also used : ErlangStatus(org.erlide.core.ErlangStatus) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) ITextOperationTarget(org.eclipse.jface.text.ITextOperationTarget) IDocument(org.eclipse.jface.text.IDocument) ITextSelection(org.eclipse.jface.text.ITextSelection) BadLocationException(org.eclipse.jface.text.BadLocationException) BadLocationException(org.eclipse.jface.text.BadLocationException) Display(org.eclipse.swt.widgets.Display) 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