Search in sources :

Example 31 with Preferences

use of org.osgi.service.prefs.Preferences in project eclipse.platform.runtime by eclipse.

the class EclipsePreferencesTest method testName.

public void testName() {
    Preferences node = Platform.getPreferencesService().getRootNode();
    assertEquals("1.0", "", node.name());
    node = node.node(TestScope.SCOPE);
    assertEquals("2.0", TestScope.SCOPE, node.name());
    node = node.node("foo");
    assertEquals("3.0", "foo", node.name());
}
Also used : Preferences(org.osgi.service.prefs.Preferences) EclipsePreferences(org.eclipse.core.internal.preferences.EclipsePreferences)

Example 32 with Preferences

use of org.osgi.service.prefs.Preferences in project eclipse.platform.runtime by eclipse.

the class EclipsePreferencesTest method tearDown.

@Override
protected void tearDown() throws Exception {
    Preferences node = getScopeRoot();
    node.removeNode();
}
Also used : Preferences(org.osgi.service.prefs.Preferences) EclipsePreferences(org.eclipse.core.internal.preferences.EclipsePreferences)

Example 33 with Preferences

use of org.osgi.service.prefs.Preferences in project eclipse.platform.runtime by eclipse.

the class ContentType method addFileSpec.

@Override
public void addFileSpec(String fileSpec, int type) throws CoreException {
    Assert.isLegal(type == FILE_EXTENSION_SPEC || type == FILE_NAME_SPEC || type == FILE_PATTERN_SPEC, // $NON-NLS-1$
    "Unknown type: " + type);
    String[] userSet;
    synchronized (this) {
        if (!internalAddFileSpec(fileSpec, type | SPEC_USER_DEFINED))
            return;
        userSet = getFileSpecs(type | IGNORE_PRE_DEFINED);
    }
    // persist using preferences
    Preferences contentTypeNode = manager.getPreferences().node(id);
    String newValue = Util.toListString(userSet);
    // we are adding stuff, newValue must be non-null
    Assert.isNotNull(newValue);
    setPreference(contentTypeNode, getPreferenceKey(type), newValue);
    try {
        contentTypeNode.flush();
    } catch (BackingStoreException bse) {
        String message = NLS.bind(ContentMessages.content_errorSavingSettings, id);
        IStatus status = new Status(IStatus.ERROR, ContentMessages.OWNER_NAME, 0, message, bse);
        throw new CoreException(status);
    }
    // notify listeners
    manager.fireContentTypeChangeEvent(this);
}
Also used : BackingStoreException(org.osgi.service.prefs.BackingStoreException) Preferences(org.osgi.service.prefs.Preferences)

Example 34 with Preferences

use of org.osgi.service.prefs.Preferences in project eclipse.platform.runtime by eclipse.

the class ContentType method setDefaultCharset.

@Override
public void setDefaultCharset(String newCharset) throws CoreException {
    synchronized (this) {
        // don't do anything if there is no actual change
        if (userCharset == null) {
            if (newCharset == null)
                return;
        } else if (userCharset.equals(newCharset))
            return;
        // apply change in memory
        userCharset = newCharset;
    }
    // persist the change
    Preferences contentTypeNode = manager.getPreferences().node(id);
    setPreference(contentTypeNode, PREF_DEFAULT_CHARSET, userCharset);
    try {
        contentTypeNode.flush();
    } catch (BackingStoreException bse) {
        String message = NLS.bind(ContentMessages.content_errorSavingSettings, id);
        IStatus status = new Status(IStatus.ERROR, ContentMessages.OWNER_NAME, 0, message, bse);
        throw new CoreException(status);
    }
    // notify listeners
    manager.fireContentTypeChangeEvent(this);
}
Also used : BackingStoreException(org.osgi.service.prefs.BackingStoreException) Preferences(org.osgi.service.prefs.Preferences)

Example 35 with Preferences

use of org.osgi.service.prefs.Preferences in project eclipse.platform.runtime by eclipse.

the class ContentType method removeFileSpec.

@Override
public void removeFileSpec(String fileSpec, int type) throws CoreException {
    Assert.isLegal(type == FILE_EXTENSION_SPEC || type == FILE_NAME_SPEC || type == FILE_PATTERN_SPEC, // $NON-NLS-1$
    "Unknown type: " + type);
    synchronized (this) {
        if (!internalRemoveFileSpec(fileSpec, type | SPEC_USER_DEFINED))
            return;
    }
    // persist the change
    Preferences contentTypeNode = manager.getPreferences().node(id);
    final String[] userSet = getFileSpecs(type | IGNORE_PRE_DEFINED);
    String preferenceKey = getPreferenceKey(type);
    String newValue = Util.toListString(userSet);
    setPreference(contentTypeNode, preferenceKey, newValue);
    try {
        contentTypeNode.flush();
    } catch (BackingStoreException bse) {
        String message = NLS.bind(ContentMessages.content_errorSavingSettings, id);
        IStatus status = new Status(IStatus.ERROR, ContentMessages.OWNER_NAME, 0, message, bse);
        throw new CoreException(status);
    }
    // notify listeners
    manager.fireContentTypeChangeEvent(this);
}
Also used : BackingStoreException(org.osgi.service.prefs.BackingStoreException) Preferences(org.osgi.service.prefs.Preferences)

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