Search in sources :

Example 6 with CSSRule

use of org.w3c.dom.css.CSSRule in project webtools.sourceediting by eclipse.

the class CSSStyleSheetTest method testInsertRule.

public void testInsertRule() {
    CSSStyleSheet sheet = getStyleSheet();
    assertEquals(0, sheet.insertRule(RULE_H3, 0));
    assertEquals(0, sheet.insertRule(RULE_H1, 0));
    assertEquals(1, sheet.insertRule(RULE_H2, 1));
    CSSRuleList ruleList = sheet.getCssRules();
    CSSRule rule;
    rule = ruleList.item(0);
    assertEquals(RULE_H1, rule.getCssText());
    rule = ruleList.item(1);
    assertEquals(RULE_H2, rule.getCssText());
    rule = ruleList.item(2);
    assertEquals(RULE_H3, rule.getCssText());
}
Also used : CSSRule(org.w3c.dom.css.CSSRule) CSSStyleSheet(org.w3c.dom.css.CSSStyleSheet) CSSRuleList(org.w3c.dom.css.CSSRuleList)

Example 7 with CSSRule

use of org.w3c.dom.css.CSSRule in project webtools.sourceediting by eclipse.

the class CSSStyleSheetTest method testDeleteRule.

public void testDeleteRule() {
    CSSStyleSheet sheet = getStyleSheet();
    assertEquals(0, sheet.insertRule(RULE_H3, 0));
    assertEquals(0, sheet.insertRule(RULE_H1, 0));
    assertEquals(1, sheet.insertRule(RULE_H2, 1));
    CSSRuleList ruleList;
    CSSRule rule;
    sheet.deleteRule(1);
    ruleList = sheet.getCssRules();
    rule = ruleList.item(0);
    assertEquals(RULE_H1, rule.getCssText());
    rule = ruleList.item(1);
    assertEquals(RULE_H3, rule.getCssText());
    sheet.deleteRule(1);
    ruleList = sheet.getCssRules();
    rule = ruleList.item(0);
    assertEquals(RULE_H1, rule.getCssText());
    sheet.deleteRule(0);
    try {
        sheet.deleteRule(0);
    } catch (DOMException e) {
        assertEquals(DOMException.INDEX_SIZE_ERR, e.code);
    }
}
Also used : DOMException(org.w3c.dom.DOMException) CSSRule(org.w3c.dom.css.CSSRule) CSSStyleSheet(org.w3c.dom.css.CSSStyleSheet) CSSRuleList(org.w3c.dom.css.CSSRuleList)

Example 8 with CSSRule

use of org.w3c.dom.css.CSSRule in project webtools.sourceediting by eclipse.

the class StyleSheetTest method testImportFromParentDirectory.

/**
 * Tests for the import of a stylesheet in a parent directory
 * @throws Exception
 */
public void testImportFromParentDirectory() throws Exception {
    String filePath = "/" + PROJECT_NAME + "/WebContent/style/sub.css";
    IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(filePath));
    assertTrue("File doesn't exist: " + filePath, file.exists());
    IStructuredModel model = null;
    try {
        model = StructuredModelManager.getModelManager().getModelForRead(file);
        if (model instanceof ICSSModel) {
            ICSSDocument document = ((ICSSModel) model).getDocument();
            if (document instanceof ICSSStyleSheet) {
                CSSRuleList list = ((ICSSStyleSheet) document).getCssRules(true);
                assertTrue("There should be a total of 1 rule.", list.getLength() == 1);
                CSSRule rule = list.item(0);
                assertTrue("Rule should be a style rule. rule.getType() == " + rule.getType(), rule.getType() == ICSSNode.STYLERULE_NODE);
                assertEquals("Stylesheet reference is different than expected.", ((CSSStyleRule) rule).getSelectorText(), "#content");
            }
        }
    } finally {
        if (model != null)
            model.releaseFromRead();
    }
}
Also used : Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) CSSRule(org.w3c.dom.css.CSSRule) ICSSModel(org.eclipse.wst.css.core.internal.provisional.document.ICSSModel) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) ICSSDocument(org.eclipse.wst.css.core.internal.provisional.document.ICSSDocument) ICSSStyleSheet(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleSheet) CSSRuleList(org.w3c.dom.css.CSSRuleList)

Example 9 with CSSRule

use of org.w3c.dom.css.CSSRule in project webtools.sourceediting by eclipse.

