Search in sources :

Example 31 with AbstractTextEditor

use of org.eclipse.ui.texteditor.AbstractTextEditor in project titan.EclipsePlug-ins by eclipse.

the class OpenDeclaration method selectAndRevealRegion.

/**
 * Opens an editor for the provided declaration, and in this editor the
 * location of the declaration is revealed and highlighted.
 *
 * @param file
 *                The file to open.
 * @param offset
 *                The start position of the declaration to select.
 * @param endOffset
 *                The end position of the declaration to select.
 * @param select
 *                Select the given region if true.
 */
private void selectAndRevealRegion(final IFile file, final int offset, final int endOffset, final boolean select) {
    IEditorDescriptor desc = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(file.getName());
    if (desc == null) {
        targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(EDITORNOTFOUND);
        return;
    }
    if (!select) {
        return;
    }
    try {
        IWorkbenchPage page = targetEditor.getSite().getPage();
        IEditorPart editorPart = page.openEditor(new FileEditorInput(file), desc.getId());
        if (editorPart != null) {
            // not AbstractTextEditor.
            if (editorPart instanceof ConfigEditor) {
                ((AbstractTextEditor) ((ConfigEditor) editorPart).getEditor()).selectAndReveal(offset, endOffset - offset);
            } else if (editorPart instanceof AbstractTextEditor) {
                ((AbstractTextEditor) editorPart).selectAndReveal(offset, endOffset - offset);
            }
        }
    } catch (PartInitException e) {
        ErrorReporter.logExceptionStackTrace(e);
    }
}
Also used : IEditorDescriptor(org.eclipse.ui.IEditorDescriptor) FileEditorInput(org.eclipse.ui.part.FileEditorInput) ConfigEditor(org.eclipse.titan.designer.editors.configeditor.ConfigEditor) AbstractTextEditor(org.eclipse.ui.texteditor.AbstractTextEditor) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorPart(org.eclipse.ui.IEditorPart) PartInitException(org.eclipse.ui.PartInitException)

Example 32 with AbstractTextEditor

use of org.eclipse.ui.texteditor.AbstractTextEditor in project titan.EclipsePlug-ins by eclipse.

the class OpenDeclaration method selectAndRevealDeclaration.

/**
 * Opens an editor for the provided declaration, and in this editor the
 * location of the declaration is revealed and selected.
 *
 * @param declaration
 *                the declaration to reveal
 */
private void selectAndRevealDeclaration(final Location location) {
    IEditorDescriptor desc = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(location.getFile().getName());
    if (desc == null) {
        targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(ASN1EDITORNOTFOUND);
        return;
    }
    try {
        IWorkbenchPage page = targetEditor.getSite().getPage();
        IEditorPart editorPart = page.openEditor(new FileEditorInput((IFile) location.getFile()), desc.getId());
        if (editorPart != null && (editorPart instanceof AbstractTextEditor)) {
            ((AbstractTextEditor) editorPart).selectAndReveal(location.getOffset(), location.getEndOffset() - location.getOffset());
        }
    } catch (PartInitException e) {
        ErrorReporter.logExceptionStackTrace(e);
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IEditorDescriptor(org.eclipse.ui.IEditorDescriptor) FileEditorInput(org.eclipse.ui.part.FileEditorInput) AbstractTextEditor(org.eclipse.ui.texteditor.AbstractTextEditor) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorPart(org.eclipse.ui.IEditorPart) PartInitException(org.eclipse.ui.PartInitException)

Example 33 with AbstractTextEditor

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

the class TextChangeCombinerTest method openInEditor.

protected ITextEditor openInEditor(IFile file) throws PartInitException {
    FileEditorInput fileEditorInput = new FileEditorInput(file);
    AbstractTextEditor editor = (AbstractTextEditor) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(fileEditorInput, "org.eclipse.ui.DefaultTextEditor");
    return editor;
}
Also used : FileEditorInput(org.eclipse.ui.part.FileEditorInput) AbstractTextEditor(org.eclipse.ui.texteditor.AbstractTextEditor)

Aggregations

AbstractTextEditor (org.eclipse.ui.texteditor.AbstractTextEditor)33 IFile (org.eclipse.core.resources.IFile)14 IEditorPart (org.eclipse.ui.IEditorPart)9 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)9 PartInitException (org.eclipse.ui.PartInitException)8 FileEditorInput (org.eclipse.ui.part.FileEditorInput)8 IDocument (org.eclipse.jface.text.IDocument)7 IEditorDescriptor (org.eclipse.ui.IEditorDescriptor)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 InputStream (java.io.InputStream)6 Path (org.eclipse.core.runtime.Path)6 TextSelection (org.eclipse.jface.text.TextSelection)6 IDocumentProvider (org.eclipse.ui.texteditor.IDocumentProvider)6 Test (org.junit.Test)6 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 Method (java.lang.reflect.Method)4 After (org.junit.After)3 FocusEvent (org.eclipse.swt.events.FocusEvent)2 FocusListener (org.eclipse.swt.events.FocusListener)2 Control (org.eclipse.swt.widgets.Control)2