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();
}
}
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();
}
}
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();
}
}
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;
}
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);
}
}
Aggregations