Search in sources :

Example 21 with Preferences

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

the class AccountStart method removeConnectionDetails.

public void removeConnectionDetails(ConnectionDetails cd) {
    try {
        Preferences preferences = new InstanceScope().getNode(ClientPlugin.PLUGIN_ID);
        Preferences connections = preferences.node(SAVED);
        String[] targets = connections.childrenNames();
        for (int i = 0; i < targets.length; i++) {
            String target = targets[i];
            Preferences node = connections.node(target);
            String cdTarget = normalizeURI(cd.getTargetURI());
            if (node != null && target != null && target.equals(cdTarget)) {
                node.removeNode();
            }
        }
        connections.flush();
    } catch (BackingStoreException e) {
        ClientPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, ClientPlugin.PLUGIN_ID, BACKING_STORE_LOAD_ERROR, Messages.AccountStart_EXCEPTION_LOADING_CONNECTION_DETAILS, e));
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) InstanceScope(org.eclipse.core.runtime.preferences.InstanceScope) BackingStoreException(org.osgi.service.prefs.BackingStoreException) Preferences(org.osgi.service.prefs.Preferences)

Example 22 with Preferences

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

the class PreferenceInitializer method initializeDefaultPreferences.

public void initializeDefaultPreferences() {
    Preferences preferences = new DefaultScope().getNode(SyncResourcesCore.PLUGIN_ID);
    preferences.putInt(PreferenceConstants.LOCAL_RESOURCE_ADDITION, PreferenceConstants.COMMIT_VALUE);
    preferences.putInt(PreferenceConstants.LOCAL_RESOURCE_CHANGE, PreferenceConstants.COMMIT_VALUE);
    preferences.putInt(PreferenceConstants.LOCAL_RESOURCE_DELETION, PreferenceConstants.COMMIT_VALUE);
    preferences.putInt(PreferenceConstants.REMOTE_RESOURCE_ADDITION, PreferenceConstants.COMMIT_VALUE);
    preferences.putInt(PreferenceConstants.REMOTE_RESOURCE_CHANGE, PreferenceConstants.COMMIT_VALUE);
    preferences.putInt(PreferenceConstants.REMOTE_RESOURCE_DELETION, PreferenceConstants.COMMIT_VALUE);
}
Also used : DefaultScope(org.eclipse.core.runtime.preferences.DefaultScope) Preferences(org.osgi.service.prefs.Preferences)

Example 23 with Preferences

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

the class EclipsePreferencesTest method testInt.

public void testInt() {
    String qualifier = getUniqueString();
    Preferences prefs = getScopeRoot().node(qualifier);
    final String key = "key1";
    final int defaultValue = 42;
    final int[] values = { 0, 1002, -201788, Integer.MAX_VALUE, Integer.MIN_VALUE };
    try {
        // nothing there so expect the default
        assertEquals("1.1", defaultValue, prefs.getInt(key, defaultValue));
        // try for each value in the set
        for (int i = 0; i < values.length; i++) {
            int v1 = values[i];
            int v2 = 54;
            prefs.putInt(key, v1);
            assertEquals("1.2." + i, v1, prefs.getInt(key, defaultValue));
            prefs.putInt(key, v2);
            assertEquals("1.3." + i, v2, prefs.getInt(key, defaultValue));
            prefs.remove(key);
            assertEquals("1.4." + i, defaultValue, prefs.getInt(key, defaultValue));
        }
        String stringValue = "foo";
        prefs.put(key, stringValue);
        assertEquals("1.5", stringValue, prefs.get(key, null));
        assertEquals("1.6", defaultValue, prefs.getInt(key, defaultValue));
        // spec'd to throw a NPE if key is null
        try {
            prefs.getInt(null, defaultValue);
            fail("2.0");
        } catch (NullPointerException e) {
        // expected
        }
        // spec'd to throw a NPE if key is null
        try {
            prefs.putInt(null, defaultValue);
            fail("2.1");
        } catch (NullPointerException e) {
        // expected
        }
    } finally {
        // clean-up
        try {
            prefs.removeNode();
        } catch (BackingStoreException e) {
            fail("0.99", e);
        }
    }
    // spec'd to throw IllegalStateException if node has been removed
    try {
        prefs.getInt(key, defaultValue);
        fail("3.0");
    } catch (IllegalStateException e) {
    // expected
    }
}
Also used : BackingStoreException(org.osgi.service.prefs.BackingStoreException) Preferences(org.osgi.service.prefs.Preferences) EclipsePreferences(org.eclipse.core.internal.preferences.EclipsePreferences)

Example 24 with Preferences

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

the class PreferencesServiceTest method testGet.

public void testGet() {
    IPreferencesService service = Platform.getPreferencesService();
    String qualifier = getUniqueString();
    Preferences node = service.getRootNode().node(TestScope.SCOPE).node(qualifier);
    service.setDefaultLookupOrder(qualifier, null, new String[] { TestScope.SCOPE });
    // fun with paths
    String searchPath = "a";
    node.put("a", searchPath);
    assertEquals("3.0", searchPath, service.getString(qualifier, searchPath, null, null));
    searchPath = "a/b";
    node.node("a").put("b", searchPath);
    assertEquals("4.0", searchPath, service.getString(qualifier, searchPath, null, null));
    searchPath = "a//b";
    node.node("a").put("b", searchPath);
    assertEquals("5.0", searchPath, service.getString(qualifier, searchPath, null, null));
    searchPath = "a/b//c";
    node.node("a").node("b").put("c", searchPath);
    assertEquals("6.0", searchPath, service.getString(qualifier, searchPath, null, null));
    searchPath = "a/b//c/d";
    node.node("a").node("b").put("c/d", searchPath);
    assertEquals("7.0", searchPath, service.getString(qualifier, searchPath, null, null));
    searchPath = "/a";
    node.put("a", searchPath);
    assertEquals("8.0", searchPath, service.getString(qualifier, searchPath, null, null));
    searchPath = "/a/b";
    node.node("a").put("b", searchPath);
    assertEquals("9.0", searchPath, service.getString(qualifier, searchPath, null, null));
    searchPath = "///a";
    node.put("/a", searchPath);
    assertEquals("10.0", searchPath, service.getString(qualifier, searchPath, null, null));
}
Also used : Preferences(org.osgi.service.prefs.Preferences) EclipsePreferences(org.eclipse.core.internal.preferences.EclipsePreferences)

Example 25 with Preferences

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

the class PreferencesServiceTest method testExportExcludes1.

/*
	 * - create a child node with some key/value pairs
	 * - set the excludes to be the child name
	 * - export the parent
	 * - don't expect anything to be exported
	 */
public void testExportExcludes1() {
    // add some random key/value pairs
    String qualifier = getUniqueString();
    String child = "child";
    IEclipsePreferences node = new TestScope().getNode(qualifier);
    Preferences childNode = node.node(child);
    childNode.put("a", "v1");
    childNode.put("b", "v2");
    childNode.put("c", "v3");
    // set the excludes list so it doesn't export anything
    String[] excludes = new String[] { child };
    ExportVerifier verifier = new ExportVerifier(node, excludes);
    verifier.verify();
    // make the child path absolute and try again
    verifier.setExcludes(new String[] { '/' + child });
    verifier.verify();
}
Also used : Preferences(org.osgi.service.prefs.Preferences) EclipsePreferences(org.eclipse.core.internal.preferences.EclipsePreferences)

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