Search in sources :

Example 11 with Preferences

use of org.eclipse.core.runtime.Preferences in project eclipse.platform.runtime by eclipse.

the class PreferencesTest method testBasics.

public void testBasics() {
    Preferences ps = new Preferences();
    final String k1 = "key1";
    final String v1 = "1";
    final String v2 = "2";
    final String v3 = "3";
    // check that a random property in a newly created store
    // appearchs to have default-default values of whatever type asked for
    assertTrue("1.0", ps.isDefault(k1));
    assertTrue("1.1", ps.getBoolean(k1) == Preferences.BOOLEAN_DEFAULT_DEFAULT);
    assertTrue("1.2", ps.getInt(k1) == Preferences.INT_DEFAULT_DEFAULT);
    assertTrue("1.3", ps.getLong(k1) == Preferences.LONG_DEFAULT_DEFAULT);
    assertTrue("1.4", ps.getFloat(k1) == Preferences.FLOAT_DEFAULT_DEFAULT);
    assertTrue("1.5", ps.getDouble(k1) == Preferences.DOUBLE_DEFAULT_DEFAULT);
    assertTrue("1.6", ps.getString(k1).equals(Preferences.STRING_DEFAULT_DEFAULT));
    assertTrue("1.7", ps.getDefaultBoolean(k1) == Preferences.BOOLEAN_DEFAULT_DEFAULT);
    assertTrue("1.8", ps.getDefaultInt(k1) == Preferences.INT_DEFAULT_DEFAULT);
    assertTrue("1.9", ps.getDefaultLong(k1) == Preferences.LONG_DEFAULT_DEFAULT);
    assertTrue("1.10", ps.getDefaultFloat(k1) == Preferences.FLOAT_DEFAULT_DEFAULT);
    assertTrue("1.11", ps.getDefaultDouble(k1) == Preferences.DOUBLE_DEFAULT_DEFAULT);
    assertTrue("1.12", ps.getDefaultString(k1).equals(Preferences.STRING_DEFAULT_DEFAULT));
    // test set/getString
    // give it a value
    ps.setValue(k1, v1);
    assertFalse("2.0", ps.isDefault(k1));
    assertTrue("2.1", ps.getString(k1).equals(v1));
    assertTrue("2.2", ps.getDefaultString(k1).equals(Preferences.STRING_DEFAULT_DEFAULT));
    // change the value
    ps.setValue(k1, v2);
    assertFalse("2.3", ps.isDefault(k1));
    assertTrue("2.4", ps.getString(k1).equals(v2));
    assertTrue("2.5", ps.getDefaultString(k1).equals(Preferences.STRING_DEFAULT_DEFAULT));
    // change to same value as default
    ps.setValue(k1, ps.getDefaultString(k1));
    assertTrue("2.6", ps.isDefault(k1) == true);
    assertTrue("2.7", ps.getString(k1).equals(ps.getDefaultString(k1)));
    assertTrue("2.8", ps.getDefaultString(k1).equals(Preferences.STRING_DEFAULT_DEFAULT));
    // reset to default
    ps.setValue(k1, v2);
    ps.setToDefault(k1);
    assertTrue("2.9", ps.isDefault(k1));
    assertTrue("2.10", ps.getString(k1).equals(Preferences.STRING_DEFAULT_DEFAULT));
    assertTrue("2.11", ps.getDefaultString(k1).equals(Preferences.STRING_DEFAULT_DEFAULT));
    // change default
    ps.setDefault(k1, v1);
    assertTrue("2.12", ps.isDefault(k1));
    assertTrue("2.13", ps.getString(k1).equals(v1));
    assertTrue("2.14", ps.getDefaultString(k1).equals(v1));
    // set the value
    ps.setValue(k1, v2);
    assertFalse("2.15", ps.isDefault(k1));
    assertTrue("2.16", ps.getString(k1).equals(v2));
    assertTrue("2.17", ps.getDefaultString(k1).equals(v1));
    // change to same value as default
    ps.setValue(k1, ps.getDefaultString(k1));
    assertTrue("2.18", ps.isDefault(k1));
    assertTrue("2.19", ps.getString(k1).equals(ps.getDefaultString(k1)));
    assertTrue("2.20", ps.getDefaultString(k1).equals(v1));
    // reset to default
    ps.setValue(k1, v2);
    ps.setToDefault(k1);
    assertTrue("2.21", ps.isDefault(k1));
    assertTrue("2.22", ps.getString(k1).equals(v1));
    assertTrue("2.23", ps.getDefaultString(k1).equals(v1));
    // change default
    ps.setDefault(k1, v3);
    assertTrue("2.24", ps.isDefault(k1));
    assertTrue("2.25", ps.getString(k1).equals(v3));
    assertTrue("2.26", ps.getDefaultString(k1).equals(v3));
}
Also used : Preferences(org.eclipse.core.runtime.Preferences)

