001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.jdt.internal.ui.preferences;
011:
012: import org.eclipse.core.runtime.IPath;
013: import org.eclipse.core.runtime.preferences.DefaultScope;
014: import org.eclipse.core.runtime.preferences.IEclipsePreferences;
015: import org.eclipse.core.runtime.preferences.IScopeContext;
016: import org.eclipse.core.runtime.preferences.InstanceScope;
017:
018: import org.eclipse.core.resources.IProject;
019: import org.eclipse.core.resources.ProjectScope;
020:
021: import org.eclipse.ui.preferences.IWorkingCopyManager;
022:
023: import org.osgi.service.prefs.BackingStoreException;
024:
025: /**
026: *
027: */
028: public class PreferencesAccess {
029:
030: public static PreferencesAccess getOriginalPreferences() {
031: return new PreferencesAccess();
032: }
033:
034: public static PreferencesAccess getWorkingCopyPreferences(
035: IWorkingCopyManager workingCopyManager) {
036: return new WorkingCopyPreferencesAccess(workingCopyManager);
037: }
038:
039: private PreferencesAccess() {
040: // can only extends in this file
041: }
042:
043: public IScopeContext getDefaultScope() {
044: return new DefaultScope();
045: }
046:
047: public IScopeContext getInstanceScope() {
048: return new InstanceScope();
049: }
050:
051: public IScopeContext getProjectScope(IProject project) {
052: return new ProjectScope(project);
053: }
054:
055: public void applyChanges() throws BackingStoreException {
056: }
057:
058: private static class WorkingCopyPreferencesAccess extends
059: PreferencesAccess {
060:
061: private final IWorkingCopyManager fWorkingCopyManager;
062:
063: private WorkingCopyPreferencesAccess(
064: IWorkingCopyManager workingCopyManager) {
065: fWorkingCopyManager = workingCopyManager;
066: }
067:
068: private final IScopeContext getWorkingCopyScopeContext(
069: IScopeContext original) {
070: return new WorkingCopyScopeContext(fWorkingCopyManager,
071: original);
072: }
073:
074: public IScopeContext getDefaultScope() {
075: return getWorkingCopyScopeContext(super .getDefaultScope());
076: }
077:
078: public IScopeContext getInstanceScope() {
079: return getWorkingCopyScopeContext(super .getInstanceScope());
080: }
081:
082: public IScopeContext getProjectScope(IProject project) {
083: return getWorkingCopyScopeContext(super
084: .getProjectScope(project));
085: }
086:
087: /* (non-Javadoc)
088: * @see org.eclipse.jdt.internal.ui.preferences.PreferencesAccess#applyChanges()
089: */
090: public void applyChanges() throws BackingStoreException {
091: fWorkingCopyManager.applyChanges();
092: }
093: }
094:
095: private static class WorkingCopyScopeContext implements
096: IScopeContext {
097:
098: private final IWorkingCopyManager fWorkingCopyManager;
099: private final IScopeContext fOriginal;
100:
101: public WorkingCopyScopeContext(
102: IWorkingCopyManager workingCopyManager,
103: IScopeContext original) {
104: fWorkingCopyManager = workingCopyManager;
105: fOriginal = original;
106: }
107:
108: /* (non-Javadoc)
109: * @see org.eclipse.core.runtime.preferences.IScopeContext#getName()
110: */
111: public String getName() {
112: return fOriginal.getName();
113: }
114:
115: /* (non-Javadoc)
116: * @see org.eclipse.core.runtime.preferences.IScopeContext#getNode(java.lang.String)
117: */
118: public IEclipsePreferences getNode(String qualifier) {
119: return fWorkingCopyManager.getWorkingCopy(fOriginal
120: .getNode(qualifier));
121: }
122:
123: /* (non-Javadoc)
124: * @see org.eclipse.core.runtime.preferences.IScopeContext#getLocation()
125: */
126: public IPath getLocation() {
127: return fOriginal.getLocation();
128: }
129: }
130:
131: }
|