Search in sources :

Example 1 with SelectorsCollector

use of org.eclipse.wst.css.core.internal.util.SelectorsCollector 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 SelectorsCollector

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

the class CSSStyleNotifyAdapter method addStyleListener.

/**
 */
public void addStyleListener(ICSSStyleListener listener) {
    if (listener == null)
        return;
    if (listeners == null)
        listeners = new Vector();
    if (!listeners.contains(listener)) {
        // send new selectors event to listener
        ImportedCollector trav = new ImportedCollector();
        trav.apply(model.getDocument());
        Iterator it = trav.getExternals().iterator();
        while (it.hasNext()) {
            ICSSStyleSheet sheet = (ICSSStyleSheet) it.next();
            // collect selectors
            SelectorsCollector selTrav = new SelectorsCollector();
            selTrav.apply(sheet);
            int nSel = selTrav.getSelectors().size();
            ICSSSelector[] added = new ICSSSelector[nSel];
            for (int i = 0; i < nSel; i++) added[i] = (ICSSSelector) selTrav.getSelectors().get(i);
            // fire event
            CSSStyleEventDeliverer deliverer = new CSSStyleEventDeliverer();
            deliverer.fireTo(listener, sheet.getModel(), null, added, null);
        }
        // add listener
        listeners.add(listener);
    }
}
Also used : ImportedCollector(org.eclipse.wst.css.core.internal.util.ImportedCollector) Iterator(java.util.Iterator) SelectorsCollector(org.eclipse.wst.css.core.internal.util.SelectorsCollector) ICSSSelector(org.eclipse.wst.css.core.internal.provisional.document.ICSSSelector) ICSSStyleSheet(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleSheet) Vector(java.util.Vector)

Example 3 with SelectorsCollector

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

the class CSSStyleNotifyAdapter method removeStyleListener.

/**
 */
public void removeStyleListener(ICSSStyleListener listener) {
    if (listener == null)
        return;
    if (listeners.contains(listener)) {
        listeners.remove(listener);
        // send old selectors event to listener
        ImportedCollector trav = new ImportedCollector();
        trav.apply(model.getDocument());
        Iterator it = trav.getExternals().iterator();
        while (it.hasNext()) {
            ICSSStyleSheet sheet = (ICSSStyleSheet) it.next();
            // collect selectors
            SelectorsCollector selTrav = new SelectorsCollector();
            selTrav.apply(sheet);
            int nSel = selTrav.getSelectors().size();
            ICSSSelector[] removed = new ICSSSelector[nSel];
            for (int i = 0; i < nSel; i++) removed[i] = (ICSSSelector) selTrav.getSelectors().get(i);
            // fire event
            CSSStyleEventDeliverer deliverer = new CSSStyleEventDeliverer();
            deliverer.fireTo(listener, sheet.getModel(), removed, null, null);
        }
    }
}
Also used : ImportedCollector(org.eclipse.wst.css.core.internal.util.ImportedCollector) Iterator(java.util.Iterator) SelectorsCollector(org.eclipse.wst.css.core.internal.util.SelectorsCollector) ICSSSelector(org.eclipse.wst.css.core.internal.provisional.document.ICSSSelector) ICSSStyleSheet(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleSheet)

Aggregations

Iterator (java.util.Iterator)3 ICSSSelector (org.eclipse.wst.css.core.internal.provisional.document.ICSSSelector)3 ImportedCollector (org.eclipse.wst.css.core.internal.util.ImportedCollector)3 SelectorsCollector (org.eclipse.wst.css.core.internal.util.SelectorsCollector)3 ICSSStyleSheet (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleSheet)2 Vector (java.util.Vector)1 ICSSNode (org.eclipse.wst.css.core.internal.provisional.document.ICSSNode)1 ICSSSelectorList (org.eclipse.wst.css.core.internal.provisional.document.ICSSSelectorList)1 ICSSStyleRule (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleRule)1 ImportRuleCollector (org.eclipse.wst.css.core.internal.util.ImportRuleCollector)1