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);
}
}
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;
}
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;
}
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();
}
}
}
Aggregations