Search in sources :

Example 1 with ImportRuleCollector

use of org.eclipse.wst.css.core.internal.util.ImportRuleCollector in project webtools.sourceediting by eclipse.

the class CSSModelImpl method childReplaced.

void childReplaced(CSSNodeImpl parentNode, CSSNodeImpl newChild, CSSNodeImpl oldChild) {
    if (!fStructuredDocumentUpdate) {
        CSSModelUpdater updater = getUpdater();
        updater.childReplaced(parentNode, newChild, oldChild);
    }
    // always check and send selector event
    ICSSSelector[] removed = null, added = null;
    if (parentNode.getNodeType() == ICSSNode.STYLESHEET_NODE || parentNode.getNodeType() == ICSSNode.MEDIARULE_NODE) {
        // collect old selectors
        SelectorsCollector selTrav = new SelectorsCollector();
        selTrav.apply(oldChild);
        int nSel = selTrav.getSelectors().size();
        if (nSel > 0) {
            removed = new ICSSSelector[nSel];
            for (int i = 0; i < nSel; i++) removed[i] = (ICSSSelector) selTrav.getSelectors().get(i);
        }
        // collect new selectors
        selTrav = new SelectorsCollector();
        selTrav.apply(newChild);
        nSel = selTrav.getSelectors().size();
        if (nSel > 0) {
            added = new ICSSSelector[nSel];
            for (int i = 0; i < nSel; i++) added[i] = (ICSSSelector) selTrav.getSelectors().get(i);
        }
    } else {
        // modification
        ICSSNode rule = parentNode;
        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);
    }
    // close removed import-rule's external style sheets
    {
        ImportRuleCollector trav = new ImportRuleCollector();
        trav.apply(oldChild);
        Iterator it = trav.getRules().iterator();
        while (it.hasNext()) {
            ((CSSImportRuleImpl) it.next()).closeStyleSheet();
        }
    }
    // send events to listener for new import-rules
    if (getStyleListeners() != null && getStyleListeners().size() > 0) {
        ImportedCollector trav = new ImportedCollector();
        trav.apply(newChild);
    }
}
Also used : ImportedCollector(org.eclipse.wst.css.core.internal.util.ImportedCollector) ICSSSelectorList(org.eclipse.wst.css.core.internal.provisional.document.ICSSSelectorList) ImportRuleCollector(org.eclipse.wst.css.core.internal.util.ImportRuleCollector) SelectorsCollector(org.eclipse.wst.css.core.internal.util.SelectorsCollector) Iterator(java.util.Iterator) ICSSSelector(org.eclipse.wst.css.core.internal.provisional.document.ICSSSelector) ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode) ICSSStyleRule(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleRule)

Example 2 with ImportRuleCollector

use of org.eclipse.wst.css.core.internal.util.ImportRuleCollector in project webtools.sourceediting by eclipse.

the class CSSNodeImpl method removeChild.

protected CSSNodeImpl removeChild(CSSNodeImpl oldChild) throws org.w3c.dom.DOMException {
    if (oldChild == null)
        return null;
    if (oldChild.getParentNode() != this)
        return null;
    // close import rules
    ImportRuleCollector trav = new ImportRuleCollector();
    trav.apply(oldChild);
    Iterator it = trav.getRules().iterator();
    while (it.hasNext()) {
        ((CSSImportRuleImpl) it.next()).closeStyleSheet();
    }
    CSSNodeImpl child = oldChild;
    CSSNodeImpl prev = (CSSNodeImpl) child.getPreviousSibling();
    CSSNodeImpl next = (CSSNodeImpl) child.getNextSibling();
    if (prev == null)
        this.fFirstChild = next;
    else
        prev.setNextSibling(next);
    if (next == null)
        this.fLastChild = prev;
    else
        next.setPreviousSibling(prev);
    child.setPreviousSibling(null);
    child.setNextSibling(null);
    child.setParentNode(null);
    notifyChildReplaced(null, child);
    return child;
}
Also used : ImportRuleCollector(org.eclipse.wst.css.core.internal.util.ImportRuleCollector) Iterator(java.util.Iterator)

Example 3 with ImportRuleCollector

use of org.eclipse.wst.css.core.internal.util.ImportRuleCollector in project webtools.sourceediting by eclipse.

the class CSSStyleSheetImpl method getOwnerRules.

/**
 * @return org.w3c.dom.css.CSSRuleList
 */
public org.w3c.dom.css.CSSRuleList getOwnerRules() {
    StyleSheetList list = getParentStyleSheets();
    if (list == null)
        return null;
    CSSRuleListImpl ruleList = new CSSRuleListImpl();
    for (int i = 0; i < list.getLength(); i++) {
        ImportRuleCollector trav = new ImportRuleCollector(this);
        trav.apply((ICSSStyleSheet) list.item(i));
        ruleList.nodes.addAll(trav.getRules());
    }
    return ruleList;
}
Also used : ImportRuleCollector(org.eclipse.wst.css.core.internal.util.ImportRuleCollector) StyleSheetList(org.w3c.dom.stylesheets.StyleSheetList)

Example 4 with ImportRuleCollector

use of org.eclipse.wst.css.core.internal.util.ImportRuleCollector in project webtools.sourceediting by eclipse.

the class CSSModelImpl method closeImported.

/**
 */
private void closeImported() {
    if (!isShared()) {
        // release listeners
        if (getStyleListeners() != null) {
            Vector toRemove = new Vector(getStyleListeners());
            Iterator it = toRemove.iterator();
            while (it.hasNext()) {
                removeStyleListener((ICSSStyleListener) it.next());
            }
        }
        // close import rules
        ImportRuleCollector trav = new ImportRuleCollector();
        trav.apply(getDocument());
        Iterator it2 = trav.getRules().iterator();
        while (it2.hasNext()) {
            ((CSSImportRuleImpl) it2.next()).releaseRule();
        }
    }
}
Also used : ImportRuleCollector(org.eclipse.wst.css.core.internal.util.ImportRuleCollector) Iterator(java.util.Iterator) Vector(java.util.Vector)

Aggregations

ImportRuleCollector (org.eclipse.wst.css.core.internal.util.ImportRuleCollector)4 Iterator (java.util.Iterator)3 Vector (java.util.Vector)1 ICSSNode (org.eclipse.wst.css.core.internal.provisional.document.ICSSNode)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 ImportedCollector (org.eclipse.wst.css.core.internal.util.ImportedCollector)1 SelectorsCollector (org.eclipse.wst.css.core.internal.util.SelectorsCollector)1 StyleSheetList (org.w3c.dom.stylesheets.StyleSheetList)1