1 11 package org.eclipse.ui.internal; 12 13 import java.io.IOException ; 14 import java.io.Reader ; 15 import java.io.StringReader ; 16 import java.util.HashMap ; 17 18 import org.eclipse.core.runtime.preferences.IEclipsePreferences; 19 import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent; 20 import org.eclipse.jface.preference.IPreferenceStore; 21 import org.eclipse.ui.IEditorDescriptor; 22 import org.eclipse.ui.IEditorRegistry; 23 import org.eclipse.ui.IWorkbench; 24 import org.eclipse.ui.IWorkbenchPreferenceConstants; 25 import org.eclipse.ui.IWorkbenchWindow; 26 import org.eclipse.ui.PlatformUI; 27 import org.eclipse.ui.WorkbenchException; 28 import org.eclipse.ui.internal.decorators.DecoratorManager; 29 import org.eclipse.ui.internal.progress.ProgressManager; 30 import org.eclipse.ui.internal.registry.EditorRegistry; 31 import org.eclipse.ui.internal.util.PrefUtil; 32 33 38 public class PlatformUIPreferenceListener implements 39 IEclipsePreferences.IPreferenceChangeListener { 40 41 private static PlatformUIPreferenceListener singleton; 42 43 public static IEclipsePreferences.IPreferenceChangeListener getSingleton(){ 44 if(singleton == null) { 45 singleton = new PlatformUIPreferenceListener(); 46 } 47 return singleton; 48 } 49 50 55 public void preferenceChange(PreferenceChangeEvent event) { 56 57 String propertyName = event.getKey(); 58 if (IPreferenceConstants.ENABLED_DECORATORS.equals(propertyName)) { 59 DecoratorManager manager = WorkbenchPlugin.getDefault() 60 .getDecoratorManager(); 61 manager.applyDecoratorsPreference(); 62 manager.clearCaches(); 63 manager.updateForEnablementChange(); 64 return; 65 } 66 67 if (IWorkbenchPreferenceConstants.SHOW_SYSTEM_JOBS.equals(propertyName)) { 68 boolean setting = PrefUtil.getAPIPreferenceStore().getBoolean( 69 IWorkbenchPreferenceConstants.SHOW_SYSTEM_JOBS); 70 71 ProgressManager.getInstance().setShowSystemJobs(setting); 72 } 73 74 if (IWorkbenchPreferenceConstants.DEFAULT_PERSPECTIVE_ID.equals(propertyName)) { 75 IWorkbench workbench = PlatformUI.getWorkbench(); 76 77 workbench.getPerspectiveRegistry().setDefaultPerspective( 78 PrefUtil.getAPIPreferenceStore().getString( 79 IWorkbenchPreferenceConstants.DEFAULT_PERSPECTIVE_ID)); 80 return; 81 } 82 83 if (IWorkbenchPreferenceConstants.DOCK_PERSPECTIVE_BAR 84 .equals(propertyName)) { 85 IPreferenceStore apiStore = PrefUtil.getAPIPreferenceStore(); 86 IWorkbench workbench = PlatformUI.getWorkbench(); 87 IWorkbenchWindow[] workbenchWindows = workbench 88 .getWorkbenchWindows(); 89 for (int i = 0; i < workbenchWindows.length; i++) { 90 IWorkbenchWindow window = workbenchWindows[i]; 91 if (window instanceof WorkbenchWindow) { 92 ((WorkbenchWindow) window) 93 .setPerspectiveBarLocation(apiStore 94 .getString(IWorkbenchPreferenceConstants.DOCK_PERSPECTIVE_BAR)); 95 } 96 } 97 return; 98 } 99 100 if (IWorkbenchPreferenceConstants.SHOW_TRADITIONAL_STYLE_TABS 102 .equals(propertyName)) { 103 boolean newValue = PrefUtil.getAPIPreferenceStore().getBoolean( 104 IWorkbenchPreferenceConstants.SHOW_TRADITIONAL_STYLE_TABS); 105 106 IWorkbench workbench = PlatformUI.getWorkbench(); 107 IWorkbenchWindow[] workbenchWindows = workbench 108 .getWorkbenchWindows(); 109 for (int i = 0; i < workbenchWindows.length; i++) { 110 IWorkbenchWindow window = workbenchWindows[i]; 111 if (window instanceof WorkbenchWindow) { 112 ((WorkbenchWindow) window).setBannerCurve(newValue); 113 } 114 } 115 return; 116 } 117 118 if (IPreferenceConstants.RESOURCES.equals(propertyName)) { 120 IEditorRegistry registry = WorkbenchPlugin.getDefault() 121 .getEditorRegistry(); 122 if (registry instanceof EditorRegistry) { 123 EditorRegistry editorRegistry = (EditorRegistry) registry; 124 IPreferenceStore store = WorkbenchPlugin.getDefault() 125 .getPreferenceStore(); 126 Reader reader = null; 127 try { 128 String xmlString = store 129 .getString(IPreferenceConstants.RESOURCES); 130 if (xmlString != null && xmlString.length() > 0) { 131 reader = new StringReader (xmlString); 132 HashMap editorMap = new HashMap (); 134 int i = 0; 135 IEditorDescriptor[] descriptors = editorRegistry 136 .getSortedEditorsFromPlugins(); 137 for (i = 0; i < descriptors.length; i++) { 139 IEditorDescriptor descriptor = descriptors[i]; 140 editorMap.put(descriptor.getId(), descriptor); 141 } 142 descriptors = editorRegistry.getSortedEditorsFromOS(); 144 for (i = 0; i < descriptors.length; i++) { 145 IEditorDescriptor descriptor = descriptors[i]; 146 editorMap.put(descriptor.getId(), descriptor); 147 } 148 editorRegistry.readResources(editorMap, reader); 150 } 151 } catch (WorkbenchException e) { 152 e.printStackTrace(); 153 } finally { 154 if (reader != null) { 155 try { 156 reader.close(); 157 } catch (IOException e) { 158 e.printStackTrace(); 159 } 160 } 161 } 162 } 163 } 164 } 165 166 } 167 | Popular Tags |