KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2005,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.ui.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.internal.preferences.WorkingCopyPreferences;
20 import org.osgi.service.prefs.BackingStoreException;
21
22 /**
23  * WorkingCopyManager is a concrete implementation of an
24  * IWorkingCopyManager.
25  * <p>
26  * This class is not intended to be sub-classed by clients.
27  * </p>
28  * @since 3.2
29  */

30 public class WorkingCopyManager implements IWorkingCopyManager{
31
32     private static final String JavaDoc EMPTY_STRING = "";//$NON-NLS-1$
33
// all working copies - maps absolute path to PreferencesWorkingCopy instance
34
private Map JavaDoc workingCopies = new HashMap JavaDoc();
35
36     
37     /* (non-Javadoc)
38      * @see org.eclipse.ui.preferences.IWorkingCopyManager#getWorkingCopy(org.eclipse.core.runtime.preferences.IEclipsePreferences)
39      */

40     public IEclipsePreferences getWorkingCopy(IEclipsePreferences original) {
41         if (original instanceof WorkingCopyPreferences) {
42             throw new IllegalArgumentException JavaDoc("Trying to get a working copy of a working copy"); //$NON-NLS-1$
43
}
44         String JavaDoc absolutePath = original.absolutePath();
45         IEclipsePreferences preferences = (IEclipsePreferences) workingCopies.get(absolutePath);
46         if (preferences == null) {
47             preferences = new WorkingCopyPreferences(original, this);
48             workingCopies.put(absolutePath, preferences);
49         }
50         return preferences;
51     }
52
53     
54     /* (non-Javadoc)
55      * @see org.eclipse.ui.preferences.IWorkingCopyManager#applyChanges()
56      */

57     public void applyChanges() throws BackingStoreException {
58         for (Iterator JavaDoc i = workingCopies.values().iterator(); i.hasNext();) {
59             WorkingCopyPreferences prefs = (WorkingCopyPreferences) i.next();
60             if (prefs.nodeExists(EMPTY_STRING))
61                 prefs.flush();
62         }
63     }
64
65 }
66
Popular Tags