Example 12 with Preferences

use of org.eclipse.core.runtime.Preferences in project eclipse.platform.runtime by eclipse.

the class PreferencesTest method testLong.

public void testLong() {
    Preferences ps = new Preferences();
    final String k1 = "key1";
    final long[] values = { 0L, 1002L, -201788L, Long.MAX_VALUE, Long.MIN_VALUE };
    assertEquals("1.0", 0L, Preferences.LONG_DEFAULT_DEFAULT);
    assertEquals("1.1", Preferences.LONG_DEFAULT_DEFAULT, ps.getLong(k1));
    for (long v1 : values) {
        long v2 = v1 + 1;
        ps.setValue(k1, v1);
        assertEquals("1.2", v1, ps.getLong(k1));
        ps.setDefault(k1, v2);
        assertEquals("1.3", v2, ps.getDefaultLong(k1));
    }
}
Also used : Preferences(org.eclipse.core.runtime.Preferences)

Example 13 with Preferences

use of org.eclipse.core.runtime.Preferences in project webtools.sourceediting by eclipse.

the class JSONSourcePreferencePage method initializeValuesForFormattingGroup.

private void initializeValuesForFormattingGroup() {
    // Formatting
    Preferences prefs = getModelPreferences();
    fLineWidthText.setText(prefs.getString(JSONCorePreferenceNames.LINE_WIDTH));
    if (JSONCorePreferenceNames.TAB.equals(getModelPreferences().getString(JSONCorePreferenceNames.INDENTATION_CHAR))) {
        fIndentUsingTabs.setSelection(true);
        fIndentUsingSpaces.setSelection(false);
    } else {
        fIndentUsingSpaces.setSelection(true);
        fIndentUsingTabs.setSelection(false);
    }
    fIndentationSize.setSelection(getModelPreferences().getInt(JSONCorePreferenceNames.INDENTATION_SIZE));
}
Also used : Preferences(org.eclipse.core.runtime.Preferences)

Example 14 with Preferences

use of org.eclipse.core.runtime.Preferences in project webtools.sourceediting by eclipse.

the class JSONSourcePreferencePage method performDefaultsForFormattingGroup.

private void performDefaultsForFormattingGroup() {
    // Formatting
    Preferences prefs = getModelPreferences();
    fLineWidthText.setText(prefs.getDefaultString(JSONCorePreferenceNames.LINE_WIDTH));
    if (JSONCorePreferenceNames.TAB.equals(getModelPreferences().getDefaultString(JSONCorePreferenceNames.INDENTATION_CHAR))) {
        fIndentUsingTabs.setSelection(true);
        fIndentUsingSpaces.setSelection(false);
    } else {
        fIndentUsingSpaces.setSelection(true);
        fIndentUsingTabs.setSelection(false);
    }
    fIndentationSize.setSelection(getModelPreferences().getDefaultInt(JSONCorePreferenceNames.INDENTATION_SIZE));
}
Also used : Preferences(org.eclipse.core.runtime.Preferences)

Example 15 with Preferences

use of org.eclipse.core.runtime.Preferences in project webtools.sourceediting by eclipse.

