Search in sources :

Example 81 with Preferences

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

the class HTMLContentProperties method getPreferences.

/**
 * Get the preferences node associated with the given project scope and
 * preference key (subNode) If create is true, the preference node will be
 * created if one does not already exist
 *
 * @param project
 *            the project the preference node is under
 * @param preferenceKey
 *            the subnode/category the preference node is located in
 * @param create
 *            if true, a preference node will be created if one does not
 *            already exist
 * @return Preferences associated with the given project scope and
 *         preference key. null if one could not be found and create is
 *         false
 */
static Preferences getPreferences(IProject project, String preferenceKey, boolean create) {
    if (create)
        // create all nodes down to the one we are interested in
        return new ProjectScope(project).getNode(HTMLCORE_ID).node(preferenceKey);
    // be careful looking up for our node so not to create any nodes as
    // side effect
    Preferences node = Platform.getPreferencesService().getRootNode().node(ProjectScope.SCOPE);
    try {
        // for now, take the long way
        if (!node.nodeExists(project.getName()))
            return null;
        node = node.node(project.getName());
        if (!node.nodeExists(HTMLCORE_ID))
            return null;
        node = node.node(HTMLCORE_ID);
        if (!node.nodeExists(preferenceKey))
            return null;
        return node.node(preferenceKey);
    } catch (BackingStoreException e) {
        // nodeExists failed
        // $NON-NLS-1$
        Logger.log(Logger.WARNING_DEBUG, "Could not retrieve preference node", e);
    }
    return null;
}
Also used : ProjectScope(org.eclipse.core.resources.ProjectScope) BackingStoreException(org.osgi.service.prefs.BackingStoreException) Preferences(org.osgi.service.prefs.Preferences)

Example 82 with Preferences

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

the class CSSCorePreferencesTest method testDelimiterPreferences.

/**
 * Tests line delimiter preferences by making sure document created
 * follows line delimiter preference.
 */
public void testDelimiterPreferences() {
    // check if content type preferences match
    String preferredDelimiter = ContentTypeEncodingPreferences.getPreferredNewLineDelimiter(ContentTypeIdForCSS.ContentTypeID_CSS);
    Preferences prefs = ContentBasedPreferenceGateway.getPreferences(ContentTypeIdForCSS.ContentTypeID_CSS);
    String gatewayDelimiter = prefs.get(CommonEncodingPreferenceNames.END_OF_LINE_CODE, null);
    assertEquals("ContentTypeEncodingPreferences and ContentBasedPreferenceGateway preferences do not match", gatewayDelimiter, preferredDelimiter);
    // set a particular line delimiter
    prefs.put(CommonEncodingPreferenceNames.END_OF_LINE_CODE, CommonEncodingPreferenceNames.LF);
    // create document
    CSSDocumentLoader loader = new CSSDocumentLoader();
    IEncodedDocument document = loader.createNewStructuredDocument();
    String documentDelimiter = document.getPreferredLineDelimiter();
    // verify delimiter in document matches preference
    assertEquals("Delimiter in document does not match preference", CommonEncodingPreferenceNames.STRING_LF, documentDelimiter);
    // return to original preference
    prefs.remove(CommonEncodingPreferenceNames.END_OF_LINE_CODE);
}
Also used : CSSDocumentLoader(org.eclipse.wst.css.core.internal.encoding.CSSDocumentLoader) ContentTypeEncodingPreferences(org.eclipse.wst.sse.core.internal.encoding.ContentTypeEncodingPreferences) Preferences(org.osgi.service.prefs.Preferences) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) IEncodedDocument(org.eclipse.wst.sse.core.internal.provisional.document.IEncodedDocument)

Example 83 with Preferences

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

the class HTMLCorePreferencesTest method testDelimiterPreferences.

/**
 * Tests line delimiter preferences by making sure document created
 * follows line delimiter preference.
 */
