use of org.osgi.service.prefs.Preferences in project eclipse.platform.runtime by eclipse.
the class ContentTypeSettings method removeFileSpec.
static void removeFileSpec(IScopeContext context, String contentTypeId, String fileSpec, int type) throws CoreException {
Preferences contentTypeNode = ContentTypeManager.getInstance().getPreferences(context).node(contentTypeId);
String key = ContentType.getPreferenceKey(type);
String existing = contentTypeNode.get(key, null);
if (existing == null)
// content type has no settings - nothing to do
return;
List<String> existingValues = Util.parseItemsIntoList(contentTypeNode.get(key, null));
int index = -1;
int existingCount = existingValues.size();
for (int i = 0; index == -1 && i < existingCount; i++) if (existingValues.get(i).equalsIgnoreCase(fileSpec))
index = i;
if (index == -1)
// did not find the file spec to be removed - nothing to do
return;
existingValues.remove(index);
// set new preference value
String newValue = Util.toListString(existingValues.toArray());
ContentType.setPreference(contentTypeNode, key, newValue);
try {
contentTypeNode.flush();
} catch (BackingStoreException bse) {
String message = NLS.bind(ContentMessages.content_errorSavingSettings, contentTypeId);
IStatus status = new Status(IStatus.ERROR, ContentMessages.OWNER_NAME, 0, message, bse);
throw new CoreException(status);
}
}
use of org.osgi.service.prefs.Preferences in project eclipse.platform.runtime by eclipse.
the class ContentTypeSettings method setDefaultCharset.
@Override
public void setDefaultCharset(String userCharset) throws CoreException {
Preferences contentTypeNode = ContentTypeManager.getInstance().getPreferences(context).node(contentType.getId());
ContentType.setPreference(contentTypeNode, ContentType.PREF_DEFAULT_CHARSET, userCharset);
try {
contentTypeNode.flush();
} catch (BackingStoreException bse) {
String message = NLS.bind(ContentMessages.content_errorSavingSettings, contentType.getId());
IStatus status = new Status(IStatus.ERROR, ContentMessages.OWNER_NAME, 0, message, bse);
throw new CoreException(status);
}
}
use of org.osgi.service.prefs.Preferences in project eclipse.platform.runtime by eclipse.
the class ContentTypeSettings method addFileSpec.
static void addFileSpec(IScopeContext context, String contentTypeId, String fileSpec, int type) throws CoreException {
Preferences contentTypeNode = ContentTypeManager.getInstance().getPreferences(context).node(contentTypeId);
String key = ContentType.getPreferenceKey(type);
List<String> existingValues = Util.parseItemsIntoList(contentTypeNode.get(key, null));
for (int i = 0; i < existingValues.size(); i++) if (existingValues.get(i).equalsIgnoreCase(fileSpec))
// don't do anything if already exists
return;
existingValues.add(fileSpec);
// set new preference value
String newValue = Util.toListString(existingValues.toArray());
ContentType.setPreference(contentTypeNode, key, newValue);
try {
contentTypeNode.flush();
} catch (BackingStoreException bse) {
String message = NLS.bind(ContentMessages.content_errorSavingSettings, contentTypeId);
IStatus status = new Status(IStatus.ERROR, ContentMessages.OWNER_NAME, 0, message, bse);
throw new CoreException(status);
}
}
use of org.osgi.service.prefs.Preferences in project eclipse.platform.runtime by eclipse.
the class PreferencePerformanceTest method testGetStringUniqueKeys.
/*
* Time how long it takes to get KEYS_PER_NODE keys that are unique.
*/
public void testGetStringUniqueKeys() {
// setup
final String qualifier = getUniqueString();
String[][] kvp = getUniqueKeys(KEYS_PER_NODE);
final String[] keys = kvp[0];
final String[] values = kvp[1];
// run the test
new PerformanceTestRunner() {
Preferences prefs;
// set the values outside the timed loop
@Override
protected void setUp() {
prefs = getScopeRoot().node(qualifier);
for (int i = 0; i < keys.length; i++) prefs.put(keys[i], values[i]);
}
// clean-up
@Override
protected void tearDown() {
try {
prefs.removeNode();
} catch (BackingStoreException e) {
fail("0.99", e);
}
}
// how long to get the values?
@Override
protected void test() {
for (String key : keys) prefs.get(key, null);
}
}.run(this, 10, INNER_LOOP);
}
use of org.osgi.service.prefs.Preferences in project eclipse.platform.runtime by eclipse.
the class PreferencePerformanceTest method testGetStringMisses.
/*
* Time how long it takes to get KEYS_PER_NODE keys that aren't there.
* Fill the node up with KEYS_PER_NODE key/value pairs so it has some data
*/
public void testGetStringMisses() {
// setup
final String qualifier = getUniqueString();
String[][] kvp = getUniqueKeys(KEYS_PER_NODE);
final String[] keys = kvp[0];
final String[] values = kvp[1];
final String[] missingKeys = getUniqueKeys(KEYS_PER_NODE)[0];
// run the test
new PerformanceTestRunner() {
Preferences prefs;
// set the values outside the timed loop
@Override
protected void setUp() {
prefs = getScopeRoot().node(qualifier);
for (int i = 0; i < keys.length; i++) prefs.put(keys[i], values[i]);
}
// clean-up
@Override
protected void tearDown() {
try {
prefs.removeNode();
} catch (BackingStoreException e) {
fail("0.99", e);
}
}
// how long to get the values?
@Override
protected void test() {
for (int i = 0; i < keys.length; i++) prefs.get(missingKeys[i], null);
}
}.run(this, 10, INNER_LOOP);
}
Aggregations