Search in sources :

Example 1 with TextEditor

use of org.eclipse.ui.editors.text.TextEditor in project eclipse.platform.text by eclipse.

the class EncodingChangeTests method testChangeEncodingViaFile.

@Test
public void testChangeEncodingViaFile() {
    IWorkbench workbench = PlatformUI.getWorkbench();
    IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage();
    try {
        fFile.setCharset(NON_DEFAULT_ENCODING, null);
    } catch (CoreException ex) {
        fail();
    }
    try {
        fEditor = IDE.openEditor(page, fFile);
        if (fEditor instanceof TextEditor) {
            TextEditor editor = (TextEditor) fEditor;
            Accessor accessor = new Accessor(editor, StatusTextEditor.class);
            while (editor.getSite().getShell().getDisplay().readAndDispatch()) {
            }
            ScrolledComposite composite = (ScrolledComposite) accessor.get("fStatusControl");
            assertNull(composite);
            DefaultEncodingSupport encodingSupport = (DefaultEncodingSupport) editor.getAdapter(IEncodingSupport.class);
            assertEquals(NON_DEFAULT_ENCODING, encodingSupport.getEncoding());
        } else
            fail();
    } catch (PartInitException e) {
        fail();
    }
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) DefaultEncodingSupport(org.eclipse.ui.editors.text.DefaultEncodingSupport) StatusTextEditor(org.eclipse.ui.texteditor.StatusTextEditor) TextEditor(org.eclipse.ui.editors.text.TextEditor) CoreException(org.eclipse.core.runtime.CoreException) IEncodingSupport(org.eclipse.ui.editors.text.IEncodingSupport) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) PartInitException(org.eclipse.ui.PartInitException) Accessor(org.eclipse.text.tests.Accessor) Test(org.junit.Test)

Example 2 with TextEditor

use of org.eclipse.ui.editors.text.TextEditor in project eclipse.platform.text by eclipse.

the class EncodingChangeTests method testChangeEncodingViaEncodingSupport.

@Test
public void testChangeEncodingViaEncodingSupport() {
    IWorkbench workbench = PlatformUI.getWorkbench();
    IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage();
    try {
        fEditor = IDE.openEditor(page, fFile);
        if (fEditor instanceof TextEditor) {
            TextEditor editor = (TextEditor) fEditor;
            while (editor.getSite().getShell().getDisplay().readAndDispatch()) {
            }
            DefaultEncodingSupport encodingSupport = (DefaultEncodingSupport) editor.getAdapter(IEncodingSupport.class);
            encodingSupport.setEncoding(NON_DEFAULT_ENCODING);
            Accessor accessor = new Accessor(editor, StatusTextEditor.class);
            while (editor.getSite().getShell().getDisplay().readAndDispatch()) {
            }
            ScrolledComposite composite = (ScrolledComposite) accessor.get("fStatusControl");
            assertNull(composite);
            String actual = null;
            try {
                actual = fFile.getCharset(false);
            } catch (CoreException e1) {
                fail();
            }
            assertEquals(NON_DEFAULT_ENCODING, actual);
        } else
            fail();
    } catch (PartInitException e) {
        fail();
    }
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) DefaultEncodingSupport(org.eclipse.ui.editors.text.DefaultEncodingSupport) StatusTextEditor(org.eclipse.ui.texteditor.StatusTextEditor) TextEditor(org.eclipse.ui.editors.text.TextEditor) CoreException(org.eclipse.core.runtime.CoreException) IEncodingSupport(org.eclipse.ui.editors.text.IEncodingSupport) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) PartInitException(org.eclipse.ui.PartInitException) Accessor(org.eclipse.text.tests.Accessor) Test(org.junit.Test)

Example 3 with TextEditor

use of org.eclipse.ui.editors.text.TextEditor in project eclipse.platform.text by eclipse.

the class EncodingChangeTests method testAInvalidEncoding.