the class AbstractCSSSourceFormatter method appendSpaceBefore.

/**
 */
protected void appendSpaceBefore(ICSSNode node, CompoundRegion toAppend, StringBuffer source) {
    if (node == null || toAppend == null || source == null)
        return;
    if (isCleanup() && !getCleanupStrategy(node).isFormatSource())
        // for not formatting case on cleanup action
        return;
    String type = toAppend.getType();
    Preferences preferences = CSSCorePlugin.getDefault().getPluginPreferences();
    boolean needIndent = !(node instanceof ICSSStyleSheet);
    if (type == CSSRegionContexts.CSS_COMMENT) {
        // check whether previous region is 'S' and has CR-LF
        String delim = getLineDelimiter(node);
        RegionIterator it = new RegionIterator(toAppend.getDocumentRegion(), toAppend.getTextRegion());
        it.prev();
        ITextRegion prev = it.prev();
        // bug390904
        if (prev.getType() == CSSRegionContexts.CSS_LBRACE && TextUtilities.indexOf(DefaultLineTracker.DELIMITERS, it.getStructuredDocumentRegion().getFullText(prev), 0)[0] > 0) {
            source.append(delim);
            source.append(getIndent(node));
            source.append(getIndentString());
        } else if (prev.getType() == CSSRegionContexts.CSS_S && TextUtilities.indexOf(DefaultLineTracker.DELIMITERS, it.getStructuredDocumentRegion().getText(prev), 0)[0] >= 0) {
            source.append(delim);
            source.append(getIndent(node));
            if (needIndent)
                source.append(getIndentString());
        } else {
            appendSpaceBefore(node, toAppend.getText(), source);
        }
    } else if (type == CSSRegionContexts.CSS_LBRACE && preferences.getBoolean(CSSCorePreferenceNames.WRAPPING_NEWLINE_ON_OPEN_BRACE)) {
        String delim = getLineDelimiter(node);
        source.append(delim);
        source.append(getIndent(node));
    // } else if (type == CSSRegionContexts.CSS_CURLY_BRACE_CLOSE) {
    // } else if (type == CSSRegionContexts.CSS_INCLUDES || type ==
    // CSSRegionContexts.CSS_DASHMATCH) {
    } else if (type == CSSRegionContexts.CSS_DECLARATION_SEPARATOR && node instanceof ICSSStyleDeclItem) {
        int n = preferences.getInt(CSSCorePreferenceNames.FORMAT_PROP_PRE_DELIM);
        // no delimiter case
        while (n-- > 0) // $NON-NLS-1$
        source.append(" ");
    } else if (type == CSSRegionContexts.CSS_DECLARATION_VALUE_OPERATOR || type == CSSRegionContexts.CSS_DECLARATION_VALUE_PARENTHESIS_CLOSE) {
        if (preferences.getInt(CSSCorePreferenceNames.LINE_WIDTH) > 0 && (!preferences.getBoolean(CSSCorePreferenceNames.WRAPPING_PROHIBIT_WRAP_ON_ATTR) || node.getOwnerDocument().getNodeType() != ICSSNode.STYLEDECLARATION_NODE)) {
            int length = getLastLineLength(node, source);
            int append = 1;
            if (length + append > preferences.getInt(CSSCorePreferenceNames.LINE_WIDTH)) {
                source.append(getLineDelimiter(node));
                source.append(getIndent(node));
                if (needIndent)
                    source.append(getIndentString());
            }
        }
    } else if (CSSRegionContexts.CSS_FOREIGN_ELEMENT == type || CSSRegionContexts.CSS_DECLARATION_DELIMITER == type) {
        return;
    } else
        appendSpaceBefore(node, toAppend.getText(), source);
}
Also used : ICSSStyleDeclItem(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclItem) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) RegionIterator(org.eclipse.wst.css.core.internal.util.RegionIterator) Preferences(org.eclipse.core.runtime.Preferences) ICSSStyleSheet(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleSheet)

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