Search in sources :

Example 16 with AbstractTextEditor

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

the class ContentAssistTestUtilities method getProposals.

/**
 * <p>
 * Returns the content assist proposals when invoked at the offset provided.
 * </p>
 *
 * @param fileNum
 * @param lineNum
 * @param lineRelativeCharOffset
 * @param numOfPages
 */
private static ICompletionProposal[][] getProposals(TestProjectSetup testProject, String filePath, int lineNum, int lineRelativeCharOffset, int numOfPages) throws Exception {
    IFile file = testProject.getFile(filePath);
    AbstractTextEditor editor = testProject.getEditor(file);
    IDocument doc = editor.getDocumentProvider().getDocument(editor.getEditorInput());
    int offset = doc.getLineOffset(lineNum) + lineRelativeCharOffset;
    ICompletionProposal[][] pages = getProposals(editor, offset, numOfPages);
    return pages;
}
Also used : IFile(org.eclipse.core.resources.IFile) AbstractTextEditor(org.eclipse.ui.texteditor.AbstractTextEditor) IDocument(org.eclipse.jface.text.IDocument)

Example 17 with AbstractTextEditor

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

the class TestProjectSetup method getEditor.

/**
 * <p>
 * Given a <code>file</code> get an editor for it. If an editor has already been retrieved for
 * the given <code>file</code> then return the same already open editor.
 * </p>
 *
 * <p>
 * When opening the editor it will also standardized the line endings to <code>\n</code>
 * </p>
 *
 * @param file
 *            open and return an editor for this
 * @return <code>StructuredTextEditor</code> opened from the given <code>file</code>
 */
public AbstractTextEditor getEditor(IFile file) {
    AbstractTextEditor editor = (AbstractTextEditor) fFileToEditorMap.get(file);
    if (editor == null) {
        try {
            IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
            IWorkbenchPage page = workbenchWindow.getActivePage();
            IEditorPart editorPart = null;
            if (file.getFileExtension().equals("js")) {
                editorPart = IDE.openEditor(page, file, true, true);
            } else if (file.getFileExtension().equals("html")) {
                editorPart = IDE.openEditor(page, file, "org.eclipse.wst.html.core.htmlsource.source", true);
            }
            if (editorPart instanceof AbstractTextEditor) {
                editor = (AbstractTextEditor) editorPart;
            } else {
                Assert.fail("Unable to open structured text editor");
            }
            if (editor != null) {
                standardizeLineEndings(editor);
                fFileToEditorMap.put(file, editor);
            } else {
                Assert.fail("Could not open editor for " + file);
            }
        } catch (Exception e) {
            Assert.fail("Could not open editor for " + file + " exception: " + e.getMessage());
        }
    }
    return editor;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) AbstractTextEditor(org.eclipse.ui.texteditor.AbstractTextEditor) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorPart(org.eclipse.ui.IEditorPart)

Example 18 with AbstractTextEditor

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

the class TestProjectSetup method tearDown.

/**
 * <p>
 * This is run once after all of the tests have been run
 * </p>
 *
 * @see junit.extensions.TestSetup#tearDown()
 */
public void tearDown() throws Exception {
    // close out the editors
    Iterator iter = fFileToEditorMap.values().iterator();
    while (iter.hasNext()) {
        AbstractTextEditor editor = (AbstractTextEditor) iter.next();
        PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().closeEditor(editor, false);
    }
    this.fFileToEditorMap.clear();
    // delete the project
    if (this.fDeleteOnTearDown) {
        this.fProject.delete(true, new NullProgressMonitor());
    }
    // restore properties
    if (fPreviousWTPAutoTestNonInteractivePropValue != null) {
        System.setProperty(WTP_AUTOTEST_NONINTERACTIVE, fPreviousWTPAutoTestNonInteractivePropValue);
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) AbstractTextEditor(org.eclipse.ui.texteditor.AbstractTextEditor) Iterator(java.util.Iterator)

Example 19 with AbstractTextEditor

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

the class TextEditorUtils method enableHostEditorKeyBindings.

/**
 * Eclipse hack. Disables/enabled all key bindings in specified site's part. Works only if host editor is extender of
 * AbstractTextEditor Uses reflection because setActionActivation is private method
 * TODO: find better way to disable key bindings or prioritize event handling to widgets
 *
 * @param partSite workbench part site
 * @param enable enable or disable
 */
@Deprecated
public static void enableHostEditorKeyBindings(IWorkbenchPartSite partSite, boolean enable) {
    IWorkbenchPart part = partSite.getPart();
    if (part instanceof AbstractTextEditor) {
        AbstractTextEditor hostEditor = (AbstractTextEditor) part;
        Control widget = hostEditor.getAdapter(Control.class);
        if (widget == null || widget.isDisposed()) {
            return;
        }
        try {
            Method activatorMethod = AbstractTextEditor.class.getDeclaredMethod("setActionActivation", Boolean.TYPE);
            activatorMethod.setAccessible(true);
            activatorMethod.invoke(hostEditor, enable);
        } catch (Throwable e) {
            if (e instanceof InvocationTargetException) {
                e = ((InvocationTargetException) e).getTargetException();
            }
            log.warn("Can't disable text editor action activations", e);
        }
    // hostEditor.getEditorSite().getActionBarContributor().setActiveEditor(hostEditor);
    }
}
Also used : Control(org.eclipse.swt.widgets.Control) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) AbstractTextEditor(org.eclipse.ui.texteditor.AbstractTextEditor) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 20 with AbstractTextEditor

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

the class TextEditorUtils method enableHostEditorKeyBindings.

/**
 * Eclipse hack. Disables/enabled all key bindings in specified site's part. Works only if host editor is extender of
 * AbstractTextEditor Uses reflection because setActionActivation is private method
 * TODO: find better way to disable key bindings or prioritize event handling to widgets
 *
 * @param partSite workbench part site
 * @param enable enable or disable
 */
@Deprecated
public static void enableHostEditorKeyBindings(IWorkbenchPartSite partSite, boolean enable) {
    IWorkbenchPart part = partSite.getPart();
    if (part instanceof AbstractTextEditor) {
        AbstractTextEditor hostEditor = (AbstractTextEditor) part;
        Control widget = hostEditor.getAdapter(Control.class);
        if (widget == null || widget.isDisposed()) {
            return;
        }
        try {
            Method activatorMethod = AbstractTextEditor.class.getDeclaredMethod("setActionActivation", Boolean.TYPE);
            activatorMethod.setAccessible(true);
            activatorMethod.invoke(hostEditor, enable);
        } catch (Throwable e) {
            if (e instanceof InvocationTargetException) {
                e = ((InvocationTargetException) e).getTargetException();
            }
            log.warn("Can't disable text editor action activations", e);
        }
    // hostEditor.getEditorSite().getActionBarContributor().setActiveEditor(hostEditor);
    }
}
Also used : Control(org.eclipse.swt.widgets.Control) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) AbstractTextEditor(org.eclipse.ui.texteditor.AbstractTextEditor) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException)

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