Search in sources :

Example 46 with Preferences

use of org.osgi.service.prefs.Preferences in project polymap4-core by Polymap4.

the class ProjectContentTypes method usesContentTypePreferences.

static boolean usesContentTypePreferences(String projectName) {
    try {
        // be careful looking up for our node so not to create any nodes as side effect
        Preferences node = PROJECT_SCOPE;
        // for now, take the long way
        if (!node.nodeExists(projectName))
            return false;
        node = node.node(projectName);
        if (!node.nodeExists(Platform.PI_RUNTIME))
            return false;
        node = node.node(Platform.PI_RUNTIME);
        if (!node.nodeExists(CONTENT_TYPE_PREF_NODE))
            return false;
        node = node.node(CONTENT_TYPE_PREF_NODE);
        return node.getBoolean(PREF_LOCAL_CONTENT_TYPE_SETTINGS, false);
    } catch (BackingStoreException e) {
    // exception treated when retrieving the project preferences
    }
    return false;
}
Also used : BackingStoreException(org.osgi.service.prefs.BackingStoreException) Preferences(org.osgi.service.prefs.Preferences)

Example 47 with Preferences

use of org.osgi.service.prefs.Preferences in project polymap4-core by Polymap4.

the class CharsetManager method getCharsetFor.

/**
 * Returns the charset explicitly set by the user for the given resource,
 * or <code>null</code>. If no setting exists for the given resource and
 * <code>recurse</code> is <code>true</code>, every parent up to the
 * workspace root will be checked until a charset setting can be found.
 *
 * @param resourcePath the path for the resource
 * @param recurse whether the parent should be queried
 * @return the charset setting for the given resource
 */
public String getCharsetFor(IPath resourcePath, boolean recurse) {
    Assert.isLegal(resourcePath.segmentCount() >= 1);
    IProject project = workspace.getRoot().getProject(resourcePath.segment(0));
    Preferences encodingSettings = getPreferences(project, false);
    if (encodingSettings == null)
        // lookup by falling back to workspace's default setting
        return recurse ? ResourcesPlugin.getEncoding() : null;
    return internalGetCharsetFor(resourcePath, encodingSettings, recurse);
}
Also used : Preferences(org.osgi.service.prefs.Preferences)

Example 48 with Preferences

use of org.osgi.service.prefs.Preferences in project polymap4-core by Polymap4.

the class CharsetManager method getPreferences.

Preferences getPreferences(IProject project, boolean create) {
    if (create)
        // create all nodes down to the one we are interested in
        return new ProjectScope(project).getNode(ResourcesPlugin.PI_RESOURCES).node(ENCODING_PREF_NODE);
    // 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(ResourcesPlugin.PI_RESOURCES))
            return null;
        node = node.node(ResourcesPlugin.PI_RESOURCES);
        if (!node.nodeExists(ENCODING_PREF_NODE))
            return null;
        return node.node(ENCODING_PREF_NODE);
    } catch (BackingStoreException e) {
        // nodeExists failed
        String message = Messages.resources_readingEncoding;
        Policy.log(new ResourceStatus(IResourceStatus.FAILED_GETTING_CHARSET, project.getFullPath(), message, e));
    }
    return null;
}
Also used : BackingStoreException(org.osgi.service.prefs.BackingStoreException) Preferences(org.osgi.service.prefs.Preferences)

Example 49 with Preferences

use of org.osgi.service.prefs.Preferences in project polymap4-core by Polymap4.

the class CharsetManager method setCharsetFor.

