Search in sources :

Example 26 with INodeAdapter

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

the class TestCSS method testTypeFooBarStyleElementAdapter.

public void testTypeFooBarStyleElementAdapter() {
    IDOMModel model = FileUtil.createHTMLModel();
    try {
        IStructuredDocument structuredDocument = model.getStructuredDocument();
        structuredDocument.set(MARKUP);
        IDOMDocument doc = model.getDocument();
        // get head tag
        NodeList list = doc.getElementsByTagName(HTML40Namespace.ElementName.HEAD);
        Element head = (Element) list.item(0);
        // create and append style element
        Element ele = doc.createElement(HTML40Namespace.ElementName.STYLE);
        ele.setAttribute(HTML40Namespace.ATTR_NAME_TYPE, "foo/bar");
        head.appendChild(ele);
        INodeAdapter adapter = StyleAdapterFactory.getInstance().adapt((IDOMNode) ele);
        assertNotNull("No adapter on " + ele, adapter);
        assertTrue("Adapter is not an ICSSModelAdapter", adapter instanceof ICSSModelAdapter);
        ICSSModelAdapter modelAdapter = (ICSSModelAdapter) adapter;
        assertNull("There should be no CSS model for the node", modelAdapter.getModel());
    } finally {
        if (model != null)
            model.releaseFromEdit();
    }
}
Also used : INodeAdapter(org.eclipse.wst.sse.core.internal.provisional.INodeAdapter) ICSSModelAdapter(org.eclipse.wst.css.core.internal.provisional.adapters.ICSSModelAdapter) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)

Example 27 with INodeAdapter

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

the class TestCSS method testStyleElementAdapter.

public void testStyleElementAdapter() {
    IDOMModel model = FileUtil.createHTMLModel();
    try {
        IStructuredDocument structuredDocument = model.getStructuredDocument();
        structuredDocument.set(MARKUP);
        IDOMDocument doc = model.getDocument();
        // get head tag
        NodeList list = doc.getElementsByTagName(HTML40Namespace.ElementName.HEAD);
        Element head = (Element) list.item(0);
        // create and append style element
        Element ele = doc.createElement(HTML40Namespace.ElementName.STYLE);
        ele.setAttribute(HTML40Namespace.ATTR_NAME_TYPE, "text/css");
        head.appendChild(ele);
        INodeAdapter adapter = StyleAdapterFactory.getInstance().adapt((IDOMNode) ele);
        assertNotNull("No adapter on " + ele, adapter);
        assertTrue("Adapter is not an ICSSModelAdapter", adapter instanceof ICSSModelAdapter);
        ICSSModelAdapter modelAdapter = (ICSSModelAdapter) adapter;
        assertNotNull("There should be a CSS model for the node", modelAdapter.getModel());
    } finally {
        if (model != null)
            model.releaseFromEdit();
    }
}
Also used : INodeAdapter(org.eclipse.wst.sse.core.internal.provisional.INodeAdapter) ICSSModelAdapter(org.eclipse.wst.css.core.internal.provisional.adapters.ICSSModelAdapter) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)

Example 28 with INodeAdapter

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

the class EMF2DOMSSEAdapter method primGetExistingAdapter.

protected EMF2DOMAdapter primGetExistingAdapter(Node aNode, Translator childMap) {
    INodeNotifier sseNode = (INodeNotifier) aNode;
    Collection adapters = sseNode.getAdapters();
    for (Iterator iterator = adapters.iterator(); iterator.hasNext(); ) {
        INodeAdapter adapter = (INodeAdapter) iterator.next();
        // First Check if it's an EMF2DOMAdapter
        if (adapter != null && adapter.isAdapterForType(EMF2DOMAdapter.ADAPTER_CLASS)) {
            // Cast to EMF2DOMAdapter
            EMF2DOMSSEAdapter e2DAdapter = (EMF2DOMSSEAdapter) adapter;
            Object adapterTarget = e2DAdapter.getTarget();
            // Handle the cases where either adapter's target is null
            if ((getTarget() == null) || (adapterTarget == null))
                if (resourceClass != null && resourceClass.equals(e2DAdapter.getResourceClass()))
                    return e2DAdapter;
                else
                    continue;
            // Check if target is an EMF resource
            if (getTarget() instanceof Resource) {
                /*
					 * Now check if it's the right one (Multiple resources
					 * could be attached)
					 */
                if (adapterTarget != null && adapterTarget == getTarget()) {
                    return e2DAdapter;
                }
            } else {
                // Check if targets are EObjects with the same resources
                EObject myTarget = (EObject) getTarget();
                /*
					 * Now check if it's the right one (Multiple resources could
					 * be attached)
					 */
                if (adapterTarget != null && ((EObject) adapterTarget).eResource() == myTarget.eResource()) {
                    return e2DAdapter;
                }
            }
            if (adapterTarget instanceof EObject) {
                if (((EObject) e2DAdapter.getTarget()).eResource() == null && e2DAdapter.fTranslator == childMap) {
                    return e2DAdapter;
                }
            }
        }
    }
    return null;
}
Also used : INodeAdapter(org.eclipse.wst.sse.core.internal.provisional.INodeAdapter) EObject(org.eclipse.emf.ecore.EObject) Iterator(java.util.Iterator) TranslatorResource(org.eclipse.wst.common.internal.emf.resource.TranslatorResource) Resource(org.eclipse.emf.ecore.resource.Resource) Collection(java.util.Collection) EObject(org.eclipse.emf.ecore.EObject) INodeNotifier(org.eclipse.wst.sse.core.internal.provisional.INodeNotifier)

