All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.eclipse.core.resources.ProjectScope Maven / Gradle / Ivy

/*******************************************************************************
 * Copyright (c) 2004, 2006 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.core.resources;

import org.eclipse.core.internal.preferences.EclipsePreferences;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.IScopeContext;

/**
 * Object representing the project scope in the Eclipse preferences
 * hierarchy. Can be used as a context for searching for preference
 * values (in the org.eclipse.core.runtime.IPreferencesService
 * APIs) or for determining the correct preference node to set values in the store.
 * 

* Project preferences are stored on a per project basis in the * project's content area as specified by IProject#getLocation. *

* The path for preferences defined in the project scope hierarchy * is as follows: /project/<projectName>/<qualifier> *

*

* This class is not intended to be subclassed. This class may be instantiated. *

* @see IProject#getLocation() * @since 3.0 */ public final class ProjectScope implements IScopeContext { /** * String constant (value of "project") used for the * scope name for this preference scope. */ public static final String SCOPE = "project"; //$NON-NLS-1$ private IProject context; /** * Create and return a new project scope for the given project. The given * project must not be null. * * @param context the project * @exception IllegalArgumentException if the project is null */ public ProjectScope(IProject context) { super(); if (context == null) throw new IllegalArgumentException(); this.context = context; } /* * @see org.eclipse.core.runtime.IScopeContext#getNode(java.lang.String) */ public IEclipsePreferences getNode(String qualifier) { if (qualifier == null) throw new IllegalArgumentException(); return (IEclipsePreferences) Platform.getPreferencesService().getRootNode().node(SCOPE).node(context.getName()).node(qualifier); } /* * @see org.eclipse.core.runtime.preferences.IScopeContext#getLocation() */ public IPath getLocation() { IProject project = ((IResource) context).getProject(); IPath location = project.getLocation(); return location == null ? null : location.append(EclipsePreferences.DEFAULT_PREFERENCES_DIRNAME); } /* * @see org.eclipse.core.runtime.preferences.IScopeContext#getName() */ public String getName() { return SCOPE; } /* (non-Javadoc) * @see java.lang.Object#equals(java.lang.Object) */ public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (!(obj instanceof ProjectScope)) return false; ProjectScope other = (ProjectScope) obj; return context.equals(other.context); } /* (non-Javadoc) * @see java.lang.Object#hashCode() */ public int hashCode() { return super.hashCode() + context.getFullPath().hashCode(); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy