Search in sources :

Example 76 with ProjectScope

use of org.eclipse.core.resources.ProjectScope in project webtools.sourceediting by eclipse.

the class ELGeneratorVisitor method getScopeContexts.

private IScopeContext[] getScopeContexts() {
    IScopeContext[] scopes = new IScopeContext[] { new InstanceScope(), new DefaultScope() };
    final IFile file = getFile();
    if (file != null && file.exists()) {
        final IProject project = file.getProject();
        if (project.exists()) {
            final ProjectScope projectScope = new ProjectScope(project);
            if (projectScope.getNode(PREFERENCE_NODE_QUALIFIER).getBoolean(JSPCorePreferenceNames.VALIDATION_USE_PROJECT_SETTINGS, false)) {
                scopes = new IScopeContext[] { projectScope, new InstanceScope(), new DefaultScope() };
            }
        }
    }
    return scopes;
}
Also used : ProjectScope(org.eclipse.core.resources.ProjectScope) IScopeContext(org.eclipse.core.runtime.preferences.IScopeContext) IFile(org.eclipse.core.resources.IFile) InstanceScope(org.eclipse.core.runtime.preferences.InstanceScope) DefaultScope(org.eclipse.core.runtime.preferences.DefaultScope) IProject(org.eclipse.core.resources.IProject)

Example 77 with ProjectScope

use of org.eclipse.core.resources.ProjectScope in project webtools.sourceediting by eclipse.

the class NewJSPWizard method applyLineDelimiter.

private String applyLineDelimiter(IFile file, String text) {
    // $NON-NLS-1$
    String lineDelimiter = Platform.getPreferencesService().getString(Platform.PI_RUNTIME, Platform.PREF_LINE_SEPARATOR, System.getProperty("line.separator"), new IScopeContext[] { new ProjectScope(file.getProject()), new InstanceScope() });
    String convertedText = StringUtils.replace(text, "\r\n", "\n");
    convertedText = StringUtils.replace(convertedText, "\r", "\n");
    convertedText = StringUtils.replace(convertedText, "\n", lineDelimiter);
    return convertedText;
}
Also used : ProjectScope(org.eclipse.core.resources.ProjectScope) InstanceScope(org.eclipse.core.runtime.preferences.InstanceScope)

Example 78 with ProjectScope

use of org.eclipse.core.resources.ProjectScope in project webtools.sourceediting by eclipse.

the class CSSContentProperties method getPreferences.

/**
 * Get the preferences node associated with the given project scope and
 * preference key (subNode) If create is true, the preference node will be
 * created if one does not already exist
 *
 * @param project
 *            the project the preference node is under
 * @param preferenceKey
 *            the subnode/category the preference node is located in
 * @param create
 *            if true, a preference node will be created if one does not
 *            already exist
 * @return Preferences associated with the given project scope and
 *         preference key. null if one could not be found and create is
 *         false
 */
static Preferences getPreferences(IProject project, String preferenceKey, boolean create) {
    if (create)
        // create all nodes down to the one we are interested in
        return new ProjectScope(project).getNode(CSSCORE_ID).node(preferenceKey);
    // be careful looking up for our node so not to create any nodes as
    // side effect
    Preferences node = Platform.getPreferencesService().getRootNode().node(ProjectScope.SCOPE);
    try {
        // for now, take the long way
        if (!node.nodeExists(project.getName()))
            return null;
        node = node.node(project.getName());
        if (!node.nodeExists(CSSCORE_ID))
            return null;
        node = node.node(CSSCORE_ID);
        if (!node.nodeExists(preferenceKey))
            return null;
        return node.node(preferenceKey);
    } catch (BackingStoreException e) {
        // nodeExists failed
        // $NON-NLS-1$
        Logger.log(Logger.WARNING_DEBUG, "Could not retrieve preference node", e);
    }
    return null;
}
Also used : ProjectScope(org.eclipse.core.resources.ProjectScope) BackingStoreException(org.osgi.service.prefs.BackingStoreException) Preferences(org.osgi.service.prefs.Preferences)

