Search in sources :

Example 26 with AbstractTextEditor

use of org.eclipse.ui.texteditor.AbstractTextEditor in project webtools.sourceediting by eclipse.

the class TestProjectSetup method editFile.

/**
 * <p>
 * Edits the file given by the fileName. The number of characters indicated by length are
 * replaced by the given text beginning at the character located at the given line number and
 * the line character offset.
 * </p>
 *
 * @param fileName
 * @param lineNum
 * @param lineRelativeCharOffset
 * @param length
 * @param text
 * @throws Exception
 */
public void editFile(String fileName, int lineNum, int lineRelativeCharOffset, int length, String text) throws Exception {
    IFile file = this.getFile(fileName);
    AbstractTextEditor editor = this.getEditor(file);
    IDocument doc = editor.getDocumentProvider().getDocument(editor.getEditorInput());
    int offset = doc.getLineOffset(lineNum) + lineRelativeCharOffset;
    doc.replace(offset, length, text);
    waitForIndexManager();
}
Also used : IFile(org.eclipse.core.resources.IFile) AbstractTextEditor(org.eclipse.ui.texteditor.AbstractTextEditor) IDocument(org.eclipse.jface.text.IDocument)

Example 27 with AbstractTextEditor

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

the class MessageKeyHyperlink method open.

public void open() {
    try {
        IEditorPart editorPart = IDE.openEditor(UIUtil.getActivePage(), _file, true);
        if (editorPart instanceof AbstractTextEditor) {
            AbstractTextEditor editor = (AbstractTextEditor) editorPart;
            editor.selectAndReveal(_offset, _length);
        }
    } catch (PartInitException pie) {
        PortletUIPlugin.logError("Could not open properties file " + this._file.getName(), pie);
    }
}
Also used : AbstractTextEditor(org.eclipse.ui.texteditor.AbstractTextEditor) IEditorPart(org.eclipse.ui.IEditorPart) PartInitException(org.eclipse.ui.PartInitException)

Example 28 with AbstractTextEditor

use of org.eclipse.ui.texteditor.AbstractTextEditor in project soot by Sable.

the class SootPartManager method updatePart.

public void updatePart(IEditorPart part) {
    if (part == null)
        return;
    if (part instanceof JimpleEditor) {
        AbstractAttributesComputer aac = new JimpleAttributesComputer();
        SootAttributesJimpleColorer sajc = new SootAttributesJimpleColorer();
        SootAttrJimpleIconGenerator saji = new SootAttrJimpleIconGenerator();
        SourceViewer viewer = (SourceViewer) ((AbstractTextEditor) part).getAdapter(ITextOperationTarget.class);
        SootAttributesHandler handler = aac.getAttributesHandler((AbstractTextEditor) part);
        if (handler != null) {
            if (isUpdateForOpen() || handler.isUpdate()) {
                sajc.setEditorPart(part);
                sajc.setViewer(viewer);
                sajc.setHandler(handler);
                Thread cThread = new Thread(sajc);
                cThread.start();
                saji.setHandler(handler);
                saji.setRec((IFile) aac.getRec());
                Thread iThread = new Thread(saji);
                iThread.start();
                handler.setUpdate(false);
            }
        }
        handleKeys(handler);
        handleTypes(handler, (IFile) aac.getRec());
    } else if (part instanceof AbstractTextEditor) {
        IEditorInput input = ((AbstractTextEditor) part).getEditorInput();
        IJavaElement jElem = (IJavaElement) ((IAdaptable) input).getAdapter(IJavaElement.class);
        if (!(jElem instanceof ICompilationUnit))
            return;
        AbstractAttributesComputer aac = new JavaAttributesComputer();
        SootAttributesJavaColorer sajc = new SootAttributesJavaColorer();
        SootAttrJavaIconGenerator saji = new SootAttrJavaIconGenerator();
        SourceViewer viewer = (SourceViewer) ((AbstractTextEditor) part).getAdapter(ITextOperationTarget.class);
        SootAttributesHandler handler = aac.getAttributesHandler((AbstractTextEditor) part);
        if (handler != null) {
            if (isUpdateForOpen() || handler.isUpdate()) {
                sajc.setEditorPart(part);
                sajc.setViewer(viewer);
                sajc.setHandler(handler);
                Thread cThread = new Thread(sajc);
                cThread.start();
                saji.setHandler(handler);
                saji.setRec((IFile) aac.getRec());
                Thread iThread = new Thread(saji);
                iThread.start();
                handler.setUpdate(false);
            }
        }
        handleKeys(handler);
        handleTypes(handler, (IFile) aac.getRec());
    }
    setUpdateForOpen(false);
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) SourceViewer(org.eclipse.jface.text.source.SourceViewer) JimpleEditor(ca.mcgill.sable.soot.editors.JimpleEditor) ITextOperationTarget(org.eclipse.jface.text.ITextOperationTarget) AbstractTextEditor(org.eclipse.ui.texteditor.AbstractTextEditor)

Example 29 with AbstractTextEditor

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

the class TextEditorUtils method enableHostEditorKeyBindingsSupport.

public static void enableHostEditorKeyBindingsSupport(final IWorkbenchPartSite partSite, Control control) {
    if (!(partSite.getPart() instanceof AbstractTextEditor)) {
        return;
    }
    final boolean[] activated = new boolean[] { false };
    control.addFocusListener(new FocusListener() {

        @Override
        public void focusGained(FocusEvent e) {
            if (!activated[0]) {
                enableHostEditorKeyBindings(partSite, false);
                activated[0] = true;
            }
        }

        @Override
        public void focusLost(FocusEvent e) {
            if (activated[0]) {
                enableHostEditorKeyBindings(partSite, true);
                activated[0] = false;
            }
        }
    });
    control.addDisposeListener(e -> {
        if (activated[0]) {
            if (!DBWorkbench.getPlatform().isShuttingDown()) {
                enableHostEditorKeyBindings(partSite, true);
            }
            activated[0] = false;
        }
    });
}
Also used : AbstractTextEditor(org.eclipse.ui.texteditor.AbstractTextEditor) FocusListener(org.eclipse.swt.events.FocusListener) FocusEvent(org.eclipse.swt.events.FocusEvent)

Example 30 with AbstractTextEditor

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

the class FindDefinitionAction method showInEditor.

private void showInEditor(final ILocateableNode node) {
    final Location location = node.getLocation();
    final IEditorDescriptor desc = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(location.getFile().getName());
    if (desc == null) {
        TITANDebugConsole.println("Cannot find the editor");
        return;
    }
    final IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    try {
        final IEditorPart editorPart = activePage.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("Error while opening the editor", 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) Location(org.eclipse.titan.designer.AST.Location)

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