Search in sources :

Example 36 with INodeNotifier

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

the class ModelQueryUtil method getModelQueryAdapter.

public static ModelQueryAdapter getModelQueryAdapter(Document node) {
    ModelQueryAdapter result = null;
    if (node instanceof INodeNotifier) {
        INodeNotifier notifier = (INodeNotifier) node;
        result = (ModelQueryAdapter) notifier.getAdapterFor(ModelQueryAdapter.class);
    }
    return result;
}
Also used : ModelQueryAdapter(org.eclipse.wst.xml.core.internal.ssemodelquery.ModelQueryAdapter) INodeNotifier(org.eclipse.wst.sse.core.internal.provisional.INodeNotifier)

Example 37 with INodeNotifier

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

the class CSSNodeAdapter method getChildren.

/**
 * Returns an enumeration containing all child nodes of the given element,
 * which represents a node in a tree. The difference to
 * <code>IStructuredContentProvider.getElements(Object)</code> is as
 * follows: <code>getElements</code> is called to obtain the tree
 * viewer's root elements. Method <code>getChildren</code> is used to
 * obtain the children of a given node in the tree, which can can be a
 * root node, too.
 */
public Object[] getChildren(Object object) {
    if (object instanceof ICSSNode) {
        ICSSNode node = (ICSSNode) object;
        short nodeType = node.getNodeType();
        if (nodeType == ICSSNode.STYLERULE_NODE || nodeType == ICSSNode.PAGERULE_NODE || nodeType == ICSSNode.FONTFACERULE_NODE) {
            for (node = node.getFirstChild(); node != null && !(node instanceof ICSSStyleDeclaration); node.getNextSibling()) {
            // nop
            }
        }
        List children = new ArrayList();
        ICSSNode child = (node != null) ? node.getFirstChild() : null;
        while (child != null) {
            if (!(child instanceof ICSSPrimitiveValue) && !(child instanceof MediaList)) {
                children.add(child);
            }
            /*
				 * Required to correctly connect the refreshing behavior to
				 * the tree
				 */
            if (child instanceof INodeNotifier) {
                ((INodeNotifier) child).getAdapterFor(IJFaceNodeAdapter.class);
            }
            child = child.getNextSibling();
        }
        return children.toArray();
    }
    return new Object[0];
}
Also used : MediaList(org.w3c.dom.stylesheets.MediaList) ICSSStyleDeclaration(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclaration) ICSSPrimitiveValue(org.eclipse.wst.css.core.internal.provisional.document.ICSSPrimitiveValue) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) MediaList(org.w3c.dom.stylesheets.MediaList) List(java.util.List) ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode) INodeNotifier(org.eclipse.wst.sse.core.internal.provisional.INodeNotifier)

Example 38 with INodeNotifier

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

the class TestPageDirective method testAdapt.

public void testAdapt() {
    IDOMModel model = createUnmanagedHTMLModel();
    PageDirectiveAdapter pageDirectiveAdapter = (PageDirectiveAdapter) model.getDocument().getAdapterFor(PageDirectiveAdapter.class);
    Node ownerNode = model.getDocument();
    ModelQueryAdapter embeddedAdapter = (ModelQueryAdapter) pageDirectiveAdapter.adapt((INodeNotifier) ownerNode, ModelQueryAdapter.class);
    assertNotNull("could not adapt embedded adapter", embeddedAdapter);
}
Also used : ModelQueryAdapter(org.eclipse.wst.xml.core.internal.ssemodelquery.ModelQueryAdapter) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) Node(org.w3c.dom.Node) PageDirectiveAdapter(org.eclipse.jst.jsp.core.internal.document.PageDirectiveAdapter) INodeNotifier(org.eclipse.wst.sse.core.internal.provisional.INodeNotifier)

Example 39 with INodeNotifier

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

the class TestModelsFromFiles method testClone.

private void testClone(IStructuredModel structuredModel) throws IOException {
    IDOMDocument document = ((IDOMModel) structuredModel).getDocument();
    INodeNotifier notifier = document;
    ModelQueryAdapter modelQueryAdapter = (ModelQueryAdapter) notifier.getAdapterFor(ModelQueryAdapter.class);
    assertNotNull("initial modelQueryAdapter should not be null", modelQueryAdapter);
    IStructuredModel newModel = structuredModel.newInstance();
    IDOMDocument newDocument = ((IDOMModel) newModel).getDocument();
    INodeNotifier newNotifier = newDocument;
    ModelQueryAdapter result = (ModelQueryAdapter) newNotifier.getAdapterFor(ModelQueryAdapter.class);
    assertNotNull("newInstance modelQueryAdapter should not be null", result);
}
Also used : ModelQueryAdapter(org.eclipse.wst.xml.core.internal.ssemodelquery.ModelQueryAdapter) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) INodeNotifier(org.eclipse.wst.sse.core.internal.provisional.INodeNotifier)

Example 40 with INodeNotifier

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

the class TestForNPEInCSSCreation method testCSSModel.

public void testCSSModel() {
    IDOMModel model = FileUtil.createHTMLModel();
    try {
        IStructuredDocument structuredDocument = model.getStructuredDocument();
        structuredDocument.set(getHTMLDocumentText());
        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");
        String delim = model.getStructuredDocument().getLineDelimiter();
        if (delim == null)
            // $NON-NLS-1$
            delim = "\n";
        StringBuffer buffer = new StringBuffer(delim);
        // $NON-NLS-1$
        buffer.append("<!--");
        buffer.append(delim);
        // $NON-NLS-1$
        buffer.append("-->");
        buffer.append(delim);
        Text text = doc.createTextNode(buffer.toString());
        ele.appendChild(text);
        head.insertBefore(ele, null);
        // get adapter for StyleSheet
        ICSSStyleSheet sheet = (ICSSStyleSheet) ((IStyleSheetAdapter) ((INodeNotifier) ele).getAdapterFor(IStyleSheetAdapter.class)).getSheet();
        // create style declaration
        ICSSStyleRule rule = sheet.createCSSStyleRule();
        rule.getStyle().setProperty("background-color", "lime", "");
        rule.getStyle().setProperty("background-color", "blue", "");
        rule.getStyle().setProperty("background-color", "#0080ff", "");
    // model.save();
    } finally {
        if (model != null) {
            model.releaseFromEdit();
        }
    }
}
Also used : 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) Text(org.w3c.dom.Text) ICSSStyleSheet(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleSheet) INodeNotifier(org.eclipse.wst.sse.core.internal.provisional.INodeNotifier) ICSSStyleRule(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleRule)

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