Search in sources :

Example 76 with Preferences

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

the class JSONSourcePreferencePage method storeValuesForFormattingGroup.

private void storeValuesForFormattingGroup() {
    // Formatting
    Preferences prefs = getModelPreferences();
    prefs.setValue(JSONCorePreferenceNames.LINE_WIDTH, fLineWidthText.getText());
    if (fIndentUsingTabs.getSelection()) {
        getModelPreferences().setValue(JSONCorePreferenceNames.INDENTATION_CHAR, JSONCorePreferenceNames.TAB);
    } else {
        getModelPreferences().setValue(JSONCorePreferenceNames.INDENTATION_CHAR, JSONCorePreferenceNames.SPACE);
    }
    getModelPreferences().setValue(JSONCorePreferenceNames.INDENTATION_SIZE, fIndentationSize.getSelection());
}
Also used : Preferences(org.eclipse.core.runtime.Preferences)

Example 77 with Preferences

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

the class PrimitiveValueFormatter method formatPre.

/**
 */
protected void formatPre(ICSSNode node, StringBuffer source) {
    int start = ((IndexedRegion) node).getStartOffset();
    int end = ((IndexedRegion) node).getEndOffset();
    Preferences preferences = CSSCorePlugin.getDefault().getPluginPreferences();
    CSSCleanupStrategy stgy = getCleanupStrategy(node);
    if (end > 0) {
        // format source
        IStructuredDocument structuredDocument = node.getOwnerDocument().getModel().getStructuredDocument();
        CompoundRegion[] regions = getRegionsWithoutWhiteSpaces(structuredDocument, new FormatRegion(start, end - start), stgy);
        boolean appendQuote = regions.length > 1 && node.getParentNode() instanceof ICSSStyleDeclItem && isCleanup() && getCleanupStrategy(node).isQuoteValues() && (((ICSSStyleDeclItem) node.getParentNode()).getPropertyName().equals(PropCMProperty.P_FONT) || ((ICSSStyleDeclItem) node.getParentNode()).getPropertyName().equals(PropCMProperty.P_FONT_FAMILY) || ((ICSSStyleDeclItem) node.getParentNode()).getPropertyName().equals(PropCMProperty.P_VOICE_FAMILY));
        String quote = preferences.getString(CSSCorePreferenceNames.FORMAT_QUOTE);
        StringBuffer strBuf = new StringBuffer();
        boolean skipSpace = false;
        for (int i = 0; i < regions.length; i++) {
            if (i != 0 && !skipSpace)
                appendSpaceBefore(node, regions[i], strBuf);
            skipSpace = false;
            strBuf.append(decoratedPropValueRegion(regions[i], stgy));
            if (regions[i].getType() == CSSRegionContexts.CSS_DECLARATION_VALUE_FUNCTION)
                skipSpace = true;
        }
        if (appendQuote) {
            source.append(quote);
            String str = strBuf.toString();
            str = str.replace('\'', ' ');
            str = str.replace('\"', ' ');
            str = str.trim();
            source.append(str);
            source.append(quote);
        } else {
            source.append(strBuf);
        }
    } else {
        // generate source
        ICSSPrimitiveValue value = (ICSSPrimitiveValue) node;
        short type = value.getPrimitiveType();
        String quote = preferences.getString(CSSCorePreferenceNames.FORMAT_QUOTE);
        String str = null;
        switch(type) {
            case CSSPrimitiveValue.CSS_NUMBER:
            case CSSPrimitiveValue.CSS_PERCENTAGE:
            case CSSPrimitiveValue.CSS_EMS:
            case CSSPrimitiveValue.CSS_EXS:
            case CSSPrimitiveValue.CSS_PX:
            case CSSPrimitiveValue.CSS_CM:
            case CSSPrimitiveValue.CSS_MM:
            case CSSPrimitiveValue.CSS_IN:
            case CSSPrimitiveValue.CSS_PT:
            case CSSPrimitiveValue.CSS_PC:
            case CSSPrimitiveValue.CSS_DEG:
            case CSSPrimitiveValue.CSS_RAD:
            case CSSPrimitiveValue.CSS_GRAD:
            case CSSPrimitiveValue.CSS_MS:
            case CSSPrimitiveValue.CSS_S:
            case CSSPrimitiveValue.CSS_HZ:
            case CSSPrimitiveValue.CSS_KHZ:
            case CSSPrimitiveValue.CSS_DIMENSION:
            case ICSSPrimitiveValue.CSS_INTEGER:
                if (value.getFloatValue(type) == ((int) value.getFloatValue(type))) {
                    str = Integer.toString((int) value.getFloatValue(type));
                } else {
                    str = Float.toString(value.getFloatValue(type));
                }
                break;
            case CSSPrimitiveValue.CSS_IDENT:
            case ICSSPrimitiveValue.CSS_HASH:
            case ICSSPrimitiveValue.CSS_INHERIT_PRIMITIVE:
                str = value.getStringValue();
                if (str != null) {
                    if (preferences.getInt(CSSCorePreferenceNames.CASE_PROPERTY_VALUE) == CSSCorePreferenceNames.UPPER)
                        str = str.toUpperCase();
                    else
                        str.toLowerCase();
                }
                break;
            case CSSPrimitiveValue.CSS_STRING:
            case CSSPrimitiveValue.CSS_URI:
            case CSSPrimitiveValue.CSS_ATTR:
            case ICSSPrimitiveValue.CSS_URANGE:
            case ICSSPrimitiveValue.CSS_FORMAT:
            case ICSSPrimitiveValue.CSS_LOCAL:
            case ICSSPrimitiveValue.CSS_COMMA:
            case ICSSPrimitiveValue.CSS_SLASH:
                str = value.getStringValue();
        }
        String preStr = null, postStr = null;
        switch(type) {
            case CSSPrimitiveValue.CSS_ATTR:
                // $NON-NLS-1$
                preStr = "attr(";
                // $NON-NLS-1$
                postStr = ")";
                break;
            case CSSPrimitiveValue.CSS_CM:
                // $NON-NLS-1$
                postStr = "cm";
                break;
            // case ICSSPrimitiveValue.CSS_COUNTER:
            case CSSPrimitiveValue.CSS_DEG:
                // $NON-NLS-1$
                postStr = "deg";
                break;
            case CSSPrimitiveValue.CSS_EMS:
                // $NON-NLS-1$
                postStr = "em";
                break;
            case CSSPrimitiveValue.CSS_EXS:
                // $NON-NLS-1$
                postStr = "ex";
                break;
            case CSSPrimitiveValue.CSS_GRAD:
                // $NON-NLS-1$
                postStr = "grad";
                break;
            case CSSPrimitiveValue.CSS_HZ:
                // $NON-NLS-1$
                postStr = "Hz";
                break;
            case CSSPrimitiveValue.CSS_IN:
                // $NON-NLS-1$
                postStr = "in";
                break;
            case CSSPrimitiveValue.CSS_KHZ:
                // $NON-NLS-1$
                postStr = "kHz";
                break;
            case CSSPrimitiveValue.CSS_MM:
                // $NON-NLS-1$
                postStr = "mm";
                break;
            case CSSPrimitiveValue.CSS_MS:
                // $NON-NLS-1$
                postStr = "ms";
                break;
            case CSSPrimitiveValue.CSS_PC:
                // $NON-NLS-1$
                postStr = "pc";
                break;
            case CSSPrimitiveValue.CSS_PERCENTAGE:
                // $NON-NLS-1$
                postStr = "%";
                break;
            case CSSPrimitiveValue.CSS_PT:
                // $NON-NLS-1$
                postStr = "pt";
                break;
            case CSSPrimitiveValue.CSS_PX:
                // $NON-NLS-1$
                postStr = "px";
                break;
            case CSSPrimitiveValue.CSS_RAD:
                // $NON-NLS-1$
                postStr = "rad";
                break;
            // case ICSSPrimitiveValue.CSS_RGBCOLOR:
            case CSSPrimitiveValue.CSS_S:
                // $NON-NLS-1$
                postStr = "s";
                break;
            case CSSPrimitiveValue.CSS_STRING:
                quote = CSSUtil.detectQuote(str, quote);
                preStr = quote;
                postStr = quote;
                break;
            case CSSPrimitiveValue.CSS_URI:
                quote = CSSUtil.detectQuote(str, quote);
                // $NON-NLS-1$
                preStr = "url(" + quote;
                // $NON-NLS-1$
                postStr = quote + ")";
                break;
            // the followings are original primitive values
            case CSSPrimitiveValue.CSS_IDENT:
            case CSSPrimitiveValue.CSS_UNKNOWN:
            // use str
            case ICSSPrimitiveValue.CSS_INTEGER:
            case ICSSPrimitiveValue.CSS_HASH:
            case ICSSPrimitiveValue.CSS_SLASH:
            case ICSSPrimitiveValue.CSS_COMMA:
            case CSSPrimitiveValue.CSS_DIMENSION:
            case CSSPrimitiveValue.CSS_NUMBER:
            case ICSSPrimitiveValue.CSS_INHERIT_PRIMITIVE:
                break;
            case ICSSPrimitiveValue.CSS_URANGE:
                // $NON-NLS-1$
                preStr = "U+";
                break;
            case ICSSPrimitiveValue.CSS_FORMAT:
                quote = CSSUtil.detectQuote(str, quote);
                // $NON-NLS-1$
                preStr = "format(" + quote;
                // $NON-NLS-1$
                postStr = quote + ")";
                break;
            case ICSSPrimitiveValue.CSS_LOCAL:
                quote = CSSUtil.detectQuote(str, quote);
                // $NON-NLS-1$
                preStr = "local(" + quote;
                // $NON-NLS-1$
                postStr = quote + ")";
                break;
        }
        if (preferences.getInt(CSSCorePreferenceNames.CASE_PROPERTY_VALUE) == CSSCorePreferenceNames.UPPER) {
            if (preStr != null)
                preStr = preStr.toUpperCase();
            if (postStr != null)
                postStr = postStr.toUpperCase();
        }
        if (preStr != null)
            source.append(preStr);
        if (str != null)
            source.append(str);
        if (postStr != null)
            source.append(postStr);
    }
}
Also used : ICSSPrimitiveValue(org.eclipse.wst.css.core.internal.provisional.document.ICSSPrimitiveValue) IndexedRegion(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion) CSSCleanupStrategy(org.eclipse.wst.css.core.internal.cleanup.CSSCleanupStrategy) ICSSStyleDeclItem(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclItem) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) Preferences(org.eclipse.core.runtime.Preferences)

