Search in sources :

Example 51 with Preferences

use of org.osgi.service.prefs.Preferences in project webtools.sourceediting by eclipse.

the class ContentBasedPreferenceGateway method getDefaultPreferences.

private static Preferences getDefaultPreferences(IContentType contentType) {
    IEclipsePreferences eclipsePreferences = Platform.getPreferencesService().getRootNode();
    // TODO: eventaully need extension mechanism to avoid these hard coded
    // mechanism.
    // The idea is to load/store based on plugin's preferences, where the
    // content type was contributed
    // Eventually, too, we could do more "dynamic lookup" to get parent
    // types for defaults, etc.
    // Get default plugin preferences
    String pluginPreferenceLocation = DefaultScope.SCOPE + IPath.SEPARATOR + getContributorPluginId(contentType);
    Preferences pluginPreferences = eclipsePreferences.node(pluginPreferenceLocation);
    return pluginPreferences;
}
Also used : IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) Preferences(org.osgi.service.prefs.Preferences)

Example 52 with Preferences

use of org.osgi.service.prefs.Preferences in project webtools.sourceediting by eclipse.

the class ContentBasedPreferenceGateway method getPreferences.

public static Preferences getPreferences(IContentType contentType) {
    IEclipsePreferences eclipsePreferences = Platform.getPreferencesService().getRootNode();
    // TODO: eventaully need extension mechanism to avoid these hard coded
    // mechanism.
    // The idea is to load/store based on plugin's preferences, where the
    // content type was contributed
    // Eventually, too, we could do more "dynamic lookup" to get parent
    // types for defaults, etc.
    // Get instance plugin preferences
    String pluginPreferenceLocation = Plugin.PLUGIN_PREFERENCE_SCOPE + IPath.SEPARATOR + getContributorPluginId(contentType);
    Preferences pluginPreferences = eclipsePreferences.node(pluginPreferenceLocation);
    // return contentPreferences;
    return pluginPreferences;
}
Also used : IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) Preferences(org.osgi.service.prefs.Preferences)

Example 53 with Preferences

use of org.osgi.service.prefs.Preferences in project webtools.sourceediting by eclipse.

the class TestPreferences method printChildren.

/**
 * @param preferences
 * @throws BackingStoreException
 */
private static void printChildren(Preferences preferences) throws BackingStoreException {
    System.out.println("\t" + preferences.absolutePath());
    String[] keys = preferences.keys();
    printKeys(keys);
    String[] children = preferences.childrenNames();
    printChildren(children);
    for (int i = 0; i < children.length; i++) {
        String child = children[i];
        Preferences subPreferences = preferences.node(child);
        String[] subkeys = subPreferences.keys();
        System.out.println();
        System.out.println(child);
        System.out.println();
        printKeys(subkeys);
    }
}
Also used : IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) Preferences(org.osgi.service.prefs.Preferences)

Example 54 with Preferences

use of org.osgi.service.prefs.Preferences in project webtools.sourceediting by eclipse.

the class TestPreferences method testContentBasedPrefHTML.

public void testContentBasedPrefHTML() {
    IContentType contentType = Platform.getContentTypeManager().findContentTypeFor("test.html");
    Preferences preferences = ContentBasedPreferenceGateway.getPreferences(contentType);
    assertNotNull(preferences);
}
Also used : IContentType(org.eclipse.core.runtime.content.IContentType) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) Preferences(org.osgi.service.prefs.Preferences)

Example 55 with Preferences

use of org.osgi.service.prefs.Preferences in project azure-tools-for-java by Microsoft.

the class ApplicationInsightsPreferences method savePreferences.

/**
 * Stores application insights resources list
 * in preference file in the form of byte array.
 */
private void savePreferences() {
    try {
        Preferences prefs = PluginUtil.getPrefs(PREF_FILE);
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        ObjectOutput output = new ObjectOutputStream(buffer);
        List<ApplicationInsightsResource> data = ApplicationInsightsResourceRegistry.getAppInsightsResrcList();
        ApplicationInsightsResource[] dataArray = data.stream().filter(a -> !a.isImported()).sorted().toArray(ApplicationInsightsResource[]::new);
        /*
             * Sort list according to application insights resource name.
             * Save only manually added resources
             */
        try {
            output.writeObject(dataArray);
        } finally {
            output.close();
        }
        prefs.putByteArray(PREF_KEY, buffer.toByteArray());
        prefs.flush();
    } catch (BackingStoreException e) {
        Activator.getDefault().log(e.getMessage(), e);
    } catch (IOException e) {
        Activator.getDefault().log(e.getMessage(), e);
    }
}
Also used : ApplicationInsightsResource(com.microsoft.applicationinsights.preference.ApplicationInsightsResource) ObjectOutput(java.io.ObjectOutput) BackingStoreException(org.osgi.service.prefs.BackingStoreException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) Preferences(org.osgi.service.prefs.Preferences) ObjectOutputStream(java.io.ObjectOutputStream)

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