KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > resources > ProjectScope


1 /*******************************************************************************
2  * Copyright (c) 2004, 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 package org.eclipse.core.resources;
12
13 import org.eclipse.core.internal.preferences.EclipsePreferences;
14 import org.eclipse.core.runtime.IPath;
15 import org.eclipse.core.runtime.Platform;
16 import org.eclipse.core.runtime.preferences.IEclipsePreferences;
17 import org.eclipse.core.runtime.preferences.IScopeContext;
18
19 /**
20  * Object representing the project scope in the Eclipse preferences
21  * hierarchy. Can be used as a context for searching for preference
22  * values (in the <code>org.eclipse.core.runtime.IPreferencesService</code>
23  * APIs) or for determining the correct preference node to set values in the store.
24  * <p>
25  * Project preferences are stored on a per project basis in the
26  * project's content area as specified by <code>IProject#getLocation</code>.
27  * </p><p>
28  * The path for preferences defined in the project scope hierarchy
29  * is as follows: <code>/project/&lt;projectName&gt;/&lt;qualifier&gt;</code>
30  * </p>
31  * <p>
32  * This class is not intended to be subclassed. This class may be instantiated.
33  * </p>
34  * @see IProject#getLocation()
35  * @since 3.0
36  */

37 public final class ProjectScope implements IScopeContext {
38
39     /**
40      * String constant (value of <code>"project"</code>) used for the
41      * scope name for this preference scope.
42      */

43     public static final String JavaDoc SCOPE = "project"; //$NON-NLS-1$
44

45     private IProject context;
46
47     /**
48      * Create and return a new project scope for the given project. The given
49      * project must not be <code>null</code>.
50      *
51      * @param context the project
52      * @exception IllegalArgumentException if the project is <code>null</code>
53      */

54     public ProjectScope(IProject context) {
55         super();
56         if (context == null)
57             throw new IllegalArgumentException JavaDoc();
58         this.context = context;
59     }
60
61     /*
62      * @see org.eclipse.core.runtime.IScopeContext#getNode(java.lang.String)
63      */

64     public IEclipsePreferences getNode(String JavaDoc qualifier) {
65         if (qualifier == null)
66             throw new IllegalArgumentException JavaDoc();
67         return (IEclipsePreferences) Platform.getPreferencesService().getRootNode().node(SCOPE).node(context.getName()).node(qualifier);
68     }
69
70     /*
71      * @see org.eclipse.core.runtime.preferences.IScopeContext#getLocation()
72      */

73     public IPath getLocation() {
74         IProject project = ((IResource) context).getProject();
75         IPath location = project.getLocation();
76         return location == null ? null : location.append(EclipsePreferences.DEFAULT_PREFERENCES_DIRNAME);
77     }
78
79     /*
80      * @see org.eclipse.core.runtime.preferences.IScopeContext#getName()
81      */

82     public String JavaDoc getName() {
83         return SCOPE;
84     }
85
86     /* (non-Javadoc)
87      * @see java.lang.Object#equals(java.lang.Object)
88      */

89     public boolean equals(Object JavaDoc obj) {
90         if (this == obj)
91             return true;
92         if (!super.equals(obj))
93             return false;
94         if (!(obj instanceof ProjectScope))
95             return false;
96         ProjectScope other = (ProjectScope) obj;
97         return context.equals(other.context);
98     }
99
100     /* (non-Javadoc)
101      * @see java.lang.Object#hashCode()
102      */

103     public int hashCode() {
104         return super.hashCode() + context.getFullPath().hashCode();
105     }
106 }
107
Popular Tags