Search in sources :

Example 21 with IDocumentProvider

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

the class GcovAnnotationModel method clear.

public static void clear(ITextEditor editor) {
    IDocumentProvider provider = editor.getDocumentProvider();
    if (provider == null) {
        return;
    }
    IAnnotationModel model = provider.getAnnotationModel(editor.getEditorInput());
    if (!(model instanceof IAnnotationModelExtension)) {
        return;
    }
    IAnnotationModelExtension modelex = (IAnnotationModelExtension) model;
    IAnnotationModel coverageModel = modelex.getAnnotationModel(KEY);
    if (coverageModel instanceof GcovAnnotationModel) {
        ((GcovAnnotationModel) coverageModel).clear();
    }
}
Also used : IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) IAnnotationModelExtension(org.eclipse.jface.text.source.IAnnotationModelExtension) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel)

Example 22 with IDocumentProvider

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

the class GcovAnnotationModel method attach.

/**
 * Attaches a coverage annotation model for the given editor if the editor
 * can be annotated. Does nothing if the model is already attached.
 *
 * @param editor Editor to which an annotation model should be attached
 */
public static void attach(ITextEditor editor) {
    IDocumentProvider provider = editor.getDocumentProvider();
    if (provider == null) {
        return;
    }
    IAnnotationModel model = provider.getAnnotationModel(editor.getEditorInput());
    if (!(model instanceof IAnnotationModelExtension)) {
        return;
    }
    IAnnotationModelExtension modelex = (IAnnotationModelExtension) model;
    IDocument document = provider.getDocument(editor.getEditorInput());
    GcovAnnotationModel coveragemodel = (GcovAnnotationModel) modelex.getAnnotationModel(KEY);
    if (coveragemodel == null) {
        coveragemodel = new GcovAnnotationModel(editor, document);
        modelex.addAnnotationModel(KEY, coveragemodel);
    } else {
        coveragemodel.updateAnnotations(false);
    }
}
Also used : IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) IAnnotationModelExtension(org.eclipse.jface.text.source.IAnnotationModelExtension) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) IDocument(org.eclipse.jface.text.IDocument)

Example 23 with IDocumentProvider

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

the class OpenSourceFileAction method openAnnotatedSourceFile.

public static void openAnnotatedSourceFile(IProject project, IFile binary, SourceFile sourceFile, IPath realLocation, int lineNumber) {
    PlatformUI.getWorkbench().getDisplay().syncExec(() -> {
        IWorkbenchPage page = CUIPlugin.getActivePage();
        if (page != null) {
            IFileStore fs = getFileStore(project, realLocation);
            if (fs == null && !realLocation.isAbsolute() && binary != null) {
                IPath p = binary.getProjectRelativePath().removeLastSegments(1);
                fs = getFileStore(project, p.append(realLocation));
            }
            if (fs == null) {
                try {
                    page.openEditor(new STAnnotatedSourceNotFoundEditorInput(project, sourceFile, realLocation, lineNumber), STAnnotatedSourceNotFoundEditor.ID, true);
                } catch (PartInitException e) {
                    Status s = new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, Messages.OpenSourceFileAction_open_error, e);
                    Activator.getDefault().getLog().log(s);
                }
            } else {
                try {
                    IEditorPart editor = IDE.openEditorOnFileStore(page, fs);
                    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);
                        } catch (BadLocationException e) {
                        // ignore
                        }
                        IWorkbenchPage p = editor.getSite().getPage();
                        p.activate(editor);
                    }
                } catch (PartInitException e) {
                    Status s = new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, Messages.OpenSourceFileAction_open_error, e);
                    Activator.getDefault().getLog().log(s);
                }
            }
        }
    });
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) IPath(org.eclipse.core.runtime.IPath) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IFileStore(org.eclipse.core.filesystem.IFileStore) PartInitException(org.eclipse.ui.PartInitException) IEditorPart(org.eclipse.ui.IEditorPart) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 24 with IDocumentProvider

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

the class GNUFormat method getDocument.

public IDocument getDocument(IEditorPart currentEditor) {
    AbstractTextEditor castEditor = (AbstractTextEditor) currentEditor;
    IDocumentProvider provider = castEditor.getDocumentProvider();
    return provider.getDocument(castEditor.getEditorInput());
}
Also used : IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) AbstractTextEditor(org.eclipse.ui.texteditor.AbstractTextEditor)

Example 25 with IDocumentProvider

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

the class GNUFormatTest method tearDown.

@After
public void tearDown() throws Exception {
    // content to the empty string).
    if (changelogEditorPart != null) {
        // testFormatDateLine does not use it
        AbstractTextEditor castEditor = (AbstractTextEditor) changelogEditorPart;
        IDocumentProvider iDocProvider = castEditor.getDocumentProvider();
        IDocument changelogContentDoc = iDocProvider.getDocument(castEditor.getEditorInput());
        // empty content
        changelogContentDoc.set("");
        changelogEditorPart.doSave(null);
        // Also close open editor in order for default content to work.
        // I.e. avoid spill over from previous test runs
        closeEditor(changelogEditorPart);
    }
    // dispose
    project.getTestProject().delete(true, true, null);
}
Also used : IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) AbstractTextEditor(org.eclipse.ui.texteditor.AbstractTextEditor) IDocument(org.eclipse.jface.text.IDocument) After(org.junit.After)

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