the class StyleSheetTest method testImportCycle.

/**
 * Tests for cycles in imports. If a cycle is encountered, we should not get stuck
 * in a loop or re-import the stylesheet.
 * @throws Exception
 */
public void testImportCycle() throws Exception {
    String filePath = "/" + PROJECT_NAME + "/WebContent/cycle0.css";
    IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(filePath));
    assertTrue("File doesn't exist: " + filePath, file.exists());
    IStructuredModel model = null;
    try {
        model = StructuredModelManager.getModelManager().getModelForRead(file);
        if (model instanceof ICSSModel) {
            ICSSDocument document = ((ICSSModel) model).getDocument();
            if (document instanceof ICSSStyleSheet) {
                CSSRuleList list = ((ICSSStyleSheet) document).getCssRules(true);
                assertTrue("There should be a total of 3 rules supplied stylesheet.", list.getLength() == 3);
                for (int i = 0; i < list.getLength(); i++) {
                    CSSRule rule = list.item(i);
                    assertTrue("Rule should be a style rule. rule.getType() == " + rule.getType(), rule.getType() == ICSSNode.STYLERULE_NODE);
                    // Check that the rules are imported, it would start with the last imported stylesheet's rules and move up
                    assertEquals("Style rules are not equal.", ((CSSStyleRule) rule).getSelectorText(), "#cycle" + (2 - i));
                }
            }
        }
    } finally {
        if (model != null)
            model.releaseFromRead();
    }
}
Also used : Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) CSSRule(org.w3c.dom.css.CSSRule) ICSSModel(org.eclipse.wst.css.core.internal.provisional.document.ICSSModel) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) ICSSDocument(org.eclipse.wst.css.core.internal.provisional.document.ICSSDocument) ICSSStyleSheet(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleSheet) CSSRuleList(org.w3c.dom.css.CSSRuleList)

Example 10 with CSSRule

use of org.w3c.dom.css.CSSRule in project webtools.sourceediting by eclipse.

the class JFaceNodeContentProviderCSS method addElements.

/**
 * @deprecated
 */
protected void addElements(Object element, ArrayList v) {
    ICSSNode node;
    if (element instanceof ICSSModel) {
        ICSSModel model = (ICSSModel) element;
        ICSSDocument doc = model.getDocument();
        node = doc.getFirstChild();
    } else if (element instanceof ICSSNode) {
        node = ((ICSSNode) element).getFirstChild();
    } else
        return;
    while (node != null) {
        if (node instanceof CSSRule) {
            v.add(node);
        }
        node = node.getNextSibling();
    }
}
Also used : CSSRule(org.w3c.dom.css.CSSRule) ICSSModel(org.eclipse.wst.css.core.internal.provisional.document.ICSSModel) ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode) ICSSDocument(org.eclipse.wst.css.core.internal.provisional.document.ICSSDocument)

Aggregations

CSSRule (org.w3c.dom.css.CSSRule)33 CSSRuleList (org.w3c.dom.css.CSSRuleList)29 ICSSModel (org.eclipse.wst.css.core.internal.provisional.document.ICSSModel)21 CSSStyleSheet (org.w3c.dom.css.CSSStyleSheet)20 CSSStyleDeclaration (org.w3c.dom.css.CSSStyleDeclaration)17 CSSValue (org.w3c.dom.css.CSSValue)15 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)14 ICSSStyleSheet (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleSheet)11 ICSSDocument (org.eclipse.wst.css.core.internal.provisional.document.ICSSDocument)10 CSSStyleRule (org.w3c.dom.css.CSSStyleRule)7 CSSPageRule (org.w3c.dom.css.CSSPageRule)6 IFile (org.eclipse.core.resources.IFile)5 Path (org.eclipse.core.runtime.Path)5 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)5 CSSValueList (org.w3c.dom.css.CSSValueList)5 CSSFontFaceRule (org.w3c.dom.css.CSSFontFaceRule)4 ICSSImportRule (org.eclipse.wst.css.core.internal.provisional.document.ICSSImportRule)3 ICSSNode (org.eclipse.wst.css.core.internal.provisional.document.ICSSNode)3 CSSStyleRuleImpl (com.steadystate.css.dom.CSSStyleRuleImpl)2 CSSStyleSheetImpl (com.steadystate.css.dom.CSSStyleSheetImpl)2