Search in sources :

Example 1 with PreferenceChangeEvent

use of org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent in project eclipse.platform.text by eclipse.

the class DefaultEncodingSupport method initialize.

/**
 * Associates this encoding support to the given text editor and initializes this encoding.
 *
 * @param textEditor the editor
 */
public void initialize(StatusTextEditor textEditor) {
    fTextEditor = textEditor;
    IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode(ResourcesPlugin.PI_RESOURCES);
    fPreferenceChangeListener = new IPreferenceChangeListener() {

        @Override
        public void preferenceChange(PreferenceChangeEvent event) {
            if (ResourcesPlugin.PREF_ENCODING.equals(event.getKey())) {
                Runnable runnable = new Runnable() {

                    @Override
                    public void run() {
                        // null means: use default
                        setEncoding(null, false);
                    }
                };
                if (Display.getCurrent() != null)
                    runnable.run();
                else {
                    // Post runnable into UI thread
                    Shell shell;
                    if (fTextEditor != null)
                        shell = fTextEditor.getSite().getShell();
                    else
                        shell = getActiveWorkbenchShell();
                    Display display;
                    if (shell != null)
                        display = shell.getDisplay();
                    else
                        display = Display.getDefault();
                    display.asyncExec(runnable);
                }
            }
        }
    };
    prefs.addPreferenceChangeListener(fPreferenceChangeListener);
}
Also used : PreferenceChangeEvent(org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent) IPreferenceChangeListener(org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener) Shell(org.eclipse.swt.widgets.Shell) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) Display(org.eclipse.swt.widgets.Display)

Aggregations

IEclipsePreferences (org.eclipse.core.runtime.preferences.IEclipsePreferences)1 IPreferenceChangeListener (org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener)1 PreferenceChangeEvent (org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent)1 Display (org.eclipse.swt.widgets.Display)1 Shell (org.eclipse.swt.widgets.Shell)1