Search in sources :

Example 1 with INodeNotifier

use of org.eclipse.wst.sse.core.internal.provisional.INodeNotifier in project jbosstools-hibernate by jbosstools.

the class DOMModelUtil method getAdaptedElements.

public static List getAdaptedElements(Element n, String elementName, INodeAdapterFactory factory) {
    List result = new ArrayList();
    List list = DOMModelUtil.getChildrenByTagName(n, elementName);
    for (int i = 0; i < list.size(); i++) {
        Node item = (Node) list.get(i);
        result.add(factory.adapt((INodeNotifier) item));
    }
    return result;
}
Also used : Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) List(java.util.List) NodeList(org.w3c.dom.NodeList) ArrayList(java.util.ArrayList) INodeNotifier(org.eclipse.wst.sse.core.internal.provisional.INodeNotifier)

Example 2 with INodeNotifier

use of org.eclipse.wst.sse.core.internal.provisional.INodeNotifier in project webtools.sourceediting by eclipse.

the class AbstractCSSSourceFormatter method formatChildren.

/**
 */
protected final void formatChildren(ICSSNode node, IRegion region, StringBuffer source) {
    ICSSNode child = node.getFirstChild();
    int start = region.getOffset();
    int end = region.getOffset() + region.getLength();
    boolean first = true;
    while (child != null) {
        int curEnd = ((IndexedRegion) child).getEndOffset();
        StringBuffer childSource = null;
        boolean toFinish = false;
        if (start < curEnd) {
            int curStart = ((IndexedRegion) child).getStartOffset();
            if (curStart < end) {
                // append child
                CSSSourceFormatter formatter = (CSSSourceFormatter) ((INodeNotifier) child).getAdapterFor(CSSSourceFormatter.class);
                if (formatter == null) {
                    formatter = CSSSourceFormatterFactory.getInstance().getSourceFormatter((INodeNotifier) child);
                }
                if (includes(region, curStart, curEnd))
                    childSource = ((AbstractCSSSourceFormatter) formatter).formatProc(child);
                else
                    childSource = ((AbstractCSSSourceFormatter) formatter).formatProc(child, overlappedRegion(region, curStart, curEnd));
            } else
                toFinish = true;
        }
        // append between children
        if (!first) {
            // change
            curEnd = ((IndexedRegion) child).getStartOffset();
            // start
            if (start < curEnd) {
                int curStart = ((IndexedRegion) child.getPreviousSibling()).getEndOffset();
                if (curStart < end) {
                    // $NON-NLS-1$
                    String toAppend = (childSource != null) ? new String(childSource) : "";
                    if (includes(region, curStart, curEnd))
                        formatBefore(node, child, toAppend, source, null);
                    else
                        formatBefore(node, child, overlappedRegion(region, curStart, curEnd), toAppend, source);
                }
            }
        }
        if (childSource != null) {
            source.append(childSource);
        }
        first = false;
        if (toFinish)
            break;
        child = child.getNextSibling();
    }
}
Also used : ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode) IndexedRegion(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion) INodeNotifier(org.eclipse.wst.sse.core.internal.provisional.INodeNotifier)

Example 3 with INodeNotifier

use of org.eclipse.wst.sse.core.internal.provisional.INodeNotifier 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 4 with INodeNotifier

use of org.eclipse.wst.sse.core.internal.provisional.INodeNotifier in project webtools.sourceediting by eclipse.

the class AbstractStyleSheetAdapter method styleChanged.

/**
 * @param srcModel com.ibm.sed.css.model.interfaces.ICSSModel
 * @param removed com.ibm.sed.css.model.interfaces.ICSSSelector[]
 * @param added com.ibm.sed.css.model.interfaces.ICSSSelector[]
 * @param media java.lang.String
 */