Example 78 with Preferences

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

the class CSSPreferenceHelper method getIndentString.

/**
 */
public String getIndentString() {
    StringBuffer indent = new StringBuffer();
    Preferences preferences = getPreferences();
    if (preferences != null) {
        char indentChar = ' ';
        String indentCharPref = preferences.getString(CSSCorePreferenceNames.INDENTATION_CHAR);
        if (CSSCorePreferenceNames.TAB.equals(indentCharPref)) {
            indentChar = '\t';
        }
        int indentationWidth = preferences.getInt(CSSCorePreferenceNames.INDENTATION_SIZE);
        for (int i = 0; i < indentationWidth; i++) {
            indent.append(indentChar);
        }
    }
    return indent.toString();
}
Also used : Preferences(org.eclipse.core.runtime.Preferences)

Example 79 with Preferences

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

the class NewCSSFileWizardPage method addDefaultExtension.

/**
 * Adds default extension to the filename
 *
 * @param filename
 * @return
 */
String addDefaultExtension(String filename) {
    StringBuffer newFileName = new StringBuffer(filename);
    Preferences preference = CSSCorePlugin.getDefault().getPluginPreferences();
    String ext = preference.getString(CSSCorePreferenceNames.DEFAULT_EXTENSION);
    // $NON-NLS-1$
    newFileName.append(".");
    newFileName.append(ext);
    return newFileName.toString();
}
Also used : Preferences(org.eclipse.core.runtime.Preferences)

