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