01: /*******************************************************************************
02: * Copyright (c) 2005,2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.preferences;
11:
12: import java.util.Collection;
13: import java.util.HashMap;
14: import java.util.Map;
15:
16: import org.eclipse.core.runtime.preferences.IEclipsePreferences;
17: import org.eclipse.ui.internal.preferences.WorkingCopyPreferences;
18: import org.osgi.service.prefs.BackingStoreException;
19:
20: /**
21: * WorkingCopyManager is a concrete implementation of an
22: * IWorkingCopyManager.
23: * <p>
24: * This class is not intended to be sub-classed by clients.
25: * </p>
26: * @since 3.2
27: */
28: public class WorkingCopyManager implements IWorkingCopyManager {
29:
30: private static final String EMPTY_STRING = "";//$NON-NLS-1$
31: // all working copies - maps absolute path to PreferencesWorkingCopy instance
32: private Map workingCopies = new HashMap();
33:
34: /* (non-Javadoc)
35: * @see org.eclipse.ui.preferences.IWorkingCopyManager#getWorkingCopy(org.eclipse.core.runtime.preferences.IEclipsePreferences)
36: */
37: public IEclipsePreferences getWorkingCopy(
38: IEclipsePreferences original) {
39: if (original instanceof WorkingCopyPreferences) {
40: throw new IllegalArgumentException(
41: "Trying to get a working copy of a working copy"); //$NON-NLS-1$
42: }
43: String absolutePath = original.absolutePath();
44: IEclipsePreferences preferences = (IEclipsePreferences) workingCopies
45: .get(absolutePath);
46: if (preferences == null) {
47: preferences = new WorkingCopyPreferences(original, this );
48: workingCopies.put(absolutePath, preferences);
49: }
50: return preferences;
51: }
52:
53: /* (non-Javadoc)
54: * @see org.eclipse.ui.preferences.IWorkingCopyManager#applyChanges()
55: */
56: public void applyChanges() throws BackingStoreException {
57: Collection values = workingCopies.values();
58: WorkingCopyPreferences[] valuesArray = (WorkingCopyPreferences[]) values
59: .toArray(new WorkingCopyPreferences[values.size()]);
60: for (int i = 0; i < valuesArray.length; i++) {
61: WorkingCopyPreferences prefs = valuesArray[i];
62: if (prefs.nodeExists(EMPTY_STRING))
63: prefs.flush();
64: }
65: }
66:
67: }
|