public void styleChanged(ICSSModel srcModel, ICSSSelector[] removed, ICSSSelector[] added, String media) {
    Element element = getElement();
    if (element == null)
        // might released
        return;
    Document doc = element.getOwnerDocument();
    if (doc == null)
        // error
        return;
    // to notify GEF tree
    if (doc instanceof INodeNotifier) {
        Collection adapters = ((INodeNotifier) doc).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).styleChanged(srcModel, removed, added, media);
            }
        }
    }
    if (styleChangedNodes == null) {
        styleChangedNodes = new HashSet();
    }
    try {
        int removedSelNum = removed != null ? removed.length : 0;
        int addedSelNum = added != null ? added.length : 0;
        NodeIterator iter = ((DocumentTraversal) doc).createNodeIterator(doc, NodeFilter.SHOW_ELEMENT, null, true);
        Node node;
        while ((node = iter.nextNode()) != null) {
            if (node.getNodeType() == Node.ELEMENT_NODE) {
                Element elm = (Element) node;
                boolean match = false;
                int i;
                for (i = 0; i < removedSelNum && !match; i++) {
                    match = removed[i].match(elm, null);
                }
                for (i = 0; i < addedSelNum && !match; i++) {
                    match = added[i].match(elm, null);
                }
                if (match) {
                    if (!styleChangedNodes.contains(elm))
                        styleChangedNodes.add(elm);
                // notifyStyleChanged(elm);
                }
            }
        }
    } catch (ClassCastException ex) {
    // Document doesn't implement DocumentTraversal...
    }
}
Also used : NodeIterator(org.w3c.dom.traversal.NodeIterator) INodeAdapter(org.eclipse.wst.sse.core.internal.provisional.INodeAdapter) ICSSStyleListener(org.eclipse.wst.css.core.internal.event.ICSSStyleListener) Element(org.w3c.dom.Element) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode) Node(org.w3c.dom.Node) Document(org.w3c.dom.Document) Iterator(java.util.Iterator) NodeIterator(org.w3c.dom.traversal.NodeIterator) Collection(java.util.Collection) DocumentTraversal(org.w3c.dom.traversal.DocumentTraversal) INodeNotifier(org.eclipse.wst.sse.core.internal.provisional.INodeNotifier) HashSet(java.util.HashSet)

Example 5 with INodeNotifier

use of org.eclipse.wst.sse.core.internal.provisional.INodeNotifier in project webtools.sourceediting by eclipse.

the class LinkElementAdapter method attrReplaced.

/**
 */
private void attrReplaced() {
    this.replaceModel = true;
    Element element = getElement();
    if (element == null)
        // error
        return;
    Document document = element.getOwnerDocument();
    if (document == null)
        // error
        return;
    INodeNotifier notifier = (INodeNotifier) document;
    HTMLDocumentAdapter adapter = (HTMLDocumentAdapter) notifier.getAdapterFor(IStyleSheetListAdapter.class);
    if (adapter == null)
        return;
    adapter.childReplaced();
}
Also used : Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) IStyleSheetListAdapter(org.eclipse.wst.css.core.internal.provisional.adapters.IStyleSheetListAdapter) INodeNotifier(org.eclipse.wst.sse.core.internal.provisional.INodeNotifier)

Aggregations

INodeNotifier (org.eclipse.wst.sse.core.internal.provisional.INodeNotifier)71 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)35 INodeAdapter (org.eclipse.wst.sse.core.internal.provisional.INodeAdapter)31 Node (org.w3c.dom.Node)29 Document (org.w3c.dom.Document)26 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)24 NullInputStream (org.eclipse.wst.sse.core.internal.encoding.util.NullInputStream)18 RegionChangedEvent (org.eclipse.wst.sse.core.internal.provisional.events.RegionChangedEvent)18 StructuredDocumentEvent (org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentEvent)18 ICSSNode (org.eclipse.wst.css.core.internal.provisional.document.ICSSNode)14 Iterator (java.util.Iterator)9 List (java.util.List)8 IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)8 ModelQueryAdapter (org.eclipse.wst.xml.core.internal.ssemodelquery.ModelQueryAdapter)8 ArrayList (java.util.ArrayList)7 Collection (java.util.Collection)7 ICSSModel (org.eclipse.wst.css.core.internal.provisional.document.ICSSModel)7 IndexedRegion (org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)7 Element (org.w3c.dom.Element)7 CSSSourceFormatter (org.eclipse.wst.css.core.internal.formatter.CSSSourceFormatter)6