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));
}
}
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);
}
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
}
}
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));
}
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();
}
Aggregations