Search in sources :

Example 6 with Preferences

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;
}
Also used : Preferences(org.eclipse.core.runtime.Preferences) CoreException(org.eclipse.core.runtime.CoreException)

Example 7 with Preferences

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
    }
}
Also used : Preferences(org.eclipse.core.runtime.Preferences)

Example 8 with Preferences

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
    }
}
Also used : Preferences(org.eclipse.core.runtime.Preferences)

Example 9 with Preferences

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"));
}
Also used : Preferences(org.eclipse.core.runtime.Preferences)

Example 10 with Preferences

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);
}
Also used : Preferences(org.eclipse.core.runtime.Preferences)

Aggregations

Preferences (org.eclipse.core.runtime.Preferences)113 ByteArrayInputStream (java.io.ByteArrayInputStream)7 IndexedRegion (org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)7 IFile (org.eclipse.core.resources.IFile)6 PartInitException (org.eclipse.ui.PartInitException)6 CSSCleanupStrategy (org.eclipse.wst.css.core.internal.cleanup.CSSCleanupStrategy)6 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 OutputStreamWriter (java.io.OutputStreamWriter)5 IStructuredFormatPreferences (org.eclipse.wst.sse.core.internal.format.IStructuredFormatPreferences)5 ArrayList (java.util.ArrayList)4 CoreException (org.eclipse.core.runtime.CoreException)4 ICSSStyleDeclItem (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclItem)4 IStructuredCleanupPreferences (org.eclipse.wst.sse.core.internal.cleanup.IStructuredCleanupPreferences)4 StructuredCleanupPreferences (org.eclipse.wst.sse.core.internal.cleanup.StructuredCleanupPreferences)4 List (java.util.List)3 Vector (java.util.Vector)3 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)3 ResultSet (java.sql.ResultSet)2 Statement (java.sql.Statement)2