use of org.eclipse.core.runtime.Preferences in project webtools.servertools by eclipse.
the class MonitorManager method saveMonitors.
protected synchronized void saveMonitors() {
try {
ignorePreferenceChanges = true;
XMLMemento memento = XMLMemento.createWriteRoot("monitors");
Iterator iterator = monitors.iterator();
while (iterator.hasNext()) {
Monitor monitor = (Monitor) iterator.next();
IMemento child = memento.createChild("monitor");
monitor.save(child);
}
String xmlString = memento.saveToString();
Preferences prefs = MonitorPlugin.getInstance().getPluginPreferences();
prefs.setValue("monitors", xmlString);
MonitorPlugin.getInstance().savePluginPreferences();
} catch (Exception e) {
if (Trace.SEVERE) {
Trace.trace(Trace.STRING_SEVERE, "Could not save browsers", e);
}
}
ignorePreferenceChanges = false;
}
use of org.eclipse.core.runtime.Preferences in project eclipse.platform.runtime by eclipse.
the class PreferencesTest method testFloat.
public void testFloat() {
Preferences ps = new Preferences();
final String k1 = "key1";
final float[] values = { 0.0f, 1002.5f, -201788.55f, Float.MAX_VALUE, Float.MIN_VALUE };
final float tol = 1.0e-20f;
assertEquals("1.0", 0.0f, Preferences.FLOAT_DEFAULT_DEFAULT, tol);
assertEquals("1.1", Preferences.FLOAT_DEFAULT_DEFAULT, ps.getFloat(k1), tol);
for (float v1 : values) {
float v2 = v1 + 1.0f;
ps.setValue(k1, v1);
assertEquals("1.2", v1, ps.getFloat(k1), tol);
ps.setDefault(k1, v2);
assertEquals("1.3", v2, ps.getDefaultFloat(k1), tol);
}
try {
ps.setValue(k1, Float.NaN);
assertTrue("1.4", false);
} catch (IllegalArgumentException e) {
// NaNs should be rejected
}
}
use of org.eclipse.core.runtime.Preferences in project eclipse.platform.runtime by eclipse.
the class PreferencesTest method testDouble.
public void testDouble() {
Preferences ps = new Preferences();
final String k1 = "key1";
final double[] values = { 0.0, 1002.5, -201788.55, Double.MAX_VALUE, Double.MIN_VALUE };
final double tol = 1.0e-20;
assertEquals("1.0", 0.0, Preferences.DOUBLE_DEFAULT_DEFAULT, tol);
assertEquals("1.1", Preferences.DOUBLE_DEFAULT_DEFAULT, ps.getDouble(k1), tol);
for (double v1 : values) {
double v2 = v1 + 1.0;
ps.setValue(k1, v1);
assertEquals("1.2", v1, ps.getDouble(k1), tol);
ps.setDefault(k1, v2);
assertEquals("1.3", v2, ps.getDefaultDouble(k1), tol);
}
try {
ps.setValue(k1, Float.NaN);
assertTrue("1.4", false);
} catch (IllegalArgumentException e) {
// NaNs should be rejected
}
}
use of org.eclipse.core.runtime.Preferences in project eclipse.platform.runtime by eclipse.
the class PreferencesTest method testContains.
public void testContains() {
Preferences ps = new Preferences();
// there are no properties initially
assertEquals("1.0", false, ps.contains("a"));
// setting defaults adds name
ps.setDefault("a", "default");
assertEquals("1.1", true, ps.contains("a"));
// setting value adds name
assertEquals("1.2", false, ps.contains("b"));
ps.setValue("b", "any");
assertEquals("1.3", true, ps.contains("b"));
// setting value does not remove entry already there
ps.setValue("a", "any");
assertEquals("1.4", true, ps.contains("a"));
assertEquals("1.5", true, ps.contains("b"));
// setting to default removes name from set unless there is a default too
ps.setToDefault("b");
assertEquals("1.6", false, ps.contains("b"));
ps.setToDefault("a");
assertEquals("1.7", true, ps.contains("a"));
// bug 51309 - if a default-default value is stored
// as a default it is still a part of #contains
assertTrue("2.0", !ps.contains("c"));
ps.setDefault("c", Preferences.STRING_DEFAULT_DEFAULT);
assertTrue("2.1", ps.contains("c"));
}
use of org.eclipse.core.runtime.Preferences in project eclipse.platform.runtime by eclipse.
the class PreferencesTest method testDefaultPropertyNames.
public void testDefaultPropertyNames() {
Preferences ps = new Preferences();
// there are no default properties initially
assertEquals("1.0", 0, ps.defaultPropertyNames().length);
String[] keys = { "a", "b", "c", "d" };
// setting actual values does not add name to set
for (String key : keys) {
ps.setValue(key, "actual");
}
assertEquals("1.1", 0, ps.defaultPropertyNames().length);
// setting defaults does add name to set
for (String key : keys) {
ps.setDefault(key, "default");
}
assertEquals("1.2", keys.length, ps.defaultPropertyNames().length);
Set<String> s1 = new HashSet<>(Arrays.asList(keys));
Set<String> s2 = new HashSet<>(Arrays.asList(ps.defaultPropertyNames()));
assertEquals("1.3", s1, s2);
// setting to default does not remove name from set
for (String key : keys) {
ps.setToDefault(key);
Set<String> s = new HashSet<>(Arrays.asList(ps.defaultPropertyNames()));
assertTrue("1.4", s.contains(key));
}
assertEquals("1.5", keys.length, ps.defaultPropertyNames().length);
// setting to default-default does not remove name from set either
for (String key : keys) {
ps.setDefault(key, Preferences.STRING_DEFAULT_DEFAULT);
Set<String> s = new HashSet<>(Arrays.asList(ps.defaultPropertyNames()));
assertTrue("1.6.1", s.contains(key));
ps.setDefault(key, Preferences.BOOLEAN_DEFAULT_DEFAULT);
s = new HashSet<>(Arrays.asList(ps.defaultPropertyNames()));
assertTrue("1.6.2", s.contains(key));
ps.setDefault(key, Preferences.INT_DEFAULT_DEFAULT);
s = new HashSet<>(Arrays.asList(ps.defaultPropertyNames()));
assertTrue("1.6.3", s.contains(key));
ps.setDefault(key, Preferences.LONG_DEFAULT_DEFAULT);
s = new HashSet<>(Arrays.asList(ps.defaultPropertyNames()));
assertTrue("1.6.4", s.contains(key));
ps.setDefault(key, Preferences.FLOAT_DEFAULT_DEFAULT);
s = new HashSet<>(Arrays.asList(ps.defaultPropertyNames()));
assertTrue("1.6.5", s.contains(key));
ps.setDefault(key, Preferences.DOUBLE_DEFAULT_DEFAULT);
s = new HashSet<>(Arrays.asList(ps.defaultPropertyNames()));
assertTrue("1.6.6", s.contains(key));
}
assertEquals("1.7", keys.length, ps.defaultPropertyNames().length);
}
Aggregations