Example 80 with Preferences

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

the class NewCSSWizard method performFinish.

public boolean performFinish() {
    boolean performedOK = false;
    // save user options for next use
    fNewFileTemplatesPage.saveLastSavedPreferences();
    // no file extension specified so add default extension
    String fileName = fNewFilePage.getFileName();
    if (fileName.lastIndexOf('.') == -1) {
        String newFileName = fNewFilePage.addDefaultExtension(fileName);
        fNewFilePage.setFileName(newFileName);
    }
    // create a new empty file
    IFile file = fNewFilePage.createNewFile();
    // sure to check
    if (file != null) {
        if (!file.isLinked()) {
            // put template contents into file
            String templateString = fNewFileTemplatesPage.getTemplateString();
            if (templateString != null) {
                templateString = applyLineDelimiter(file, templateString);
                // determine the encoding for the new file
                Preferences preference = CSSCorePlugin.getDefault().getPluginPreferences();
                String charSet = preference.getString(CommonEncodingPreferenceNames.OUTPUT_CODESET);
                try {
                    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
                    OutputStreamWriter outputStreamWriter = null;
                    if (charSet == null || charSet.trim().equals("")) {
                        // $NON-NLS-1$
                        // just use default encoding
                        outputStreamWriter = new OutputStreamWriter(outputStream);
                    } else {
                        outputStreamWriter = new OutputStreamWriter(outputStream, charSet);
                    }
                    outputStreamWriter.write(templateString);
                    outputStreamWriter.flush();
                    outputStreamWriter.close();
                    ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
                    file.setContents(inputStream, true, false, null);
                    inputStream.close();
                } catch (Exception e) {
                    // $NON-NLS-1$
                    Logger.log(Logger.WARNING_DEBUG, "Could not create contents for new CSS file", e);
                }
            }
        }
        // open the file in editor
        openEditor(file);
        // everything's fine
        performedOK = true;
    }
    return performedOK;
}
Also used : IFile(org.eclipse.core.resources.IFile) ByteArrayInputStream(java.io.ByteArrayInputStream) OutputStreamWriter(java.io.OutputStreamWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Preferences(org.eclipse.core.runtime.Preferences) PartInitException(org.eclipse.ui.PartInitException)

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