Example 29 with INodeAdapter

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

the class EMF2DOMSSEAdapter method primGetExistingAdapter.

protected EMF2DOMAdapter primGetExistingAdapter(Node aNode) {
    INodeNotifier sseNode = (INodeNotifier) aNode;
    Collection adapters = sseNode.getAdapters();
    for (Iterator iterator = adapters.iterator(); iterator.hasNext(); ) {
        INodeAdapter adapter = (INodeAdapter) iterator.next();
        // First Check if it's an EMF2DOMAdapter
        if (adapter != null && adapter.isAdapterForType(EMF2DOMAdapter.ADAPTER_CLASS)) {
            // Cast to EMF2DOMAdapter
            EMF2DOMSSEAdapter e2DAdapter = (EMF2DOMSSEAdapter) adapter;
            Object adapterTarget = e2DAdapter.getTarget();
            // Handle the cases where either adapter's target is null
            if ((getTarget() == null) || (adapterTarget == null))
                if (resourceClass != null && resourceClass.equals(e2DAdapter.getResourceClass()))
                    return e2DAdapter;
                else
                    continue;
            // Check if target is an EMF resource
            if (getTarget() instanceof Resource) {
                /*
					 * Now check if it's the right one (Multiple resources
					 * could be attached)
					 */
                if (adapterTarget != null && adapterTarget == getTarget()) {
                    return e2DAdapter;
                }
            } else {
                // Check if targets are EObjects with the same resources
                EObject myTarget = (EObject) getTarget();
                /*
					 * Now check if it's the right one (Multiple resources could
					 * be attached)
					 */
                if (adapterTarget != null && ((EObject) adapterTarget).eResource() == myTarget.eResource()) {
                    return e2DAdapter;
                }
            }
            if (adapterTarget instanceof EObject) {
                if (((EObject) e2DAdapter.getTarget()).eResource() == null) {
                    return e2DAdapter;
                }
            }
        }
    }
    return null;
}
Also used : INodeAdapter(org.eclipse.wst.sse.core.internal.provisional.INodeAdapter) EObject(org.eclipse.emf.ecore.EObject) Iterator(java.util.Iterator) TranslatorResource(org.eclipse.wst.common.internal.emf.resource.TranslatorResource) Resource(org.eclipse.emf.ecore.resource.Resource) Collection(java.util.Collection) EObject(org.eclipse.emf.ecore.EObject) INodeNotifier(org.eclipse.wst.sse.core.internal.provisional.INodeNotifier)

Example 30 with INodeAdapter

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

the class EMF2DOMSSERenderer method getExistingDOMAdapter.

public EMF2DOMAdapter getExistingDOMAdapter(Node node) {
    // IDOMNode xNode = (IDOMNode) node;
    // return (EMF2DOMSSEAdapter) xNode.getAdapterFor(EMF2DOMAdapter.ADAPTER_CLASS);
    INodeNotifier sseNode = (INodeNotifier) node;
    Collection adapters = sseNode.getAdapters();
    for (Iterator iterator = adapters.iterator(); iterator.hasNext(); ) {
        INodeAdapter adapter = (INodeAdapter) iterator.next();
        // First Check if it's an EMF2DOMAdapter
        if (adapter != null && adapter.isAdapterForType(EMF2DOMAdapter.ADAPTER_CLASS)) {
            // Cast to EMF2DOMSSEAdapter
            EMF2DOMSSEAdapter e2DAdapter = (EMF2DOMSSEAdapter) adapter;
            // Use the resourceClass to make sure the resource type is identical
            if (getResource() == null || e2DAdapter.getTarget() == null)
                if (resourceClass.equals(e2DAdapter.getResourceClass()))
                    return e2DAdapter;
                else
                    continue;
            // First check if targets are resources
            if (e2DAdapter.getTarget() instanceof Resource) {
                /*
					 * Now check if it's the right one (Multiple resources
					 * could be attached)
					 */
                if (e2DAdapter.getTarget() == getResource()) {
                    return e2DAdapter;
                }
            } else {
                // Check if targets are EObjects with the same resources
                TranslatorResource myTarget = getResource();
                EObject adapterTarget = (EObject) e2DAdapter.getTarget();
                /*
					 * Now check if it's the right one (Multiple resources could
					 * be attached)
					 */
                if (adapterTarget.eResource() == myTarget || adapterTarget.eResource() == null) {
                    return e2DAdapter;
                }
            }
        }
    }
    return null;
}
Also used : INodeAdapter(org.eclipse.wst.sse.core.internal.provisional.INodeAdapter) EObject(org.eclipse.emf.ecore.EObject) Iterator(java.util.Iterator) TranslatorResource(org.eclipse.wst.common.internal.emf.resource.TranslatorResource) Resource(org.eclipse.emf.ecore.resource.Resource) TranslatorResource(org.eclipse.wst.common.internal.emf.resource.TranslatorResource) Collection(java.util.Collection) 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