Search in sources :

Example 1 with ICSSValue

use of org.eclipse.wst.css.core.internal.provisional.document.ICSSValue in project webtools.sourceediting by eclipse.

the class BackgroundPositionXSubStyleAdapter method get.

/**
 */
public String get(ICSS2Properties properties) {
    String str = null;
    Object obj = properties.get(PropCMProperty.getInstanceOf(PropCMProperty.P_BG_POSITION));
    if (obj != null) {
        PropCMProperty propX = PropCMSubProperty.getInstanceOf(PropCMSubProperty.PSUB_BG_POSITION_X);
        PropCMProperty propY = PropCMSubProperty.getInstanceOf(PropCMSubProperty.PSUB_BG_POSITION_Y);
        if (obj instanceof ICSSValueList) {
            ICSSValueList list = (ICSSValueList) obj;
            ICSSValue value = (ICSSValue) list.item(0);
            if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
                ICSSPrimitiveValue prim = (ICSSPrimitiveValue) value;
                if (prim.getPrimitiveType() == CSSPrimitiveValue.CSS_IDENT) {
                    // check not top or bottom
                    if (!propX.canHave(prim.getStringValue()) && propY.canHave(prim.getStringValue())) {
                        // case order is vertical -> horizontal
                        value = (ICSSValue) list.item(1);
                    }
                }
            }
            str = value.getCSSValueText();
        } else if (obj instanceof ICSSValue) {
            str = ((ICSSValue) obj).getCSSValueText();
            if (str.equalsIgnoreCase(IValID.V_BOTTOM) || str.equalsIgnoreCase(IValID.V_TOP))
                // $NON-NLS-1$
                str = "";
        } else {
            str = obj.toString();
            CSSTextParser parser = new CSSTextParser(CSSTextParser.MODE_DECLARATION_VALUE, str);
            CSSTextToken[] tokens = parser.getTokens();
            tokens = correctMeaningToken(tokens);
            if (tokens.length == 0)
                // $NON-NLS-1$
                str = "";
            else if (tokens.length == 1 && (tokens[0].image.equalsIgnoreCase(IValID.V_BOTTOM) || tokens[0].image.equalsIgnoreCase(IValID.V_TOP)))
                // $NON-NLS-1$
                str = "";
            else
                str = tokens[0].image;
        }
    }
    // $NON-NLS-1$
    return (str != null) ? str : "";
}
Also used : PropCMProperty(org.eclipse.wst.css.core.internal.contentmodel.PropCMProperty) ICSSValue(org.eclipse.wst.css.core.internal.provisional.document.ICSSValue) ICSSPrimitiveValue(org.eclipse.wst.css.core.internal.provisional.document.ICSSPrimitiveValue) CSSTextParser(org.eclipse.wst.css.core.internal.parserz.CSSTextParser) ICSSValueList(org.eclipse.wst.css.core.internal.provisional.document.ICSSValueList)

Example 2 with ICSSValue

use of org.eclipse.wst.css.core.internal.provisional.document.ICSSValue in project webtools.sourceediting by eclipse.

the class BackgroundPositionYSubStyleAdapter method get.

/**
 */
public String get(ICSS2Properties properties) {
    String str = null;
    Object obj = properties.get(PropCMProperty.getInstanceOf(PropCMProperty.P_BG_POSITION));
    if (obj != null) {
        PropCMProperty propX = PropCMSubProperty.getInstanceOf(PropCMSubProperty.PSUB_BG_POSITION_X);
        PropCMProperty propY = PropCMSubProperty.getInstanceOf(PropCMSubProperty.PSUB_BG_POSITION_Y);
        if (obj instanceof ICSSValueList) {
            ICSSValueList list = (ICSSValueList) obj;
            int index = 1;
            ICSSValue value = (ICSSValue) list.item(0);
            if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
                ICSSPrimitiveValue prim = (ICSSPrimitiveValue) value;
                if (prim.getPrimitiveType() == CSSPrimitiveValue.CSS_IDENT) {
                    // check not top or bottom
                    if (!propX.canHave(prim.getStringValue()) && propY.canHave(prim.getStringValue())) {
                        // case order is vertical -> horizontal
                        index = 0;
                    }
                }
            }
            str = ((ICSSValue) list.item(index)).getCSSValueText();
        } else if (obj instanceof ICSSValue) {
            str = ((ICSSValue) obj).getCSSValueText();
            if (!str.equalsIgnoreCase(IValID.V_BOTTOM) && !str.equalsIgnoreCase(IValID.V_TOP))
                // $NON-NLS-1$
                str = "";
        } else {
            str = obj.toString();
            CSSTextParser parser = new CSSTextParser(CSSTextParser.MODE_DECLARATION_VALUE, str);
            CSSTextToken[] tokens = parser.getTokens();
            tokens = correctMeaningToken(tokens);
            if (tokens.length == 1 && (tokens[0].image.equalsIgnoreCase(IValID.V_BOTTOM) || tokens[0].image.equalsIgnoreCase(IValID.V_TOP)))
                str = tokens[0].image;
            else if (tokens.length > 1)
                str = tokens[1].image;
            else
                // $NON-NLS-1$
                str = "";
        }
    }
    // $NON-NLS-1$
    return (str != null) ? str : "";
}
Also used : PropCMProperty(org.eclipse.wst.css.core.internal.contentmodel.PropCMProperty) ICSSValue(org.eclipse.wst.css.core.internal.provisional.document.ICSSValue) ICSSPrimitiveValue(org.eclipse.wst.css.core.internal.provisional.document.ICSSPrimitiveValue) CSSTextParser(org.eclipse.wst.css.core.internal.parserz.CSSTextParser) ICSSValueList(org.eclipse.wst.css.core.internal.provisional.document.ICSSValueList)

