Search in sources :

Example 36 with IDocumentProvider

use of org.eclipse.ui.texteditor.IDocumentProvider in project eclipse.platform.text by eclipse.

the class ReferenceSelectionAction method getDiffer.

/**
 * Fetches the differ installed with the current editor's document's annotation model. If none
 * is installed yet, and <code>createIfNeeded</code> is true, one is created and attached to the
 * model.
 *
 * @param createIfNeeded when set to <code>true</code>, a new differ will be created if needed.
 * @return the differ installed with the annotation model, or <code>null</code>.
 */
private DocumentLineDiffer getDiffer(boolean createIfNeeded) {
    // get annotation model
    if (fEditor == null)
        return null;
    IDocumentProvider provider = fEditor.getDocumentProvider();
    IEditorInput editorInput = fEditor.getEditorInput();
    if (provider == null || editorInput == null)
        return null;
    IAnnotationModel m = provider.getAnnotationModel(editorInput);
    IAnnotationModelExtension model = null;
    if (m instanceof IAnnotationModelExtension) {
        model = (IAnnotationModelExtension) m;
    } else {
        return null;
    }
    // get differ
    DocumentLineDiffer differ = (DocumentLineDiffer) model.getAnnotationModel(IChangeRulerColumn.QUICK_DIFF_MODEL_ID);
    // create if needed
    if (differ == null && createIfNeeded) {
        differ = new DocumentLineDiffer();
        model.addAnnotationModel(IChangeRulerColumn.QUICK_DIFF_MODEL_ID, differ);
    }
    return differ;
}
Also used : IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) IAnnotationModelExtension(org.eclipse.jface.text.source.IAnnotationModelExtension) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) IEditorInput(org.eclipse.ui.IEditorInput)

Example 37 with IDocumentProvider

use of org.eclipse.ui.texteditor.IDocumentProvider in project eclipse.platform.text by eclipse.

the class HighlightTest method getAnnotationModel.

private IAnnotationModel getAnnotationModel() {
    IDocumentProvider dp = editor.getDocumentProvider();
    IAnnotationModel am = dp.getAnnotationModel(editor.getEditorInput());
    return am;
}
Also used : IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel)

Example 38 with IDocumentProvider

use of org.eclipse.ui.texteditor.IDocumentProvider in project eclipse.platform.text by eclipse.

the class DefaultEncodingSupport method setEncoding.

/**
 * Sets the encoding of the editor's input to the given value. If <code>overwrite</code> is
 * <code>true</code> the value is set even if the encoding is already set.
 *
 * @param encoding the new encoding
 * @param overwrite <code>true</code> if current encoding should be overwritten
 */
protected void setEncoding(String encoding, boolean overwrite) {
    IDocumentProvider p = fTextEditor.getDocumentProvider();
    if (p instanceof IStorageDocumentProvider) {
        final IEditorInput input = fTextEditor.getEditorInput();
        IStorageDocumentProvider provider = (IStorageDocumentProvider) p;
        String current = provider.getEncoding(input);
        if (!fTextEditor.isDirty()) {
            // $NON-NLS-1$
            String internal = encoding == null ? "" : encoding;
            boolean apply = (overwrite || current == null) && !internal.equals(current);
            if (apply) {
                provider.setEncoding(input, encoding);
                Runnable encodingSetter = new Runnable() {

                    @Override
                    public void run() {
                        fTextEditor.doRevertToSaved();
                    }
                };
                Display display = fTextEditor.getSite().getShell().getDisplay();
                if (display != null && !display.isDisposed())
                    BusyIndicator.showWhile(display, encodingSetter);
                else
                    encodingSetter.run();
            }
        }
    }
}
Also used : IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) IEditorInput(org.eclipse.ui.IEditorInput) Display(org.eclipse.swt.widgets.Display)

Example 39 with IDocumentProvider

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

the class FileHyperlink method linkActivated.

@Override
public void linkActivated() {
    IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    IEditorPart editorPart = null;
    try {
        editorPart = IDE.openEditorOnFileStore(page, file);
        if (line > 0) {
            ITextEditor textEditor = null;
            if (editorPart instanceof ITextEditor) {
                textEditor = (ITextEditor) editorPart;
            } else {
                textEditor = editorPart.getAdapter(ITextEditor.class);
            }
            if (textEditor != null) {
                IEditorInput input = editorPart.getEditorInput();
                IDocumentProvider provider = textEditor.getDocumentProvider();
                try {
                    provider.connect(input);
                } catch (CoreException e) {
                    // unable to link
                    return;
                }
                IDocument document = provider.getDocument(input);
                int offset = -1;
                int length = -1;
                try {
                    IRegion region = document.getLineInformation(line - 1);
                    offset = region.getOffset();
                    length = region.getLength();
                } catch (BadLocationException e) {
                // unable to link
                }
                provider.disconnect(input);
                if (offset >= 0 && length >= 0) {
                    textEditor.selectAndReveal(offset, length);
                }
            }
        }
    } catch (PartInitException e) {
    // Put your exception handler here if you wish to
    }
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor) IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) CoreException(org.eclipse.core.runtime.CoreException) 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) IRegion(org.eclipse.jface.text.IRegion) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 40 with IDocumentProvider

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

the class JavaParserTest method tearDown.

@After
public void tearDown() throws Exception {
    // content to the empty string).
    if (javaSourceEditorPart != null) {
        AbstractTextEditor castEditor = (AbstractTextEditor) javaSourceEditorPart;
        IDocumentProvider iDocProvider = castEditor.getDocumentProvider();
        IDocument changelogContentDoc = iDocProvider.getDocument(castEditor.getEditorInput());
        changelogContentDoc.set("");
        javaSourceEditorPart.doSave(null);
        // Also close open editor in order for default content to work.
        // I.e. avoid spill over from previous test runs
        closeEditor(javaSourceEditorPart);
    }
    // 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