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));
}
}
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;
}
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);
}
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;
}
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);
}
}
});
}
Aggregations