Search in sources :

Example 1 with IEncodingSupport

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

Example 2 with IEncodingSupport

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

the class EncodingSupport method initialize.

/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.eclipse.ui.editors.text.DefaultEncodingSupport#initialize(org.eclipse
	 * .ui.texteditor.StatusTextEditor)
	 */
public void initialize(StatusTextEditor textEditor) {
    super.initialize(textEditor);
    fStatusTextEditor = textEditor;
    IEncodingSupport encodingSupportDelegate = getEncodingSupportDelegate();
    if (encodingSupportDelegate instanceof DefaultEncodingSupport) {
        ((DefaultEncodingSupport) encodingSupportDelegate).initialize(textEditor);
    }
}
Also used : DefaultEncodingSupport(org.eclipse.ui.editors.text.DefaultEncodingSupport) IEncodingSupport(org.eclipse.ui.editors.text.IEncodingSupport)

Example 3 with IEncodingSupport

use of org.eclipse.ui.editors.text.IEncodingSupport in project dbeaver by serge-rider.

the class BinaryEditor method loadBinaryContent.

private void loadBinaryContent() {
    String charset = GeneralUtils.UTF8_ENCODING;
    IEditorInput editorInput = getEditorInput();
    if (editorInput instanceof IEncodingSupport) {
        charset = ((IEncodingSupport) editorInput).getEncoding();
    }
    File systemFile = null;
    if (editorInput instanceof IPathEditorInput) {
        systemFile = ((IPathEditorInput) editorInput).getPath().toFile();
    }
    if (systemFile != null) {
        // open file
        try {
            manager.openFile(systemFile, charset);
        } catch (IOException e) {
            log.error("Can't open binary content", e);
        }
        setPartName(systemFile.getName());
    }
}
Also used : IEncodingSupport(org.eclipse.ui.editors.text.IEncodingSupport) IOException(java.io.IOException) File(java.io.File)

Example 4 with IEncodingSupport

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

the class ChangeEncodingAction method run.

