KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > preferences > PreferencesAccess


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

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 /**
28  *
29  */

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         // can only extends in this file
42
}
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         /* (non-Javadoc)
85          * @see org.eclipse.jdt.internal.ui.preferences.PreferencesAccess#applyChanges()
86          */

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         /* (non-Javadoc)
104          * @see org.eclipse.core.runtime.preferences.IScopeContext#getName()
105          */

106         public String JavaDoc getName() {
107             return fOriginal.getName();
108         }
109
110         /* (non-Javadoc)
111          * @see org.eclipse.core.runtime.preferences.IScopeContext#getNode(java.lang.String)
112          */

113         public IEclipsePreferences getNode(String JavaDoc qualifier) {
114             return fWorkingCopyManager.getWorkingCopy(fOriginal.getNode(qualifier));
115         }
116
117         /* (non-Javadoc)
118          * @see org.eclipse.core.runtime.preferences.IScopeContext#getLocation()
119          */

120         public IPath getLocation() {
121             return fOriginal.getLocation();
122         }
123     }
124
125
126 }
127
Popular Tags