Search in sources :

Example 96 with ITextEditor

use of org.eclipse.ui.texteditor.ITextEditor in project dbeaver by serge-rider.

the class SQLAnnotationHover method findAnnotations.

/**
 * Finds annotations either by offset or by lineNumber
 */
private void findAnnotations(int offset, IAnnotationModel model, IDocument document, int lineNumber) {
    annotations.clear();
    if (model == null) {
        if (editor != null) {
            ITextEditor editor = this.editor;
            model = editor.getDocumentProvider().getAnnotationModel(editor.getEditorInput());
        }
    }
    if (model == null) {
        return;
    }
    for (Iterator<?> it = model.getAnnotationIterator(); it.hasNext(); ) {
        Annotation annotation = (Annotation) it.next();
        Position position = model.getPosition(annotation);
        // if position is null, just return.
        if (position == null) {
            return;
        }
        try {
            if (position.overlapsWith(offset, 1) || document != null && document.getLineOfOffset(position.offset) == lineNumber) {
                annotations.add(annotation);
            }
        } catch (BadLocationException e) {
            log.error(e);
        }
    }
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor) Annotation(org.eclipse.jface.text.source.Annotation)

Example 97 with ITextEditor

use of org.eclipse.ui.texteditor.ITextEditor in project xtext-xtend by eclipse.

the class OpenEditorAction method run.

@Override
public void run() {
    if (inputFile == null) {
        return;
    }
    IWorkbenchPartSite workbenchPartSite = derivedSourceView.getSite();
    IWorkbenchPage workbenchPage = workbenchPartSite.getPage();
    try {
        IEditorPart editorPart = workbenchPage.openEditor(new FileEditorInput(inputFile), COMPILATION_UNIT_EDITOR_ID, true, IWorkbenchPage.MATCH_ID | IWorkbenchPage.MATCH_INPUT);
        if (selectedRegion != null) {
            ((ITextEditor) editorPart).selectAndReveal(selectedRegion.getOffset(), selectedRegion.getLength());
        }
    } catch (PartInitException partInitException) {
        throw new WrappedRuntimeException(partInitException);
    }
}
Also used : IWorkbenchPartSite(org.eclipse.ui.IWorkbenchPartSite) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorPart(org.eclipse.ui.IEditorPart) PartInitException(org.eclipse.ui.PartInitException) WrappedRuntimeException(org.eclipse.core.internal.utils.WrappedRuntimeException)

Example 98 with ITextEditor

use of org.eclipse.ui.texteditor.ITextEditor in project xtext-xtend by eclipse.

the class SeveralEditorsQueuedBuildTest method undoEditorChangesAndClose.

