Search in sources :

Example 36 with Preferences

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);
    }
}
Also used : BackingStoreException(org.osgi.service.prefs.BackingStoreException) Preferences(org.osgi.service.prefs.Preferences)

Example 37 with Preferences

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);
    }
}
Also used : BackingStoreException(org.osgi.service.prefs.BackingStoreException) Preferences(org.osgi.service.prefs.Preferences)

Example 38 with Preferences

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);
    }
}
Also used : BackingStoreException(org.osgi.service.prefs.BackingStoreException) Preferences(org.osgi.service.prefs.Preferences)

Example 39 with Preferences

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);
}
Also used : PerformanceTestRunner(org.eclipse.core.tests.harness.PerformanceTestRunner) BackingStoreException(org.osgi.service.prefs.BackingStoreException) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) Preferences(org.osgi.service.prefs.Preferences)

Example 40 with Preferences

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);
}
Also used : PerformanceTestRunner(org.eclipse.core.tests.harness.PerformanceTestRunner) BackingStoreException(org.osgi.service.prefs.BackingStoreException) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) Preferences(org.osgi.service.prefs.Preferences)

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