Search in sources :

Example 16 with IDocumentProvider

use of org.eclipse.ui.texteditor.IDocumentProvider 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 17 with IDocumentProvider

use of org.eclipse.ui.texteditor.IDocumentProvider in project linuxtools by eclipse.

the class STLink2SourceSupport method openFileImpl.

private static boolean openFileImpl(IProject project, IPath sourceLoc, int lineNumber) {
    if (sourceLoc == null || "??".equals(sourceLoc.toString())) {
        // $NON-NLS-1$
        return false;
    }
    try {
        IEditorInput editorInput = getEditorInput(sourceLoc, project);
        IWorkbenchPage p = CUIPlugin.getActivePage();
        if (p != null) {
            if (editorInput == null) {
                p.openEditor(new STCSourceNotFoundEditorInput(project, sourceLoc, lineNumber), STCSourceNotFoundEditor.ID, true);
            } else {
                IEditorPart editor = p.openEditor(editorInput, CUIPlugin.EDITOR_ID, true);
                if (lineNumber > 0 && editor instanceof ITextEditor) {
                    IDocumentProvider provider = ((ITextEditor) editor).getDocumentProvider();
                    IDocument document = provider.getDocument(editor.getEditorInput());
                    try {
                        int start = document.getLineOffset(lineNumber - 1);
                        ((ITextEditor) editor).selectAndReveal(start, 0);
                        IWorkbenchPage page = editor.getSite().getPage();
                        page.activate(editor);
                        return true;
                    } catch (BadLocationException x) {
                    // ignore
                    }
                }
            }
        }
    } catch (PartInitException e) {
    }
    return false;
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor) IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorPart(org.eclipse.ui.IEditorPart) PartInitException(org.eclipse.ui.PartInitException) IEditorInput(org.eclipse.ui.IEditorInput) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 18 with IDocumentProvider

use of org.eclipse.ui.texteditor.IDocumentProvider in project linuxtools by eclipse.

the class ProfileUIUtils method openEditorAndSelect.

/**
 * Opens the specified file in an editor (or selects an already open
 * editor) and highlights the specified line.
 * @param result - result of performing source lookup with a org.eclipse.debug.core.model.ISourceLocator
 * @param line - line number to select, 0 to not select a line
 * @throws PartInitException - Failed to open editor
 * @throws BadLocationException - Line number not valid in file
 * @see DebugUITools#lookupSource(Object, org.eclipse.debug.core.model.ISourceLocator)
 */