@Test
public void testAInvalidEncoding() {
    IWorkbench workbench = PlatformUI.getWorkbench();
    IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage();
    try {
        fFile.setCharset("nonexistent", null);
    } catch (CoreException e2) {
        fail();
    }
    try {
        fEditor = IDE.openEditor(page, fFile);
        if (fEditor instanceof TextEditor) {
            TextEditor editor = (TextEditor) fEditor;
            Accessor accessor = new Accessor(editor, StatusTextEditor.class);
            while (editor.getSite().getShell().getDisplay().readAndDispatch()) {
            }
            ITextFileBuffer fileBuffer = FileBuffers.getTextFileBufferManager().getTextFileBuffer(fFile.getFullPath(), LocationKind.IFILE);
            DefaultEncodingSupport encodingSupport = (DefaultEncodingSupport) editor.getAdapter(IEncodingSupport.class);
            String expected = encodingSupport.getStatusMessage(fileBuffer.getStatus());
            Composite composite = (Composite) accessor.get("fStatusControl");
            ScrolledComposite scrolledComposite = (ScrolledComposite) composite.getChildren()[0];
            StyledText statusText = (StyledText) ((Composite) scrolledComposite.getContent()).getChildren()[5];
            String actual = statusText.getText();
            assertEquals(expected, actual);
        } else
            fail();
    } catch (PartInitException e) {
        fail();
    }
}
Also used : DefaultEncodingSupport(org.eclipse.ui.editors.text.DefaultEncodingSupport) StyledText(org.eclipse.swt.custom.StyledText) Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) IEncodingSupport(org.eclipse.ui.editors.text.IEncodingSupport) Accessor(org.eclipse.text.tests.Accessor) IWorkbench(org.eclipse.ui.IWorkbench) StatusTextEditor(org.eclipse.ui.texteditor.StatusTextEditor) TextEditor(org.eclipse.ui.editors.text.TextEditor) CoreException(org.eclipse.core.runtime.CoreException) ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) PartInitException(org.eclipse.ui.PartInitException) Test(org.junit.Test)

Example 4 with TextEditor

use of org.eclipse.ui.editors.text.TextEditor in project linuxtools by eclipse.

the class RepoFormEditor method createEditorPage.

/**
 * Creates editor for the current .repo file.
 *
 * @throws PartInitException
 */
private void createEditorPage() throws PartInitException {
    editor = new TextEditor();
    int index = addPage(editor, getEditorInput());
    setPageText(index, editor.getTitle());
}
Also used : TextEditor(org.eclipse.ui.editors.text.TextEditor)

Example 5 with TextEditor

use of org.eclipse.ui.editors.text.TextEditor in project eclipse.platform.text by eclipse.

the class StatusEditorTest method openNonExistentFile.

private IEditorPart openNonExistentFile(IWorkbenchPage page1, URI uri) throws Exception {
    FileStoreEditorInput input = new FileStoreEditorInput(EFS.getStore(uri));
    TextEditor editor = (TextEditor) page1.openEditor(input, EditorsUI.DEFAULT_TEXT_EDITOR_ID, true);
    Method setMethod = AbstractTextEditor.class.getDeclaredMethod("setDocumentProvider", IDocumentProvider.class);
    setMethod.setAccessible(true);
    setMethod.invoke(editor, new ErrorDocumentProvider(editor.getDocumentProvider()));
    editor.setInput(input);
    processEvents();
    return editor;
}
Also used : TextEditor(org.eclipse.ui.editors.text.TextEditor) AbstractTextEditor(org.eclipse.ui.texteditor.AbstractTextEditor) Method(java.lang.reflect.Method) FileStoreEditorInput(org.eclipse.ui.ide.FileStoreEditorInput)

Aggregations

TextEditor (org.eclipse.ui.editors.text.TextEditor)5 CoreException (org.eclipse.core.runtime.CoreException)3 ScrolledComposite (org.eclipse.swt.custom.ScrolledComposite)3 Accessor (org.eclipse.text.tests.Accessor)3 IWorkbench (org.eclipse.ui.IWorkbench)3 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)3 PartInitException (org.eclipse.ui.PartInitException)3 DefaultEncodingSupport (org.eclipse.ui.editors.text.DefaultEncodingSupport)3 IEncodingSupport (org.eclipse.ui.editors.text.IEncodingSupport)3 StatusTextEditor (org.eclipse.ui.texteditor.StatusTextEditor)3 Test (org.junit.Test)3 Method (java.lang.reflect.Method)1 ITextFileBuffer (org.eclipse.core.filebuffers.ITextFileBuffer)1 StyledText (org.eclipse.swt.custom.StyledText)1 Composite (org.eclipse.swt.widgets.Composite)1 FileStoreEditorInput (org.eclipse.ui.ide.FileStoreEditorInput)1 AbstractTextEditor (org.eclipse.ui.texteditor.AbstractTextEditor)1