1 11 12 package org.eclipse.jdt.internal.ui.preferences; 13 14 import org.eclipse.core.runtime.IPath; 15 import org.eclipse.core.runtime.preferences.DefaultScope; 16 import org.eclipse.core.runtime.preferences.IEclipsePreferences; 17 import org.eclipse.core.runtime.preferences.IScopeContext; 18 import org.eclipse.core.runtime.preferences.InstanceScope; 19 20 import org.eclipse.core.resources.IProject; 21 import org.eclipse.core.resources.ProjectScope; 22 23 import org.eclipse.ui.preferences.IWorkingCopyManager; 24 25 import org.osgi.service.prefs.BackingStoreException; 26 27 30 public class PreferencesAccess { 31 32 public static PreferencesAccess getOriginalPreferences() { 33 return new PreferencesAccess(); 34 } 35 36 public static PreferencesAccess getWorkingCopyPreferences(IWorkingCopyManager workingCopyManager) { 37 return new WorkingCopyPreferencesAccess(workingCopyManager); 38 } 39 40 private PreferencesAccess() { 41 } 43 44 public IScopeContext getDefaultScope() { 45 return new DefaultScope(); 46 } 47 48 public IScopeContext getInstanceScope() { 49 return new InstanceScope(); 50 } 51 52 public IScopeContext getProjectScope(IProject project) { 53 return new ProjectScope(project); 54 } 55 56 public void applyChanges() throws BackingStoreException { 57 } 58 59 60 private static class WorkingCopyPreferencesAccess extends PreferencesAccess { 61 62 private final IWorkingCopyManager fWorkingCopyManager; 63 64 private WorkingCopyPreferencesAccess(IWorkingCopyManager workingCopyManager) { 65 fWorkingCopyManager= workingCopyManager; 66 } 67 68 private final IScopeContext getWorkingCopyScopeContext(IScopeContext original) { 69 return new WorkingCopyScopeContext(fWorkingCopyManager, original); 70 } 71 72 public IScopeContext getDefaultScope() { 73 return getWorkingCopyScopeContext(super.getDefaultScope()); 74 } 75 76 public IScopeContext getInstanceScope() { 77 return getWorkingCopyScopeContext(super.getInstanceScope()); 78 } 79 80 public IScopeContext getProjectScope(IProject project) { 81 return getWorkingCopyScopeContext(super.getProjectScope(project)); 82 } 83 84 87 public void applyChanges() throws BackingStoreException { 88 fWorkingCopyManager.applyChanges(); 89 } 90 } 91 92 93 private static class WorkingCopyScopeContext implements IScopeContext { 94 95 private final IWorkingCopyManager fWorkingCopyManager; 96 private final IScopeContext fOriginal; 97 98 public WorkingCopyScopeContext(IWorkingCopyManager workingCopyManager, IScopeContext original) { 99 fWorkingCopyManager= workingCopyManager; 100 fOriginal= original; 101 } 102 103 106 public String getName() { 107 return fOriginal.getName(); 108 } 109 110 113 public IEclipsePreferences getNode(String qualifier) { 114 return fWorkingCopyManager.getWorkingCopy(fOriginal.getNode(qualifier)); 115 } 116 117 120 public IPath getLocation() { 121 return fOriginal.getLocation(); 122 } 123 } 124 125 126 } 127 | Popular Tags |