Search in sources :

Example 6 with ICSSValue

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

the class CSSModelImpl method valueChanged.

void valueChanged(CSSNodeImpl node, String oldValue) {
    if (!fStructuredDocumentUpdate) {
        CSSModelUpdater updater = getUpdater();
        updater.valueChanged(node, oldValue);
    }
    ICSSSelector[] removed = null, added = null;
    if (node != null) {
        if (node.getNodeType() == ICSSNode.ATTR_NODE && ((CSSAttrImpl) node).getName().equals(ICSSStyleRule.SELECTOR)) {
            CSSAttrImpl attr = (CSSAttrImpl) node;
            // collect changed selector
            ICSSSelectorList list = new CSSSelectorListImpl(attr.getValue());
            added = new ICSSSelector[list.getLength()];
            for (int i = 0; i < list.getLength(); i++) added[i] = list.getSelector(i);
            // get old value
            list = new CSSSelectorListImpl(oldValue);
            removed = new ICSSSelector[list.getLength()];
            for (int i = 0; i < list.getLength(); i++) removed[i] = list.getSelector(i);
        } else if (node instanceof ICSSValue) {
            ICSSNode rule = node;
            while (rule != null) {
                if (rule instanceof ICSSStyleRule)
                    break;
                rule = rule.getParentNode();
            }
            if (rule != null) {
                ICSSSelectorList list = ((ICSSStyleRule) rule).getSelectors();
                added = new ICSSSelector[list.getLength()];
                for (int i = 0; i < list.getLength(); i++) added[i] = list.getSelector(i);
            }
        }
    }
    if (removed != null || added != null || getDocument().getNodeType() == ICSSNode.STYLEDECLARATION_NODE) {
        // send selector changed event
        getStyleNotifier().fire(removed, added, null);
    }
    // for href attribute
    if (getStyleListeners() != null && getStyleListeners().size() > 0) {
        if (node != null && node.getNodeType() == ICSSNode.ATTR_NODE && ((CSSAttrImpl) node).getName().equals(ICSSImportRule.HREF)) {
            ((ICSSImportRule) ((ICSSAttr) node).getOwnerCSSNode()).getStyleSheet();
        }
    }
}
Also used : ICSSValue(org.eclipse.wst.css.core.internal.provisional.document.ICSSValue) ICSSSelectorList(org.eclipse.wst.css.core.internal.provisional.document.ICSSSelectorList) ICSSSelector(org.eclipse.wst.css.core.internal.provisional.document.ICSSSelector) ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode) ICSSImportRule(org.eclipse.wst.css.core.internal.provisional.document.ICSSImportRule) ICSSStyleRule(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleRule)

Example 7 with ICSSValue

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

the class CSSPropertyContext method applyFull.

/**
 * This function exports all property/value pairs to 'decl' declaration
 */
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);
        String value = (val instanceof ICSSValue) ? ((ICSSValue) val).getCSSValueText() : val.toString();
        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 : Enumeration(java.util.Enumeration) ICSSValue(org.eclipse.wst.css.core.internal.provisional.document.ICSSValue)

Example 8 with ICSSValue

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

the class CSSFontFamilyTest method testValueModification.

public void testValueModification() throws IOException {
    ICSSModel model = getModel();
    IStructuredDocument structuredDocument = model.getStructuredDocument();
    structuredDocument.set(FileUtil.createString("src/org/eclipse/wst/css/core/tests/testfiles", "CSSFontFamilyTest.css"));
    CSSStyleSheet sheet = (CSSStyleSheet) model.getDocument();
    CSSRuleList rules = sheet.getCssRules();
    assertEquals(4, rules.getLength());
    // Rule 1: No whitespace
    CSSRule rule;
    CSSStyleDeclaration declaration;
    CSSValue value;
    // Rule 1: No whitespace
    rule = rules.item(0);
    assertEquals(CSSRule.STYLE_RULE, rule.getType());
    assertTrue(rule instanceof CSSStyleRule);
    declaration = ((CSSStyleRule) rule).getStyle();
    value = declaration.getPropertyCSSValue(FONT_FAMILY);
    checkPrimitiveString(value, new PrimitiveString(CSSPrimitiveValue.CSS_IDENT, "Courier"));
    declaration.setProperty(FONT_FAMILY, "\"Times New Roman\", Times, serif", "");
    value = declaration.getPropertyCSSValue(FONT_FAMILY);
    assertTrue(value instanceof ICSSValue);
    assertEquals("\"Times New Roman\", Times, serif", ((ICSSValue) value).getCSSValueText());
    declaration.setProperty(FONT_FAMILY, "\"Times New Roman\", Times", "");
    value = declaration.getPropertyCSSValue(FONT_FAMILY);
    assertTrue(value instanceof ICSSValue);
    assertEquals("\"Times New Roman\", Times", ((ICSSValue) value).getCSSValueText());
}
Also used : ICSSValue(org.eclipse.wst.css.core.internal.provisional.document.ICSSValue) CSSValue(org.w3c.dom.css.CSSValue) CSSRule(org.w3c.dom.css.CSSRule) ICSSValue(org.eclipse.wst.css.core.internal.provisional.document.ICSSValue) ICSSModel(org.eclipse.wst.css.core.internal.provisional.document.ICSSModel) CSSStyleRule(org.w3c.dom.css.CSSStyleRule) CSSStyleSheet(org.w3c.dom.css.CSSStyleSheet) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) CSSStyleDeclaration(org.w3c.dom.css.CSSStyleDeclaration) CSSRuleList(org.w3c.dom.css.CSSRuleList)

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