Example 3 with ICSSValue

use of org.eclipse.wst.css.core.internal.provisional.document.ICSSValue in project webtools.sourceediting by eclipse.

the class CSSPropertyContext method applyModified.

/**
 * This function exports modified property/value pairs to 'decl'
 * declaration
 */
public void applyModified(ICSSStyleDeclaration decl) {
    if (decl == null || fModified == null)
        return;
    Iterator it = fModified.iterator();
    while (it.hasNext()) {
        Object key = it.next();
        Object val = fProperties.get(key);
        String value = (val instanceof ICSSValue) ? ((ICSSValue) val).getCSSValueText() : ((val != null) ? val.toString() : null);
        if (value == null || value.length() <= 0)
            decl.removeProperty(key.toString());
        else
            // $NON-NLS-2$//$NON-NLS-1$
            decl.setProperty(key.toString(), value.trim(), (val instanceof ValueData && ((ValueData) val).important) ? "!important" : "");
    }
}
Also used : ICSSValue(org.eclipse.wst.css.core.internal.provisional.document.ICSSValue) Iterator(java.util.Iterator)

Example 4 with ICSSValue

use of org.eclipse.wst.css.core.internal.provisional.document.ICSSValue in project webtools.sourceediting by eclipse.

the class CSSContentOutlineConfiguration method getFilteredNode.

private Object getFilteredNode(Object o) {
    ICSSNode node = null;
    if (o instanceof ICSSNode) {
        node = (ICSSNode) o;
        short nodeType = node.getNodeType();
        if (node instanceof ICSSValue) {
            while (node != null && !(node instanceof ICSSStyleDeclItem)) {
                node = node.getParentNode();
            }
        } else if (nodeType == ICSSNode.STYLEDECLARATION_NODE) {
            node = node.getParentNode();
        } else if (nodeType == ICSSNode.MEDIALIST_NODE) {
            node = node.getParentNode();
        }
    }
    return node;
}
Also used : ICSSValue(org.eclipse.wst.css.core.internal.provisional.document.ICSSValue) ICSSStyleDeclItem(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclItem) ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode)

Example 5 with ICSSValue

use of org.eclipse.wst.css.core.internal.provisional.document.ICSSValue in project webtools.sourceediting by eclipse.

the class CSSQueryContext method applyFull.

/**
 */
public void applyFull(ICSSStyleDeclaration decl) {
    if (decl == null)
        return;
    Enumeration keys = fProperties.keys();
    while (keys.hasMoreElements()) {
        Object key = keys.nextElement();
        Object val = fProperties.get(key);
        if (val instanceof CSSQueryDeclarationData) {
            ICSSStyleDeclItem declItem = ((CSSQueryDeclarationData) val).getDeclItem();
            if (declItem.getLength() <= 0) {
                ICSSStyleDeclItem itemToRemove = decl.getDeclItemNode(key.toString());
                if (itemToRemove != null) {
                    decl.removeDeclItemNode(itemToRemove);
                }
            } else {
                decl.setDeclItemNode(declItem);
            }
        } else {
            String value = (val instanceof ICSSValue) ? ((ICSSValue) val).getCSSValueText() : val.toString();
            if (value == null || value.length() <= 0) {
                ICSSStyleDeclItem itemToRemove = decl.getDeclItemNode(key.toString());
                if (itemToRemove != null) {
                    decl.removeDeclItemNode(itemToRemove);
                }
            } else {
                decl.setProperty(key.toString(), value, null);
            }
        }
    }
}
Also used : Enumeration(java.util.Enumeration) ICSSValue(org.eclipse.wst.css.core.internal.provisional.document.ICSSValue) ICSSStyleDeclItem(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclItem)

Aggregations

ICSSValue (org.eclipse.wst.css.core.internal.provisional.document.ICSSValue)8 Enumeration (java.util.Enumeration)2 PropCMProperty (org.eclipse.wst.css.core.internal.contentmodel.PropCMProperty)2 CSSTextParser (org.eclipse.wst.css.core.internal.parserz.CSSTextParser)2 ICSSNode (org.eclipse.wst.css.core.internal.provisional.document.ICSSNode)2 ICSSPrimitiveValue (org.eclipse.wst.css.core.internal.provisional.document.ICSSPrimitiveValue)2 ICSSStyleDeclItem (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclItem)2 ICSSValueList (org.eclipse.wst.css.core.internal.provisional.document.ICSSValueList)2 Iterator (java.util.Iterator)1 ICSSImportRule (org.eclipse.wst.css.core.internal.provisional.document.ICSSImportRule)1 ICSSModel (org.eclipse.wst.css.core.internal.provisional.document.ICSSModel)1 ICSSSelector (org.eclipse.wst.css.core.internal.provisional.document.ICSSSelector)1 ICSSSelectorList (org.eclipse.wst.css.core.internal.provisional.document.ICSSSelectorList)1 ICSSStyleRule (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleRule)1 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)1 CSSRule (org.w3c.dom.css.CSSRule)1 CSSRuleList (org.w3c.dom.css.CSSRuleList)1 CSSStyleDeclaration (org.w3c.dom.css.CSSStyleDeclaration)1 CSSStyleRule (org.w3c.dom.css.CSSStyleRule)1 CSSStyleSheet (org.w3c.dom.css.CSSStyleSheet)1