Search in sources :

Example 1 with DefaultEncodingSupport

use of org.eclipse.ui.editors.text.DefaultEncodingSupport 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 DefaultEncodingSupport

use of org.eclipse.ui.editors.text.DefaultEncodingSupport 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 DefaultEncodingSupport

use of org.eclipse.ui.editors.text.DefaultEncodingSupport 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 DefaultEncodingSupport

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

the class AbstractDecoratedTextEditor method createStatusControl.

@Override
protected Control createStatusControl(Composite parent, final IStatus status) {
    Object adapter = getAdapter(IEncodingSupport.class);
    DefaultEncodingSupport encodingSupport = null;
    if (adapter instanceof DefaultEncodingSupport)
        encodingSupport = (DefaultEncodingSupport) adapter;
    if (encodingSupport == null || !encodingSupport.isEncodingError(status))
        return super.createStatusControl(parent, status);
    Shell shell = getSite().getShell();
    Display display = shell.getDisplay();
    Color bgColor = display.getSystemColor(SWT.COLOR_LIST_BACKGROUND);
    Color fgColor = display.getSystemColor(SWT.COLOR_LIST_FOREGROUND);
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new GridLayout());
    composite.setBackground(bgColor);
    composite.setForeground(fgColor);
    Control control = super.createStatusControl(composite, status);
    control.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    Composite buttonComposite = new Composite(composite, SWT.NONE);
    buttonComposite.setLayout(new GridLayout());
    buttonComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
    buttonComposite.setBackground(bgColor);
    buttonComposite.setForeground(fgColor);
    encodingSupport.createStatusEncodingChangeControl(buttonComposite, status);
    return composite;
}
Also used : DefaultEncodingSupport(org.eclipse.ui.editors.text.DefaultEncodingSupport) Shell(org.eclipse.swt.widgets.Shell) GridLayout(org.eclipse.swt.layout.GridLayout) Control(org.eclipse.swt.widgets.Control) Composite(org.eclipse.swt.widgets.Composite) Color(org.eclipse.swt.graphics.Color) GridData(org.eclipse.swt.layout.GridData) Display(org.eclipse.swt.widgets.Display)

Example 5 with DefaultEncodingSupport

use of org.eclipse.ui.editors.text.DefaultEncodingSupport in project webtools.sourceediting by eclipse.

the class EncodingSupport method reinitialize.

void reinitialize(String[] configurationPoints) {
    if (fSupportDelegate instanceof DefaultEncodingSupport) {
        ((DefaultEncodingSupport) fSupportDelegate).dispose();
    }
    fSupportDelegate = null;
    fConfigurationPoints = configurationPoints;
    IEncodingSupport encodingSupportDelegate = getEncodingSupportDelegate();
    if (encodingSupportDelegate instanceof DefaultEncodingSupport) {
        ((DefaultEncodingSupport) encodingSupportDelegate).initialize(fStatusTextEditor);
    }
}
Also used : DefaultEncodingSupport(org.eclipse.ui.editors.text.DefaultEncodingSupport) IEncodingSupport(org.eclipse.ui.editors.text.IEncodingSupport)

Aggregations

DefaultEncodingSupport (org.eclipse.ui.editors.text.DefaultEncodingSupport)6 IEncodingSupport (org.eclipse.ui.editors.text.IEncodingSupport)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 TextEditor (org.eclipse.ui.editors.text.TextEditor)3 StatusTextEditor (org.eclipse.ui.texteditor.StatusTextEditor)3 Test (org.junit.Test)3 Composite (org.eclipse.swt.widgets.Composite)2 ITextFileBuffer (org.eclipse.core.filebuffers.ITextFileBuffer)1 StyledText (org.eclipse.swt.custom.StyledText)1 Color (org.eclipse.swt.graphics.Color)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Control (org.eclipse.swt.widgets.Control)1 Display (org.eclipse.swt.widgets.Display)1 Shell (org.eclipse.swt.widgets.Shell)1