public void setCharsetFor(IPath resourcePath, String newCharset) throws CoreException {
    // for the workspace root we just set a preference in the instance scope
    if (resourcePath.segmentCount() == 0) {
        org.eclipse.core.runtime.Preferences resourcesPreferences = ResourcesPlugin.getPlugin().getPluginPreferences();
        if (newCharset != null)
            resourcesPreferences.setValue(ResourcesPlugin.PREF_ENCODING, newCharset);
        else
            resourcesPreferences.setToDefault(ResourcesPlugin.PREF_ENCODING);
        ResourcesPlugin.getPlugin().savePluginPreferences();
        return;
    }
    // for all other cases, we set a property in the corresponding project
    IProject project = workspace.getRoot().getProject(resourcePath.segment(0));
    Preferences encodingSettings = getPreferences(project, true);
    if (newCharset == null || newCharset.trim().length() == 0)
        encodingSettings.remove(getKeyFor(resourcePath));
    else
        encodingSettings.put(getKeyFor(resourcePath), newCharset);
    try {
        // disable the listener so we don't react to changes made by ourselves
        charsetListener.setDisabled(true);
        // save changes
        encodingSettings.flush();
    } catch (BackingStoreException e) {
        String message = Messages.resources_savingEncoding;
        throw new ResourceException(IResourceStatus.FAILED_SETTING_CHARSET, project.getFullPath(), message, e);
    } finally {
        charsetListener.setDisabled(false);
    }
}
Also used : BackingStoreException(org.osgi.service.prefs.BackingStoreException) org.eclipse.core.runtime(org.eclipse.core.runtime) Preferences(org.osgi.service.prefs.Preferences)

Example 50 with Preferences

use of org.osgi.service.prefs.Preferences in project eclipse-integration-commons by spring-projects.

the class CorePlugin method getUUID.

public static synchronized String getUUID() {
    ServiceReference ref = getDefault().getBundle().getBundleContext().getServiceReference(IPreferencesService.class.getName());
    IPreferencesService prefService = (IPreferencesService) getDefault().getBundle().getBundleContext().getService(ref);
    try {
        IEclipsePreferences prefs = (IEclipsePreferences) prefService.getRootNode().node(InstanceScope.SCOPE);
        Preferences p = prefs.node(PLUGIN_ID);
        if (StringUtils.isEmpty(p.get(UUID_PROPERTY_KEY, ""))) {
            p.put(UUID_PROPERTY_KEY, UUID.randomUUID().toString());
        }
        return p.get(UUID_PROPERTY_KEY, "");
    } finally {
        if (prefService != null) {
            getDefault().getBundle().getBundleContext().ungetService(ref);
        }
    }
}
Also used : IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) Preferences(org.osgi.service.prefs.Preferences) IPreferencesService(org.eclipse.core.runtime.preferences.IPreferencesService) ServiceReference(org.osgi.framework.ServiceReference)

Aggregations

Preferences (org.osgi.service.prefs.Preferences)157 BackingStoreException (org.osgi.service.prefs.BackingStoreException)82 EclipsePreferences (org.eclipse.core.internal.preferences.EclipsePreferences)41 IEclipsePreferences (org.eclipse.core.runtime.preferences.IEclipsePreferences)37 ProjectScope (org.eclipse.core.resources.ProjectScope)18 IScopeContext (org.eclipse.core.runtime.preferences.IScopeContext)14 IStatus (org.eclipse.core.runtime.IStatus)10 IOException (java.io.IOException)7 Test (org.junit.Test)7 IProject (org.eclipse.core.resources.IProject)6 Status (org.eclipse.core.runtime.Status)6 PerformanceTestRunner (org.eclipse.core.tests.harness.PerformanceTestRunner)6 InstanceScope (org.eclipse.core.runtime.preferences.InstanceScope)5 ISecurePreferences (org.eclipse.equinox.security.storage.ISecurePreferences)5 Field (java.lang.reflect.Field)4 ArrayList (java.util.ArrayList)4 ExportedPreferences (org.eclipse.core.internal.preferences.ExportedPreferences)4 IExportedPreferences (org.eclipse.core.runtime.preferences.IExportedPreferences)4 ContentTypeEncodingPreferences (org.eclipse.wst.sse.core.internal.encoding.ContentTypeEncodingPreferences)4 IEncodedDocument (org.eclipse.wst.sse.core.internal.provisional.document.IEncodedDocument)4