Example 79 with ProjectScope

use of org.eclipse.core.resources.ProjectScope in project webtools.sourceediting by eclipse.

the class TaskScanningJob method isEnabledOnProject.

private boolean isEnabledOnProject(IProject p) {
    IPreferencesService preferencesService = Platform.getPreferencesService();
    IScopeContext[] lookupOrder = new IScopeContext[] { new ProjectScope(p), new InstanceScope(), new DefaultScope() };
    return preferencesService.getBoolean(TaskTagPreferenceKeys.TASK_TAG_NODE, TaskTagPreferenceKeys.TASK_TAG_ENABLE, false, lookupOrder);
}
Also used : ProjectScope(org.eclipse.core.resources.ProjectScope) IScopeContext(org.eclipse.core.runtime.preferences.IScopeContext) InstanceScope(org.eclipse.core.runtime.preferences.InstanceScope) DefaultScope(org.eclipse.core.runtime.preferences.DefaultScope) IPreferencesService(org.eclipse.core.runtime.preferences.IPreferencesService)

Example 80 with ProjectScope

use of org.eclipse.core.resources.ProjectScope in project webtools.sourceediting by eclipse.

the class JSPFContentProperties method getPreferences.

/**
 * Get the preferences node associated with the given project scope and
 * preference key (subNode) If create is true, the preference node will be
 * created if one does not already exist
 *
 * @param project
 *            the project the preference node is under
 * @param preferenceKey
 *            the subnode/category the preference node is located in
 * @param create
 *            if true, a preference node will be created if one does not
 *            already exist
 * @return Preferences associated with the given project scope and
 *         preference key. null if one could not be found and create is
 *         false
 */
static Preferences getPreferences(IProject project, String preferenceKey, boolean create) {
    if (create)
        // create all nodes down to the one we are interested in
        return new ProjectScope(project).getNode(JSPCORE_ID).node(preferenceKey);
    // be careful looking up for our node so not to create any nodes as
    // side effect
    Preferences node = Platform.getPreferencesService().getRootNode().node(ProjectScope.SCOPE);
    try {
        // for now, take the long way
        if (!node.nodeExists(project.getName()))
            return null;
        node = node.node(project.getName());
        if (!node.nodeExists(JSPCORE_ID))
            return null;
        node = node.node(JSPCORE_ID);
        if (!node.nodeExists(preferenceKey))
            return null;
        return node.node(preferenceKey);
    } catch (BackingStoreException e) {
        // nodeExists failed
        // $NON-NLS-1$
        Logger.log(Logger.WARNING_DEBUG, "Could not retrieve preference node", e);
    }
    return null;
}
Also used : ProjectScope(org.eclipse.core.resources.ProjectScope) BackingStoreException(org.osgi.service.prefs.BackingStoreException) Preferences(org.osgi.service.prefs.Preferences)

Aggregations

ProjectScope (org.eclipse.core.resources.ProjectScope)92 IScopeContext (org.eclipse.core.runtime.preferences.IScopeContext)42 InstanceScope (org.eclipse.core.runtime.preferences.InstanceScope)31 IProject (org.eclipse.core.resources.IProject)28 IEclipsePreferences (org.eclipse.core.runtime.preferences.IEclipsePreferences)24 Preferences (org.osgi.service.prefs.Preferences)18 DefaultScope (org.eclipse.core.runtime.preferences.DefaultScope)17 BackingStoreException (org.osgi.service.prefs.BackingStoreException)17 ScopedPreferenceStore (org.eclipse.ui.preferences.ScopedPreferenceStore)11 IFile (org.eclipse.core.resources.IFile)9 IResource (org.eclipse.core.resources.IResource)9 CoreException (org.eclipse.core.runtime.CoreException)8 IAdaptable (org.eclipse.core.runtime.IAdaptable)5 IPath (org.eclipse.core.runtime.IPath)5 HashSet (java.util.HashSet)4 Set (java.util.Set)4 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)4 Path (org.eclipse.core.runtime.Path)4 Test (org.junit.Test)4 File (java.io.File)3