public static void openEditorAndSelect(ISourceLookupResult result, int line) throws PartInitException, BadLocationException {
    IEditorInput input = result.getEditorInput();
    String editorID = result.getEditorId();
    if (input == null || editorID == null) {
        // Consult the CDT DebugModelPresentation
        Object sourceElement = result.getSourceElement();
        if (sourceElement != null) {
            // Resolve IResource in case we get a LocalFileStorage object
            if (sourceElement instanceof LocalFileStorage) {
                IPath filePath = ((LocalFileStorage) sourceElement).getFullPath();
                URI fileURI = URIUtil.toURI(filePath);
                IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
                IFile[] files = root.findFilesForLocationURI(fileURI);
                if (files.length > 0) {
                    // Take the first match
                    sourceElement = files[0];
                }
            }
            IDebugModelPresentation pres = DebugUITools.newDebugModelPresentation(CDebugCorePlugin.getUniqueIdentifier());
            input = pres.getEditorInput(sourceElement);
            editorID = pres.getEditorId(input, sourceElement);
            pres.dispose();
        }
    }
    if (input != null && editorID != null) {
        // Open the editor
        IWorkbenchPage activePage = ProfileUIPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage();
        IEditorPart editor = IDE.openEditor(activePage, input, editorID);
        // Select the line
        if (editor instanceof ITextEditor) {
            ITextEditor textEditor = (ITextEditor) editor;
            if (line > 0) {
                IDocumentProvider provider = textEditor.getDocumentProvider();
                IDocument document = provider.getDocument(textEditor.getEditorInput());
                // zero-indexed
                IRegion lineRegion = document.getLineInformation(line - 1);
                textEditor.selectAndReveal(lineRegion.getOffset(), lineRegion.getLength());
            }
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) IPath(org.eclipse.core.runtime.IPath) LocalFileStorage(org.eclipse.debug.core.sourcelookup.containers.LocalFileStorage) IDebugModelPresentation(org.eclipse.debug.ui.IDebugModelPresentation) IEditorPart(org.eclipse.ui.IEditorPart) URI(java.net.URI) IRegion(org.eclipse.jface.text.IRegion) IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorInput(org.eclipse.ui.IEditorInput) IDocument(org.eclipse.jface.text.IDocument)

Example 19 with IDocumentProvider

use of org.eclipse.ui.texteditor.IDocumentProvider in project linuxtools by eclipse.

the class ProfileUIUtils method openEditorAndSelect.

/**
 * Opens an editor on the given file and selects the line.
 * @param file The file to open.
 * @param line The line to select.
 * @throws PartInitException If opening editor failed.
 * @throws BadLocationException If line number is invalid.
 *
 * @since 2.0
 */
public static void openEditorAndSelect(IFile file, int line) throws PartInitException, BadLocationException {
    if (file.exists()) {
        IWorkbenchPage activePage = ProfileUIPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage();
        IEditorPart editor = IDE.openEditor(activePage, file);
        if (editor instanceof ITextEditor) {
            ITextEditor textEditor = (ITextEditor) editor;
            if (line > 0) {
                IDocumentProvider provider = textEditor.getDocumentProvider();
                IDocument document = provider.getDocument(textEditor.getEditorInput());
                // zero-indexed
                int start = document.getLineOffset(line - 1);
                textEditor.selectAndReveal(start, 0);
            }
        }
    }
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor) IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorPart(org.eclipse.ui.IEditorPart) IDocument(org.eclipse.jface.text.IDocument)

Example 20 with IDocumentProvider

use of org.eclipse.ui.texteditor.IDocumentProvider in project linuxtools by eclipse.

the class IndentHandler method getDocument.

/**
 * Returns the document currently displayed in the editor, or
 * <code>null</code> if none can be obtained.
 *
 * @return the current document or <code>null</code>
 */
private IDocument getDocument(ITextEditor editor) {
    if (editor != null) {
        IDocumentProvider provider = editor.getDocumentProvider();
        IEditorInput input = editor.getEditorInput();
        if (provider != null && input != null)
            return provider.getDocument(input);
    }
    return null;
}
Also used : IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) IEditorInput(org.eclipse.ui.IEditorInput)

Aggregations

IDocumentProvider (org.eclipse.ui.texteditor.IDocumentProvider)42 IDocument (org.eclipse.jface.text.IDocument)20 IEditorInput (org.eclipse.ui.IEditorInput)14 ITextEditor (org.eclipse.ui.texteditor.ITextEditor)12 IEditorPart (org.eclipse.ui.IEditorPart)10 IAnnotationModel (org.eclipse.jface.text.source.IAnnotationModel)9 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)9 IFile (org.eclipse.core.resources.IFile)6 CoreException (org.eclipse.core.runtime.CoreException)6 BadLocationException (org.eclipse.jface.text.BadLocationException)6 IAnnotationModelExtension (org.eclipse.jface.text.source.IAnnotationModelExtension)6 PartInitException (org.eclipse.ui.PartInitException)6 AbstractTextEditor (org.eclipse.ui.texteditor.AbstractTextEditor)6 IOException (java.io.IOException)4 IPath (org.eclipse.core.runtime.IPath)4 IDocumentWrapper (bndtools.editor.model.IDocumentWrapper)3 IResource (org.eclipse.core.resources.IResource)3 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)3 Workspace (aQute.bnd.build.Workspace)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2