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