Search in sources :

Example 11 with AbstractDecoratedTextEditor

use of org.eclipse.ui.texteditor.AbstractDecoratedTextEditor in project egit by eclipse.

the class BlameOperation method openEditor.

private void openEditor(final RevisionInformation info) {
    IEditorPart editorPart;
    try {
        if (storage instanceof IFile) {
            editorPart = RevisionAnnotationController.openEditor(page, (IFile) storage);
        } else {
            FileRevisionEditorInput editorInput = new FileRevisionEditorInput(fileRevision, storage);
            editorPart = EgitUiEditorUtils.openEditor(page, editorInput);
            if (editorPart instanceof MultiPageEditorPart) {
                MultiPageEditorPart multiEditor = (MultiPageEditorPart) editorPart;
                for (IEditorPart part : multiEditor.findEditors(editorInput)) {
                    if (part instanceof AbstractDecoratedTextEditor) {
                        multiEditor.setActiveEditor(part);
                        editorPart = part;
                        break;
                    }
                }
            }
        }
    } catch (CoreException e) {
        // $NON-NLS-1$
        Activator.handleError(// $NON-NLS-1$
        "Error displaying blame annotations", // $NON-NLS-1$
        e, false);
        return;
    }
    if (!(editorPart instanceof AbstractDecoratedTextEditor)) {
        return;
    }
    AbstractDecoratedTextEditor editor = (AbstractDecoratedTextEditor) editorPart;
    // IRevisionRulerColumn would also be possible but using
    // IVerticalRulerInfo seems to work in more situations.
    IVerticalRulerInfo rulerInfo = AdapterUtils.adapt(editor, IVerticalRulerInfo.class);
    BlameInformationControlCreator creator = new BlameInformationControlCreator(rulerInfo);
    info.setHoverControlCreator(creator);
    info.setInformationPresenterControlCreator(creator);
    editor.showRevisionInformation(info, // $NON-NLS-1$
    "org.eclipse.egit.ui.internal.decorators.GitQuickDiffProvider");
    if (lineNumberToReveal >= 0) {
        IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput());
        int offset;
        try {
            offset = document.getLineOffset(lineNumberToReveal);
            editor.selectAndReveal(offset, 0);
        } catch (BadLocationException e) {
            Activator.logError("Error revealing line " + lineNumberToReveal, // $NON-NLS-1$
            e);
        }
    }
    IRevisionRulerColumn revisionRuler = AdapterUtils.adapt(editor, IRevisionRulerColumn.class);
    if (revisionRuler instanceof IRevisionRulerColumnExtension)
        ((IRevisionRulerColumnExtension) revisionRuler).getRevisionSelectionProvider().addSelectionChangedListener(new RevisionSelectionHandler(repository, path, storage));
}
Also used : IFile(org.eclipse.core.resources.IFile) MultiPageEditorPart(org.eclipse.ui.part.MultiPageEditorPart) IEditorPart(org.eclipse.ui.IEditorPart) IRevisionRulerColumnExtension(org.eclipse.jface.text.revisions.IRevisionRulerColumnExtension) IRevisionRulerColumn(org.eclipse.jface.text.revisions.IRevisionRulerColumn) AbstractDecoratedTextEditor(org.eclipse.ui.texteditor.AbstractDecoratedTextEditor) CoreException(org.eclipse.core.runtime.CoreException) FileRevisionEditorInput(org.eclipse.egit.ui.internal.revision.FileRevisionEditorInput) IVerticalRulerInfo(org.eclipse.jface.text.source.IVerticalRulerInfo) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Aggregations

AbstractDecoratedTextEditor (org.eclipse.ui.texteditor.AbstractDecoratedTextEditor)11 IFile (org.eclipse.core.resources.IFile)10 Path (org.eclipse.core.runtime.Path)8 ByteArrayInputStream (java.io.ByteArrayInputStream)7 InputStream (java.io.InputStream)7 TextSelection (org.eclipse.jface.text.TextSelection)7 Test (org.junit.Test)7 CoreException (org.eclipse.core.runtime.CoreException)3 IEditorInput (org.eclipse.ui.IEditorInput)2 IEditorPart (org.eclipse.ui.IEditorPart)2 IDocumentProvider (org.eclipse.ui.texteditor.IDocumentProvider)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 IMarker (org.eclipse.core.resources.IMarker)1 IPath (org.eclipse.core.runtime.IPath)1 FileRevisionEditorInput (org.eclipse.egit.ui.internal.revision.FileRevisionEditorInput)1 BadLocationException (org.eclipse.jface.text.BadLocationException)1 IDocument (org.eclipse.jface.text.IDocument)1 ITextSelection (org.eclipse.jface.text.ITextSelection)1 IRevisionRulerColumn (org.eclipse.jface.text.revisions.IRevisionRulerColumn)1