Search in sources :

Example 1 with ICSSModelAdapter

use of org.eclipse.wst.css.core.internal.provisional.adapters.ICSSModelAdapter in project webtools.sourceediting by eclipse.

the class CSSFormatUtil method findCSS.

private void findCSS(List cssNodes, IDOMNode node) {
    ICSSModelAdapter adapter;
    adapter = (ICSSModelAdapter) node.getAdapterFor(IStyleSheetAdapter.class);
    if (adapter != null) {
        ICSSModel model = adapter.getModel();
        if (model != null && model.getStyleSheetType() == ICSSModel.EMBEDDED) {
            cssNodes.add(model.getDocument());
        }
    } else {
        adapter = (ICSSModelAdapter) node.getAdapterFor(IStyleDeclarationAdapter.class);
        if (adapter != null) {
            ICSSModel model = adapter.getModel();
            if (model != null && model.getStyleSheetType() == ICSSModel.INLINE) {
                cssNodes.add(model.getDocument());
            }
        }
    }
    for (IDOMNode child = (IDOMNode) node.getFirstChild(); child != null; child = (IDOMNode) child.getNextSibling()) {
        findCSS(cssNodes, child);
    }
}
Also used : ICSSModelAdapter(org.eclipse.wst.css.core.internal.provisional.adapters.ICSSModelAdapter) ICSSModel(org.eclipse.wst.css.core.internal.provisional.document.ICSSModel) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)

Example 2 with ICSSModelAdapter

use of org.eclipse.wst.css.core.internal.provisional.adapters.ICSSModelAdapter in project webtools.sourceediting by eclipse.

the class CSSCompletionProposalComputer method getCSSModel.

/**
 * Returns the CSSmodel for a given XML node.
 *
 * @param element
 * @return IStructuredModel
 */
private static IStructuredModel getCSSModel(IDOMNode element) {
    if (element == null) {
        return null;
    }
    INodeAdapter adapter = StyleAdapterFactory.getInstance().adapt(element);
    if ((adapter == null) || !(adapter instanceof ICSSModelAdapter)) {
        return null;
    }
    ICSSModelAdapter modelAdapter = (ICSSModelAdapter) adapter;
    return modelAdapter.getModel();
}
Also used : INodeAdapter(org.eclipse.wst.sse.core.internal.provisional.INodeAdapter) ICSSModelAdapter(org.eclipse.wst.css.core.internal.provisional.adapters.ICSSModelAdapter)

Example 3 with ICSSModelAdapter

use of org.eclipse.wst.css.core.internal.provisional.adapters.ICSSModelAdapter in project webtools.sourceediting by eclipse.

the class CSSContentAssistProcessor method getCSSModel.

/**
 * Get CSSModel for an indexed node
 *
 * @param indexedNode
 * @return IStructuredModel
 */
// private IStructuredModel getCSSModel(IndexedRegion indexedNode) {
// if (indexedNode == null) return null;
// Node node = (Node)indexedNode;
// INodeNotifier notifier = (INodeNotifier)node.getParentNode();
// if (notifier == null) return null;
// INodeAdapter adapter =
// StyleAdapterFactory.getInstance().adapt(notifier);
// if (adapter == null || !(adapter instanceof CSSModelAdapter)) return
// null;
// CSSModelAdapter modelAdapter = (CSSModelAdapter)adapter;
// return modelAdapter.getModel();
// }
/**
 * Returns the CSSmodel for a given XML node.
 *
 * @param element
 * @return IStructuredModel
 */
private IStructuredModel getCSSModel(IDOMNode element) {
    if (element == null)
        return null;
    INodeAdapter adapter = StyleAdapterFactory.getInstance().adapt(element);
    if ((adapter == null) || !(adapter instanceof ICSSModelAdapter))
        return null;
    ICSSModelAdapter modelAdapter = (ICSSModelAdapter) adapter;
    return modelAdapter.getModel();
}
Also used : INodeAdapter(org.eclipse.wst.sse.core.internal.provisional.INodeAdapter) ICSSModelAdapter(org.eclipse.wst.css.core.internal.provisional.adapters.ICSSModelAdapter)

Example 4 with ICSSModelAdapter

use of org.eclipse.wst.css.core.internal.provisional.adapters.ICSSModelAdapter 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 5 with ICSSModelAdapter

use of org.eclipse.wst.css.core.internal.provisional.adapters.ICSSModelAdapter 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)

Aggregations

ICSSModelAdapter (org.eclipse.wst.css.core.internal.provisional.adapters.ICSSModelAdapter)5 INodeAdapter (org.eclipse.wst.sse.core.internal.provisional.INodeAdapter)4 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)2 IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)2 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)2 Element (org.w3c.dom.Element)2 NodeList (org.w3c.dom.NodeList)2 ICSSModel (org.eclipse.wst.css.core.internal.provisional.document.ICSSModel)1 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)1