Search in sources :

Example 6 with INodeAdapter

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

the class AbstractCSSModelAdapter method notifyStyleChanged.

/**
 */
protected void notifyStyleChanged(Element target) {
    INodeNotifier notifier = (INodeNotifier) target;
    if (notifier == null)
        return;
    Collection adapters = notifier.getAdapters();
    if (adapters == null)
        return;
    Iterator it = adapters.iterator();
    if (it == null)
        return;
    while (it.hasNext()) {
        INodeAdapter adapter = (INodeAdapter) it.next();
        if (adapter instanceof StyleListener) {
            StyleListener listener = (StyleListener) adapter;
            listener.styleChanged();
        }
    }
}
Also used : INodeAdapter(org.eclipse.wst.sse.core.internal.provisional.INodeAdapter) Iterator(java.util.Iterator) Collection(java.util.Collection) INodeNotifier(org.eclipse.wst.sse.core.internal.provisional.INodeNotifier)

Example 7 with INodeAdapter

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

the class HTMLDocumentAdapter method notifyStyleSheetsChanged.

/**
 */
private void notifyStyleSheetsChanged(Document target) {
    INodeNotifier notifier = (INodeNotifier) target;
    if (notifier == null)
        return;
    Collection adapters = notifier.getAdapters();
    if (adapters == null)
        return;
    Iterator it = adapters.iterator();
    if (it == null)
        return;
    while (it.hasNext()) {
        INodeAdapter adapter = (INodeAdapter) it.next();
        if (adapter instanceof StyleListener) {
            StyleListener listener = (StyleListener) adapter;
            listener.styleChanged();
        }
    }
}
Also used : INodeAdapter(org.eclipse.wst.sse.core.internal.provisional.INodeAdapter) Iterator(java.util.Iterator) Collection(java.util.Collection) INodeNotifier(org.eclipse.wst.sse.core.internal.provisional.INodeNotifier)

Example 8 with INodeAdapter

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

the class HTMLDocumentAdapter method addStyleSheet.

/**
 */
private void addStyleSheet(Element node) {
    IDOMElement element = (IDOMElement) node;
    String tagName = element.getTagName();
    if (tagName == null)
        return;
    boolean isContainer = false;
    if (tagName.equalsIgnoreCase(HTML40Namespace.ElementName.HTML) || tagName.equalsIgnoreCase(HTML40Namespace.ElementName.HEAD) || tagName.equalsIgnoreCase(HTML40Namespace.ElementName.NOSCRIPT) || tagName.equalsIgnoreCase(HTML40Namespace.ElementName.BASE) || tagName.equalsIgnoreCase(JSP11Namespace.ElementName.ROOT) || (!element.isGlobalTag() && element.isContainer())) {
        isContainer = true;
    } else if (element.isCommentTag()) {
        Node parent = element.getParentNode();
        if (parent == element.getOwnerDocument()) {
            // This condition is too severe, actually do not work for JSF template.
            // But above (! globalTag() && isContainer()) cover JSF template + tpl template
            isContainer = true;
        } else if (parent.getNodeType() == Node.ELEMENT_NODE) {
            tagName = ((Element) parent).getTagName();
            if (tagName != null && tagName.equalsIgnoreCase(HTML40Namespace.ElementName.HEAD)) {
                isContainer = true;
            }
        }
    } else {
        String localName = element.getLocalName();
        if (localName != null && localName.equalsIgnoreCase(HTML40Namespace.ElementName.HTML)) {
            // taglib html tag
            isContainer = true;
        } else {
            INodeNotifier notifier = element;
            INodeAdapter adapter = notifier.getAdapterFor(IStyleSheetAdapter.class);
            if (adapter != null && adapter instanceof IStyleSheetAdapter) {
                this.styleAdapters.addElement(adapter);
            }
        }
    }
    if (isContainer) {
        INodeNotifier notifier = element;
        if (notifier.getExistingAdapter(IStyleSheetListAdapter.class) == null) {
            notifier.addAdapter(this);
        }
        for (Node child = element.getFirstChild(); child != null; child = child.getNextSibling()) {
            if (child.getNodeType() != Node.ELEMENT_NODE)
                continue;
            addStyleSheet((Element) child);
        }
    }
}
Also used : INodeAdapter(org.eclipse.wst.sse.core.internal.provisional.INodeAdapter) ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode) Node(org.w3c.dom.Node) IStyleSheetListAdapter(org.eclipse.wst.css.core.internal.provisional.adapters.IStyleSheetListAdapter) IStyleSheetAdapter(org.eclipse.wst.css.core.internal.provisional.adapters.IStyleSheetAdapter) IDOMElement(org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement) INodeNotifier(org.eclipse.wst.sse.core.internal.provisional.INodeNotifier)

Example 9 with INodeAdapter

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

the class HTMLStyleSelectorAdapterFactory method adapt.

/**
 * Method that returns the adapter associated with the given object.
 * It may be a singleton or not ... depending on the needs of the INodeAdapter  ...
 * but in general it is recommended for an adapter to be stateless,
 * so the efficiencies of a singleton can be gained.
 *
 * The implementation of this method should call addAdapter on the adapted
 * object with the correct instance of the adapter.
 */
public INodeAdapter adapt(INodeNotifier notifier) {
    INodeAdapter adapter = notifier.getExistingAdapter(IStyleSelectorAdapter.class);
    if (adapter != null)
        return adapter;
    adapter = HTMLStyleSelectorAdapter.getInstance();
    notifier.addAdapter(adapter);
    return adapter;
}
Also used : INodeAdapter(org.eclipse.wst.sse.core.internal.provisional.INodeAdapter)

Example 10 with INodeAdapter

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

the class HTMLModelParserAdapterFactory method adapt.

/**
 * Method that returns the adapter associated with the given object. It
 * may be a singleton or not ... depending on the needs of the
 * INodeAdapter ... but in general it is recommended for an adapter to be
 * stateless, so the efficiencies of a singleton can be gained.
 *
 * The implementation of this method should call addAdapter on the adapted
 * object with the correct instance of the adapter.
 */
public INodeAdapter adapt(INodeNotifier notifier) {
    INodeAdapter adapter = null;
    if (notifier != null) {
        if (notifier instanceof IDOMDocument) {
            adapter = notifier.getExistingAdapter(ModelParserAdapter.class);
            if (adapter == null) {
                adapter = new HTMLModelParserAdapter();
                notifier.addAdapter(adapter);
            }
        }
    }
    return adapter;
}
Also used : ModelParserAdapter(org.eclipse.wst.xml.core.internal.document.ModelParserAdapter) INodeAdapter(org.eclipse.wst.sse.core.internal.provisional.INodeAdapter) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)

Aggregations

INodeAdapter (org.eclipse.wst.sse.core.internal.provisional.INodeAdapter)51 INodeNotifier (org.eclipse.wst.sse.core.internal.provisional.INodeNotifier)31 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)25 Node (org.w3c.dom.Node)22 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)20 Document (org.w3c.dom.Document)19 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 Iterator (java.util.Iterator)10 Collection (java.util.Collection)7 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)7 Element (org.w3c.dom.Element)5 List (java.util.List)4 ICSSStyleListener (org.eclipse.wst.css.core.internal.event.ICSSStyleListener)4 IStyleSheetAdapter (org.eclipse.wst.css.core.internal.provisional.adapters.IStyleSheetAdapter)4 IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)4 EObject (org.eclipse.emf.ecore.EObject)3 Resource (org.eclipse.emf.ecore.resource.Resource)3 ISelection (org.eclipse.jface.viewers.ISelection)3