KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > preferences > WorkingCopyManager


1 /*******************************************************************************
2  * Copyright (c) 2005 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.ui.internal.preferences;
13
14 import java.util.HashMap JavaDoc;
15 import java.util.Iterator JavaDoc;
16 import java.util.Map JavaDoc;
17
18 import org.eclipse.core.runtime.preferences.IEclipsePreferences;
19 import org.eclipse.ui.preferences.IWorkingCopyManager;
20 import org.osgi.service.prefs.BackingStoreException;
21
22 /**
23  * <p>
24  * This class is not intended to be sub-classed by clients.
25  * </p><p>
26  * This class is a work-in-progress and its API may change before the final release of Eclipse 3.1.
27  * </p>
28  * @since 3.1
29  */

30 public final class WorkingCopyManager implements IWorkingCopyManager{
31
32     // all working copies - maps absolute path to PreferencesWorkingCopy instance
33
private Map JavaDoc workingCopies = new HashMap JavaDoc();
34
35     /**
36      * Return a working copy instance based on the given preference node. If a working
37      * copy already exists then return it, otherwise create one and keep track of it for
38      * other clients who are looking for it.
39      *
40      * @param original the original node
41      * @return the working copy node
42      */

43     public IEclipsePreferences getWorkingCopy(IEclipsePreferences original) {
44         if (original instanceof WorkingCopyPreferences)
45             throw new IllegalArgumentException JavaDoc("Trying to get a working copy of a working copy"); //$NON-NLS-1$
46
String JavaDoc absolutePath = original.absolutePath();
47         IEclipsePreferences preferences = (IEclipsePreferences) workingCopies.get(absolutePath);
48         if (preferences == null) {
49             preferences = new WorkingCopyPreferences(original, this);
50             workingCopies.put(absolutePath, preferences);
51         }
52         return preferences;
53     }
54
55     /**
56      * Apply the changes for <em>all</em> working copies, to their original preference
57      * nodes. Alternatively, if a client wishes to apply the changes for a single working copy
58      * they can call <code>#flush</code> on that working copy node.
59      *
60      * @throws BackingStoreException if there were problems accessing the backing store
61      */

62     public void applyChanges() throws BackingStoreException {
63         for (Iterator JavaDoc i = workingCopies.values().iterator(); i.hasNext();)
64             ((WorkingCopyPreferences) i.next()).flush();
65     }
66
67 }
68
Popular Tags