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