1 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 37 public final class ProjectScope implements IScopeContext { 38 39 43 public static final String SCOPE = "project"; 45 private IProject context; 46 47 54 public ProjectScope(IProject context) { 55 super(); 56 if (context == null) 57 throw new IllegalArgumentException (); 58 this.context = context; 59 } 60 61 64 public IEclipsePreferences getNode(String qualifier) { 65 if (qualifier == null) 66 throw new IllegalArgumentException (); 67 return (IEclipsePreferences) Platform.getPreferencesService().getRootNode().node(SCOPE).node(context.getName()).node(qualifier); 68 } 69 70 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 82 public String getName() { 83 return SCOPE; 84 } 85 86 89 public boolean equals(Object 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 103 public int hashCode() { 104 return super.hashCode() + context.getFullPath().hashCode(); 105 } 106 } 107 | Popular Tags |