Search in sources :

Example 86 with Preferences

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

the class JSPCorePreferencesTest 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(ContentTypeIdForJSP.ContentTypeID_JSP);
    Preferences prefs = ContentBasedPreferenceGateway.getPreferences(ContentTypeIdForJSP.ContentTypeID_JSP);
    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
    JSPDocumentLoader loader = new JSPDocumentLoader();
    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 : 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) JSPDocumentLoader(org.eclipse.jst.jsp.core.internal.encoding.JSPDocumentLoader)

Example 87 with Preferences

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

the class XMLCorePreferencesTest 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(ContentTypeIdForXML.ContentTypeID_XML);
    Preferences prefs = ContentBasedPreferenceGateway.getPreferences(ContentTypeIdForXML.ContentTypeID_XML);
    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
    XMLDocumentLoader loader = new XMLDocumentLoader();
    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 : XMLDocumentLoader(org.eclipse.wst.xml.core.internal.encoding.XMLDocumentLoader) 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 88 with Preferences

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

the class JSPFContentProperties 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(JSPCORE_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(JSPCORE_ID))
            return null;
        node = node.node(JSPCORE_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 89 with Preferences

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

the class XSLValidationPreferencePage method getModelPreferences.

protected Preferences getModelPreferences() {
    IEclipsePreferences prefs = Platform.getPreferencesService().getRootNode();
    IProject project = getProject();
    if (project != null) {
        return prefs.node(ProjectScope.SCOPE).node(getPreferenceNodeQualifier());
    }
    Preferences instanceScope = prefs.node(InstanceScope.SCOPE).node(getPreferenceNodeQualifier());
    if (instanceScope != null) {
        return instanceScope;
    }
    return prefs.node(DefaultScope.SCOPE).node(getPreferenceNodeQualifier());
}
Also used : IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) ValidationPreferences(org.eclipse.wst.xsl.core.ValidationPreferences) Preferences(org.osgi.service.prefs.Preferences) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) IProject(org.eclipse.core.resources.IProject)

Example 90 with Preferences

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

the class XSLValidationPreferencePage method storeValues.

@Override
protected void storeValues() {
    super.storeValues();
    int maxErrors = Integer.parseInt(maxErrorsText.getText());
    Preferences prefs = getModelPreferences();
    prefs.putInt(ValidationPreferences.MAX_ERRORS, maxErrors);
    try {
        prefs.flush();
    } catch (BackingStoreException ex) {
        XSLUIPlugin.log(ex);
    }
}
Also used : BackingStoreException(org.osgi.service.prefs.BackingStoreException) ValidationPreferences(org.eclipse.wst.xsl.core.ValidationPreferences) Preferences(org.osgi.service.prefs.Preferences) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences)

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