@Test
public void undoEditorChangesAndClose() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("package mypackage;");
        _builder.newLine();
        _builder.newLine();
        _builder.append("public class Foo {");
        _builder.newLine();
        _builder.newLine();
        _builder.append("\t");
        _builder.append("public void foo() {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        this.testHelper.createFile("/mypackage/Foo.java", _builder.toString());
        StringConcatenation _builder_1 = new StringConcatenation();
        _builder_1.append("package mypackage;");
        _builder_1.newLine();
        _builder_1.newLine();
        _builder_1.append("public class Bar {");
        _builder_1.newLine();
        _builder_1.newLine();
        _builder_1.append("\t");
        _builder_1.append("public void bar() {");
        _builder_1.newLine();
        _builder_1.append("\t");
        _builder_1.append("}");
        _builder_1.newLine();
        _builder_1.newLine();
        _builder_1.append("}");
        _builder_1.newLine();
        this.testHelper.createFile("/mypackage/Bar.java", _builder_1.toString());
        this.reset();
        final ITextEditor fooEditor = this._javaEditorExtension.reconcile("/mypackage/Foo.java", "foo", "foo2");
        this.assertThereAreNotDeltas(this.queuedBuildDataContribution.getUnconfirmedDeltas());
        this.assertThereAreNotDeltas(this.queuedBuildData.getAndRemovePendingDeltas());
        final ITextEditor barEditor = this._javaEditorExtension.reconcile("/mypackage/Bar.java", "bar", "bar2");
        this.assertThereAreNotDeltas(this.queuedBuildDataContribution.getUnconfirmedDeltas());
        this.assertThereAreNotDeltas(this.queuedBuildData.getAndRemovePendingDeltas());
        this._javaEditorExtension.reconcile(fooEditor, "foo2", "foo");
        this.assertThereAreNotDeltas(this.queuedBuildDataContribution.getUnconfirmedDeltas());
        this.assertThereAreNotDeltas(this.queuedBuildData.getAndRemovePendingDeltas());
        this._javaEditorExtension.close(fooEditor);
        this.assertThereAreNotDeltas(this.queuedBuildDataContribution.getUnconfirmedDeltas());
        this.assertThereAreNotDeltas(this.queuedBuildData.getAndRemovePendingDeltas());
        this._javaEditorExtension.save(barEditor);
        this.assertThereAreDeltas(this.queuedBuildDataContribution.getUnconfirmedDeltas(), "mypackage.Bar");
        this.assertThereAreNotDeltas(this.queuedBuildData.getAndRemovePendingDeltas());
        this.confirmDeltas();
        this.assertThereAreNotDeltas(this.queuedBuildDataContribution.getUnconfirmedDeltas());
        this.assertThereAreDeltas(this.queuedBuildData.getAndRemovePendingDeltas(), "mypackage.Bar");
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Test(org.junit.Test)

Example 99 with ITextEditor

use of org.eclipse.ui.texteditor.ITextEditor in project xtext-xtend by eclipse.

the class SeveralEditorsQueuedBuildTest method saveSeveralEditorsOneByOne.

@Test
public void saveSeveralEditorsOneByOne() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("package mypackage;");
        _builder.newLine();
        _builder.newLine();
        _builder.append("public class Foo {");
        _builder.newLine();
        _builder.newLine();
        _builder.append("\t");
        _builder.append("public void foo() {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        this.testHelper.createFile("/mypackage/Foo.java", _builder.toString());
        StringConcatenation _builder_1 = new StringConcatenation();
        _builder_1.append("package mypackage;");
        _builder_1.newLine();
        _builder_1.newLine();
        _builder_1.append("public class Bar {");
        _builder_1.newLine();
        _builder_1.newLine();
        _builder_1.append("\t");
        _builder_1.append("public void bar() {");
        _builder_1.newLine();
        _builder_1.append("\t");
        _builder_1.append("}");
        _builder_1.newLine();
        _builder_1.newLine();
        _builder_1.append("}");
        _builder_1.newLine();
        this.testHelper.createFile("/mypackage/Bar.java", _builder_1.toString());
        this.reset();
        final ITextEditor fooEditor = this._javaEditorExtension.reconcile("/mypackage/Foo.java", "foo", "foo2");
        this.assertThereAreNotDeltas(this.queuedBuildDataContribution.getUnconfirmedDeltas());
        this.assertThereAreNotDeltas(this.queuedBuildData.getAndRemovePendingDeltas());
        final ITextEditor barEditor = this._javaEditorExtension.reconcile("/mypackage/Bar.java", "bar", "bar2");
        this.assertThereAreNotDeltas(this.queuedBuildDataContribution.getUnconfirmedDeltas());
        this.assertThereAreNotDeltas(this.queuedBuildData.getAndRemovePendingDeltas());
        this._javaEditorExtension.save(barEditor);
        this.assertThereAreDeltas(this.queuedBuildDataContribution.getUnconfirmedDeltas(), "mypackage.Bar");
        this.assertThereAreNotDeltas(this.queuedBuildData.getAndRemovePendingDeltas());
        this.confirmDeltas();
        this.assertThereAreNotDeltas(this.queuedBuildDataContribution.getUnconfirmedDeltas());
        this.assertThereAreDeltas(this.queuedBuildData.getAndRemovePendingDeltas(), "mypackage.Bar");
        this._javaEditorExtension.save(fooEditor);
        this.assertThereAreDeltas(this.queuedBuildDataContribution.getUnconfirmedDeltas(), "mypackage.Foo");
        this.assertThereAreNotDeltas(this.queuedBuildData.getAndRemovePendingDeltas());
        this.confirmDeltas();
        this.assertThereAreNotDeltas(this.queuedBuildDataContribution.getUnconfirmedDeltas());
        this.assertThereAreDeltas(this.queuedBuildData.getAndRemovePendingDeltas(), "mypackage.Foo");
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Test(org.junit.Test)

Example 100 with ITextEditor

use of org.eclipse.ui.texteditor.ITextEditor in project xtext-xtend by eclipse.

the class SeveralEditorsQueuedBuildTest method undoEditorChangesAndSave.

@Test
public void undoEditorChangesAndSave() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("package mypackage;");
        _builder.newLine();
        _builder.newLine();
        _builder.append("public class Foo {");
        _builder.newLine();
        _builder.newLine();
        _builder.append("\t");
        _builder.append("public void foo() {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        this.testHelper.createFile("/mypackage/Foo.java", _builder.toString());
        StringConcatenation _builder_1 = new StringConcatenation();
        _builder_1.append("package mypackage;");
        _builder_1.newLine();
        _builder_1.newLine();
        _builder_1.append("public class Bar {");
        _builder_1.newLine();
        _builder_1.newLine();
        _builder_1.append("\t");
        _builder_1.append("public void bar() {");
        _builder_1.newLine();
        _builder_1.append("\t");
        _builder_1.append("}");
        _builder_1.newLine();
        _builder_1.newLine();
        _builder_1.append("}");
        _builder_1.newLine();
        this.testHelper.createFile("/mypackage/Bar.java", _builder_1.toString());
        this.reset();
        final ITextEditor fooEditor = this._javaEditorExtension.reconcile("/mypackage/Foo.java", "foo", "foo2");
        this.assertThereAreNotDeltas(this.queuedBuildDataContribution.getUnconfirmedDeltas());
        this.assertThereAreNotDeltas(this.queuedBuildData.getAndRemovePendingDeltas());
        final ITextEditor barEditor = this._javaEditorExtension.reconcile("/mypackage/Bar.java", "bar", "bar2");
        this.assertThereAreNotDeltas(this.queuedBuildDataContribution.getUnconfirmedDeltas());
        this.assertThereAreNotDeltas(this.queuedBuildData.getAndRemovePendingDeltas());
        this._javaEditorExtension.reconcile(fooEditor, "foo2", "foo");
        this.assertThereAreNotDeltas(this.queuedBuildDataContribution.getUnconfirmedDeltas());
        this.assertThereAreNotDeltas(this.queuedBuildData.getAndRemovePendingDeltas());
        this._javaEditorExtension.save(fooEditor);
        this.assertThereAreDeltas(this.queuedBuildDataContribution.getUnconfirmedDeltas(), "mypackage.Foo");
        this.assertThereAreNotDeltas(this.queuedBuildData.getAndRemovePendingDeltas());
        this.confirmDeltas();
        this.assertThereAreNotDeltas(this.queuedBuildDataContribution.getUnconfirmedDeltas());
        this.assertThereAreNotDeltas(this.queuedBuildData.getAndRemovePendingDeltas());
        this._javaEditorExtension.save(barEditor);
        this.assertThereAreDeltas(this.queuedBuildDataContribution.getUnconfirmedDeltas(), "mypackage.Bar");
        this.assertThereAreNotDeltas(this.queuedBuildData.getAndRemovePendingDeltas());
        this.confirmDeltas();
        this.assertThereAreNotDeltas(this.queuedBuildDataContribution.getUnconfirmedDeltas());
        this.assertThereAreDeltas(this.queuedBuildData.getAndRemovePendingDeltas(), "mypackage.Bar");
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Test(org.junit.Test)

Aggregations

ITextEditor (org.eclipse.ui.texteditor.ITextEditor)236 IEditorPart (org.eclipse.ui.IEditorPart)92 IDocument (org.eclipse.jface.text.IDocument)76 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)42 IFile (org.eclipse.core.resources.IFile)36 ITextSelection (org.eclipse.jface.text.ITextSelection)34 Test (org.junit.Test)33 BadLocationException (org.eclipse.jface.text.BadLocationException)28 IDocumentProvider (org.eclipse.ui.texteditor.IDocumentProvider)25 PartInitException (org.eclipse.ui.PartInitException)23 ISelection (org.eclipse.jface.viewers.ISelection)19 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)17 IRegion (org.eclipse.jface.text.IRegion)16 Annotation (org.eclipse.jface.text.source.Annotation)16 ArrayList (java.util.ArrayList)15 CoreException (org.eclipse.core.runtime.CoreException)15 IAnnotationModel (org.eclipse.jface.text.source.IAnnotationModel)15 IResource (org.eclipse.core.resources.IResource)14 IEditorInput (org.eclipse.ui.IEditorInput)14 TextSelection (org.eclipse.jface.text.TextSelection)12