@Override
public void run() {
    final IResource resource = getResource();
    final Shell parentShell = getTextEditor().getSite().getShell();
    final IEncodingSupport encodingSupport = getEncodingSupport();
    if (resource == null && encodingSupport == null) {
        MessageDialog.openInformation(parentShell, fDialogTitle, TextEditorMessages.ChangeEncodingAction_message_noEncodingSupport);
        return;
    }
    Dialog dialog = new Dialog(parentShell) {

        private AbstractEncodingFieldEditor fEncodingEditor;

        private IPreferenceStore store = null;

        @Override
        protected void configureShell(Shell newShell) {
            super.configureShell(newShell);
            newShell.setText(fDialogTitle);
        }

        @Override
        protected Control createDialogArea(Composite parent) {
            Composite composite = (Composite) super.createDialogArea(parent);
            composite = new Composite(composite, SWT.NONE);
            GridLayout layout = new GridLayout();
            layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
            layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
            layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
            layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
            composite.setLayout(layout);
            GridData data = new GridData(GridData.FILL_BOTH);
            composite.setLayoutData(data);
            composite.setFont(parent.getFont());
            DialogPage page = new MessageDialogPage(composite) {

                @Override
                public void setErrorMessage(String newMessage) {
                    super.setErrorMessage(newMessage);
                    setButtonEnabledState(IDialogConstants.OK_ID, newMessage == null);
                    setButtonEnabledState(APPLY_ID, newMessage == null);
                }

                private void setButtonEnabledState(int id, boolean state) {
                    Button button = getButton(id);
                    if (button != null)
                        button.setEnabled(state);
                }
            };
            if (resource != null) {
                // $NON-NLS-1$
                fEncodingEditor = new ResourceEncodingFieldEditor("", composite, resource, null);
                fEncodingEditor.setPage(page);
                fEncodingEditor.load();
            } else {
                // $NON-NLS-1$
                fEncodingEditor = new EncodingFieldEditor(ENCODING_PREF_KEY, "", null, composite);
                store = new PreferenceStore();
                String defaultEncoding = encodingSupport.getDefaultEncoding();
                store.setDefault(ENCODING_PREF_KEY, defaultEncoding);
                String encoding = encodingSupport.getEncoding();
                if (encoding != null)
                    store.setValue(ENCODING_PREF_KEY, encoding);
                fEncodingEditor.setPreferenceStore(store);
                fEncodingEditor.setPage(page);
                fEncodingEditor.load();
                if (encoding == null || encoding.equals(defaultEncoding) || encoding.length() == 0)
                    fEncodingEditor.loadDefault();
            }
            return composite;
        }

        @Override
        protected void createButtonsForButtonBar(Composite parent) {
            createButton(parent, APPLY_ID, TextEditorMessages.ChangeEncodingAction_button_apply_label, false);
            super.createButtonsForButtonBar(parent);
        }

        @Override
        protected void buttonPressed(int buttonId) {
            if (buttonId == APPLY_ID)
                apply();
            else
                super.buttonPressed(buttonId);
        }

        @Override
        protected void okPressed() {
            apply();
            super.okPressed();
        }

        private void apply() {
            fEncodingEditor.store();
            if (resource == null) {
                String encoding = fEncodingEditor.getPreferenceStore().getString(fEncodingEditor.getPreferenceName());
                encodingSupport.setEncoding(encoding);
            }
        }
    };
    dialog.open();
}
Also used : AbstractEncodingFieldEditor(org.eclipse.ui.ide.dialogs.AbstractEncodingFieldEditor) Composite(org.eclipse.swt.widgets.Composite) IEncodingSupport(org.eclipse.ui.editors.text.IEncodingSupport) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) PreferenceStore(org.eclipse.jface.preference.PreferenceStore) Shell(org.eclipse.swt.widgets.Shell) GridLayout(org.eclipse.swt.layout.GridLayout) AbstractEncodingFieldEditor(org.eclipse.ui.ide.dialogs.AbstractEncodingFieldEditor) ResourceEncodingFieldEditor(org.eclipse.ui.ide.dialogs.ResourceEncodingFieldEditor) EncodingFieldEditor(org.eclipse.ui.ide.dialogs.EncodingFieldEditor) Button(org.eclipse.swt.widgets.Button) ResourceEncodingFieldEditor(org.eclipse.ui.ide.dialogs.ResourceEncodingFieldEditor) Dialog(org.eclipse.jface.dialogs.Dialog) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) DialogPage(org.eclipse.jface.dialogs.DialogPage) GridData(org.eclipse.swt.layout.GridData) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) IResource(org.eclipse.core.resources.IResource)

Example 5 with IEncodingSupport

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

the class EncodingSupport method setEncoding.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.ui.editors.text.DefaultEncodingSupport#setEncoding
	 * (java.lang.String, boolean)
	 */
protected void setEncoding(String encoding, boolean overwrite) {
    super.setEncoding(encoding, overwrite);
    IEncodingSupport delegate = getEncodingSupportDelegate();
    if (delegate != null && overwrite) {
        delegate.setEncoding(encoding);
    }
}
Also used : IEncodingSupport(org.eclipse.ui.editors.text.IEncodingSupport)

Aggregations

IEncodingSupport (org.eclipse.ui.editors.text.IEncodingSupport)6 File (java.io.File)2 IOException (java.io.IOException)2 DefaultEncodingSupport (org.eclipse.ui.editors.text.DefaultEncodingSupport)2 IResource (org.eclipse.core.resources.IResource)1 Dialog (org.eclipse.jface.dialogs.Dialog)1 DialogPage (org.eclipse.jface.dialogs.DialogPage)1 MessageDialog (org.eclipse.jface.dialogs.MessageDialog)1 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)1 PreferenceStore (org.eclipse.jface.preference.PreferenceStore)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Button (org.eclipse.swt.widgets.Button)1 Composite (org.eclipse.swt.widgets.Composite)1 Shell (org.eclipse.swt.widgets.Shell)1 AbstractEncodingFieldEditor (org.eclipse.ui.ide.dialogs.AbstractEncodingFieldEditor)1 EncodingFieldEditor (org.eclipse.ui.ide.dialogs.EncodingFieldEditor)1 ResourceEncodingFieldEditor (org.eclipse.ui.ide.dialogs.ResourceEncodingFieldEditor)1