Search in sources :

Example 1 with ImportedCollector

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

the class AbstractStyleSheetAdapter method styleUpdate.

/**
 * @param srcModel com.ibm.sed.css.model.interfaces.ICSSModel
 */
public void styleUpdate(ICSSModel srcModel) {
    IDOMNode node = (IDOMNode) getElement();
    if (node == null)
        return;
    IDOMModel model = node.getModel();
    if (model == null)
        return;
    XMLModelNotifier notifier = model.getModelNotifier();
    if (notifier == null)
        return;
    // before updating, all sub-models should be loaded!
    DocumentStyle document = (DocumentStyle) model.getDocument();
    StyleSheetList styles = document.getStyleSheets();
    if (styles != null) {
        int n = styles.getLength();
        ImportedCollector trav = new ImportedCollector();
        for (int i = 0; i < n; i++) {
            org.w3c.dom.stylesheets.StyleSheet sheet = styles.item(i);
            if (sheet instanceof ICSSNode)
                trav.apply((ICSSNode) sheet);
        }
    }
    // flash style changed events
    if (styleChangedNodes != null) {
        Object[] elements = styleChangedNodes.toArray();
        for (int i = 0; elements != null && i < elements.length; i++) notifyStyleChanged((Element) elements[i]);
        styleChangedNodes.clear();
    }
    // to notify GEF tree
    if (document instanceof INodeNotifier) {
        Collection adapters = ((INodeNotifier) document).getAdapters();
        if (adapters == null)
            return;
        Iterator it = adapters.iterator();
        if (it == null)
            return;
        while (it.hasNext()) {
            INodeAdapter adapter = (INodeAdapter) it.next();
            if (adapter instanceof ICSSStyleListener) {
                ((ICSSStyleListener) adapter).styleUpdate(srcModel);
            }
        }
    }
    notifier.propertyChanged(node);
}
Also used : INodeAdapter(org.eclipse.wst.sse.core.internal.provisional.INodeAdapter) ImportedCollector(org.eclipse.wst.css.core.internal.util.ImportedCollector) ICSSStyleListener(org.eclipse.wst.css.core.internal.event.ICSSStyleListener) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) Element(org.w3c.dom.Element) XMLModelNotifier(org.eclipse.wst.xml.core.internal.document.XMLModelNotifier) ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode) DocumentStyle(org.w3c.dom.stylesheets.DocumentStyle) StyleSheet(org.w3c.dom.stylesheets.StyleSheet) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) Iterator(java.util.Iterator) NodeIterator(org.w3c.dom.traversal.NodeIterator) Collection(java.util.Collection) INodeNotifier(org.eclipse.wst.sse.core.internal.provisional.INodeNotifier) StyleSheetList(org.w3c.dom.stylesheets.StyleSheetList)

Example 2 with ImportedCollector

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

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

use of org.eclipse.wst.css.core.internal.util.ImportedCollector 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)4 ImportedCollector (org.eclipse.wst.css.core.internal.util.ImportedCollector)4 ICSSSelector (org.eclipse.wst.css.core.internal.provisional.document.ICSSSelector)3 SelectorsCollector (org.eclipse.wst.css.core.internal.util.SelectorsCollector)3 ICSSNode (org.eclipse.wst.css.core.internal.provisional.document.ICSSNode)2 ICSSStyleSheet (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleSheet)2 Collection (java.util.Collection)1 Vector (java.util.Vector)1 ICSSStyleListener (org.eclipse.wst.css.core.internal.event.ICSSStyleListener)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 INodeAdapter (org.eclipse.wst.sse.core.internal.provisional.INodeAdapter)1 INodeNotifier (org.eclipse.wst.sse.core.internal.provisional.INodeNotifier)1 XMLModelNotifier (org.eclipse.wst.xml.core.internal.document.XMLModelNotifier)1 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)1 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)1 Element (org.w3c.dom.Element)1 DocumentStyle (org.w3c.dom.stylesheets.DocumentStyle)1 StyleSheet (org.w3c.dom.stylesheets.StyleSheet)1