public void testDelimiterPreferences() {
    // check if content type preferences match
    String preferredDelimiter = ContentTypeEncodingPreferences.getPreferredNewLineDelimiter(ContentTypeIdForHTML.ContentTypeID_HTML);
    Preferences prefs = ContentBasedPreferenceGateway.getPreferences(ContentTypeIdForHTML.ContentTypeID_HTML);
    String gatewayDelimiter = prefs.get(CommonEncodingPreferenceNames.END_OF_LINE_CODE, null);
    assertEquals("ContentTypeEncodingPreferences and ContentBasedPreferenceGateway preferences do not match", gatewayDelimiter, preferredDelimiter);
    // set a particular line delimiter
    prefs.put(CommonEncodingPreferenceNames.END_OF_LINE_CODE, CommonEncodingPreferenceNames.LF);
    // create document
    HTMLDocumentLoader loader = new HTMLDocumentLoader();
    IEncodedDocument document = loader.createNewStructuredDocument();
    String documentDelimiter = document.getPreferredLineDelimiter();
    // verify delimiter in document matches preference
    assertEquals("Delimiter in document does not match preference", CommonEncodingPreferenceNames.STRING_LF, documentDelimiter);
    // return to original preference
    prefs.remove(CommonEncodingPreferenceNames.END_OF_LINE_CODE);
}
Also used : HTMLDocumentLoader(org.eclipse.wst.html.core.internal.encoding.HTMLDocumentLoader) ContentTypeEncodingPreferences(org.eclipse.wst.sse.core.internal.encoding.ContentTypeEncodingPreferences) Preferences(org.osgi.service.prefs.Preferences) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) IEncodedDocument(org.eclipse.wst.sse.core.internal.provisional.document.IEncodedDocument)

Example 84 with Preferences

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

the class PrefUtil method getProperty.

private static String getProperty(String property) {
    // Importance order is:
    // default-default < instanceScope < configurationScope < systemProperty
    // < envVar
    String value = null;
    if (value == null) {
        value = System.getenv(property);
    }
    if (value == null) {
        value = System.getProperty(property);
    }
    if (value == null) {
        IPreferencesService preferencesService = Platform.getPreferencesService();
        String key = property;
        if (property != null && property.startsWith(SSECorePlugin.ID)) {
            // +1, include the "."
            key = property.substring(SSECorePlugin.ID.length() + 1, property.length());
        }
        InstanceScope instance = new InstanceScope();
        ConfigurationScope config = new ConfigurationScope();
        Preferences instanceNode = instance.getNode(SSECorePlugin.ID);
        Preferences configNode = config.getNode(SSECorePlugin.ID);
        value = preferencesService.get(key, getDefault(property), new Preferences[] { configNode, instanceNode });
    }
    return value;
}
Also used : InstanceScope(org.eclipse.core.runtime.preferences.InstanceScope) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) Preferences(org.osgi.service.prefs.Preferences) IPreferencesService(org.eclipse.core.runtime.preferences.IPreferencesService) ConfigurationScope(org.eclipse.core.runtime.preferences.ConfigurationScope)

Example 85 with Preferences

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

the class CSSContentProperties method getPreferences.

/**
 * Get the preferences node associated with the given project scope and
 * preference key (subNode) If create is true, the preference node will be
 * created if one does not already exist
 *
 * @param project
 *            the project the preference node is under
 * @param preferenceKey
 *            the subnode/category the preference node is located in
 * @param create
 *            if true, a preference node will be created if one does not
 *            already exist
 * @return Preferences associated with the given project scope and
 *         preference key. null if one could not be found and create is
 *         false
 */
static Preferences getPreferences(IProject project, String preferenceKey, boolean create) {
    if (create)
        // create all nodes down to the one we are interested in
        return new ProjectScope(project).getNode(CSSCORE_ID).node(preferenceKey);
    // be careful looking up for our node so not to create any nodes as
    // side effect
    Preferences node = Platform.getPreferencesService().getRootNode().node(ProjectScope.SCOPE);
    try {
        // for now, take the long way
        if (!node.nodeExists(project.getName()))
            return null;
        node = node.node(project.getName());
        if (!node.nodeExists(CSSCORE_ID))
            return null;
        node = node.node(CSSCORE_ID);
        if (!node.nodeExists(preferenceKey))
            return null;
        return node.node(preferenceKey);
    } catch (BackingStoreException e) {
        // nodeExists failed
        // $NON-NLS-1$
        Logger.log(Logger.WARNING_DEBUG, "Could not retrieve preference node", e);
    }
    return null;
}
Also used : ProjectScope(org.eclipse.core.resources.ProjectScope) BackingStoreException(org.osgi.service.prefs.BackingStoreException) 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