Search in sources :

Example 46 with INodeAdapter

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

the class PageDirectiveAdapterImpl method adapt.

/**
 * @see PageDirectiveAdapter#adapt(INodeNotifier, Object)
 */
public INodeAdapter adapt(INodeNotifier notifier, Object type) {
    INodeAdapter result = null;
    // then we can not adapt it.
    if (embeddedTypeHandler != null) {
        if (embeddedFactoryRegistry != null) {
            Iterator iterator = embeddedFactoryRegistry.iterator();
            INodeAdapterFactory factory = null;
            while (iterator.hasNext()) {
                factory = (INodeAdapterFactory) iterator.next();
                if (factory.isFactoryForType(type)) {
                    result = factory.adapt(notifier);
                    break;
                }
            }
        }
    }
    return result;
}
Also used : INodeAdapter(org.eclipse.wst.sse.core.internal.provisional.INodeAdapter) Iterator(java.util.Iterator) INodeAdapterFactory(org.eclipse.wst.sse.core.internal.provisional.INodeAdapterFactory)

Example 47 with INodeAdapter

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

the class DocumentStyleImpl method releaseStyleSheets.

protected void releaseStyleSheets() {
    INodeAdapter adapter = getExistingAdapter(IStyleSheetListAdapter.class);
    if (adapter == null)
        return;
    ((IStyleSheetListAdapter) adapter).releaseStyleSheets();
}
Also used : INodeAdapter(org.eclipse.wst.sse.core.internal.provisional.INodeAdapter) IStyleSheetListAdapter(org.eclipse.wst.css.core.internal.provisional.adapters.IStyleSheetListAdapter)

Example 48 with INodeAdapter

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

the class StyleAdapterFactory method adapt.

/**
 */
public INodeAdapter adapt(INodeNotifier notifier) {
    if (notifier == null)
        return null;
    Node node = (Node) notifier;
    short nodeType = node.getNodeType();
    if (nodeType == Node.DOCUMENT_NODE) {
        INodeAdapter adapter = notifier.getExistingAdapter(IStyleSheetListAdapter.class);
        if (adapter != null)
            return adapter;
        HTMLDocumentAdapter newAdapter = new HTMLDocumentAdapter();
        newAdapter.setDocument((Document) node);
        notifier.addAdapter(newAdapter);
        return newAdapter;
    }
    if (nodeType != Node.ELEMENT_NODE)
        return null;
    Element element = (Element) node;
    String tagName = element.getTagName();
    if (tagName.equalsIgnoreCase(HTML40Namespace.ElementName.STYLE)) {
        if (!isTagAvailable(element.getOwnerDocument(), HTML40Namespace.ElementName.STYLE)) {
            return null;
        }
        // String type = element.getAttribute(HTML40Namespace.ATTR_NAME_TYPE);
        // if (type != null && ! type.equalsIgnoreCase(CSS_CONTENT_TYPE)) {
        // return null;
        // }
        INodeAdapter adapter = notifier.getExistingAdapter(IStyleSheetAdapter.class);
        if (adapter != null)
            return adapter;
        StyleElementAdapter newAdapter = new StyleElementAdapter();
        newAdapter.setElement(element);
        notifier.addAdapter(newAdapter);
        return newAdapter;
    } else if (tagName.equalsIgnoreCase(HTML40Namespace.ElementName.LINK)) {
        if (!isTagAvailable(element.getOwnerDocument(), HTML40Namespace.ElementName.LINK)) {
            return null;
        }
        INodeAdapter adapter = notifier.getExistingAdapter(IStyleSheetAdapter.class);
        if (adapter != null)
            return adapter;
        LinkElementAdapter newAdapter = new LinkElementAdapter();
        newAdapter.setElement(element);
        notifier.addAdapter(newAdapter);
        return newAdapter;
    }
    INodeAdapter adapter = notifier.getExistingAdapter(IStyleDeclarationAdapter.class);
    if (adapter != null)
        return adapter;
    if (!isAttributeAvailable(element, HTML40Namespace.ATTR_NAME_STYLE)) {
        return null;
    }
    StyleAttrAdapter newAdapter = new StyleAttrAdapter();
    newAdapter.setElement(element);
    notifier.addAdapter(newAdapter);
    return newAdapter;
}
Also used : INodeAdapter(org.eclipse.wst.sse.core.internal.provisional.INodeAdapter) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) IStyleSheetAdapter(org.eclipse.wst.css.core.internal.provisional.adapters.IStyleSheetAdapter)

Example 49 with INodeAdapter

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

the class HTMLDocumentTypeAdapterFactory 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 result = null;
    // only adapt IDOMDocument
    if (notifier instanceof IDOMDocument) {
        // if already has an adapter, no need to recreate/initialize.
        // Note: this means if "doctype" for DOM changes,
        // theDocumentTypeAdatper for that DOM
        // should be removed (and released) and it will be re-created next
        // time required.
        DocumentTypeAdapter oldAdapter = (DocumentTypeAdapter) notifier.getExistingAdapter(DocumentTypeAdapter.class);
        if (oldAdapter != null) {
            result = oldAdapter;
        } else {
            // if there already was an adapter
            // if(fAdapter != null)
            // fAdapter.release();
            // note, the factory is included in this case to have a central place
            // to come back to for case preferences.
            result = new HTMLDocumentTypeAdapter((IDOMDocument) notifier, this);
            notifier.addAdapter(result);
        }
    }
    return result;
}
Also used : INodeAdapter(org.eclipse.wst.sse.core.internal.provisional.INodeAdapter) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) DocumentTypeAdapter(org.eclipse.wst.xml.core.internal.document.DocumentTypeAdapter)

Example 50 with INodeAdapter

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

the class EmbeddedCSSFormatter method getCSSModel.

/**
 */
private ICSSModel getCSSModel(IDOMNode text) {
    if (text == null)
        return null;
    INodeNotifier notifier = (INodeNotifier) text.getParentNode();
    if (notifier == null)
        return null;
    INodeAdapter adapter = notifier.getAdapterFor(IStyleSheetAdapter.class);
    if (adapter == null)
        return null;
    if (!(adapter instanceof IStyleSheetAdapter))
        return null;
    IStyleSheetAdapter styleAdapter = (IStyleSheetAdapter) adapter;
    return styleAdapter.getModel();
}
Also used : INodeAdapter(org.eclipse.wst.sse.core.internal.provisional.INodeAdapter) IStyleSheetAdapter(org.eclipse.wst.css.core.internal.provisional.adapters.IStyleSheetAdapter) INodeNotifier(org.eclipse.wst.sse.core.internal.provisional.INodeNotifier)

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