Search in sources :

Example 71 with ModelQuery

use of org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery in project webtools.sourceediting by eclipse.

the class ElementNodeCleanupHandler method isEmptyElement.

private boolean isEmptyElement(IDOMElement element) {
    Document document = element.getOwnerDocument();
    if (document == null)
        // undefined tag, return default
        return false;
    ModelQuery modelQuery = ModelQueryUtil.getModelQuery(document);
    if (modelQuery == null)
        // undefined tag, return default
        return false;
    CMElementDeclaration decl = modelQuery.getCMElementDeclaration(element);
    if (decl == null)
        // undefined tag, return default
        return false;
    return (decl.getContentType() == CMElementDeclaration.EMPTY);
}
Also used : CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) ModelQuery(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery) Document(org.w3c.dom.Document) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)

Example 72 with ModelQuery

use of org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery in project webtools.sourceediting by eclipse.

the class ElementNodeCleanupHandler method getRequiredAttrs.

protected List getRequiredAttrs(Node node) {
    List result = new ArrayList();
    ModelQuery modelQuery = getModelQuery(node);
    if (modelQuery != null) {
        CMElementDeclaration elementDecl = modelQuery.getCMElementDeclaration((Element) node);
        if (elementDecl != null) {
            CMNamedNodeMap attrMap = elementDecl.getAttributes();
            Iterator it = attrMap.iterator();
            CMAttributeDeclaration attr = null;
            while (it.hasNext()) {
                attr = (CMAttributeDeclaration) it.next();
                if (attr.getUsage() == CMAttributeDeclaration.REQUIRED) {
                    result.add(attr);
                }
            }
        }
    }
    return result;
}
Also used : CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) List(java.util.List) ModelQuery(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery) CMAttributeDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration) CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)

Example 73 with ModelQuery

use of org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery in project webtools.sourceediting by eclipse.

the class DOMExtensionDetailsContentProvider method getItems.

public Object[] getItems(Object input) {
    HashMap resultMap = new HashMap();
    if (input instanceof Element) {
        Element element = (Element) input;
        // here we compute items for the attributes that physically in the document
        // 
        NamedNodeMap attributes = element.getAttributes();
        for (int i = 0; i < attributes.getLength(); i++) {
            Attr attr = (Attr) attributes.item(i);
            if (// $NON-NLS-1$ //$NON-NLS-2$
            !XMLNS.equals(attr.getName()) && !XMLNS.equals(attr.getPrefix())) {
                resultMap.put(attr.getName(), DOMExtensionItem.createItemForElementAttribute(element, attr));
            }
        }
        // here we compute an item for the text node that is physically in the document
        // 
        String textNodeValue = new TreeContentHelper().getNodeValue(element);
        if (textNodeValue != null) {
            resultMap.put(TEXT_NODE_KEY, DOMExtensionItem.createItemForElementText(element));
        }
        ModelQuery modelQuery = ModelQueryUtil.getModelQuery(element.getOwnerDocument());
        if (modelQuery != null) {
            CMElementDeclaration ed = modelQuery.getCMElementDeclaration(element);
            if (ed != null) {
                // here we compute items for the attributes that may be added to the document according to the grammar
                // 
                List list = modelQuery.getAvailableContent(element, ed, ModelQuery.INCLUDE_ATTRIBUTES);
                for (Iterator i = list.iterator(); i.hasNext(); ) {
                    CMAttributeDeclaration ad = (CMAttributeDeclaration) i.next();
                    if (ad != null && resultMap.get(ad.getNodeName()) == null) {
                        resultMap.put(ad.getNodeName(), DOMExtensionItem.createItemForElementAttribute(element, ad));
                    }
                }
                if (resultMap.get(TEXT_NODE_KEY) == null) {
                    // here we compute an item for the text node that may be added to the document according to the grammar
                    // 
                    int contentType = ed.getContentType();
                    if (contentType == CMElementDeclaration.PCDATA || contentType == CMElementDeclaration.MIXED) {
                        resultMap.put(TEXT_NODE_KEY, DOMExtensionItem.createItemForElementText(element));
                    }
                }
            }
        }
        Collection collection = resultMap.values();
        // 
        for (Iterator i = collection.iterator(); i.hasNext(); ) {
            initPropertyEditorConfiguration((DOMExtensionItem) i.next());
        }
        DOMExtensionItem[] items = new DOMExtensionItem[collection.size()];
        resultMap.values().toArray(items);
        // 
        if (items.length > 0) {
            Comparator comparator = new Comparator() {

                public int compare(Object arg0, Object arg1) {
                    DOMExtensionItem a = (DOMExtensionItem) arg0;
                    DOMExtensionItem b = (DOMExtensionItem) arg1;
                    // begin special case to ensure 'text nodes' come last
                    if (a.isTextValue() && !b.isTextValue()) {
                        return 1;
                    } else if (b.isTextValue() && !a.isTextValue()) {
                        return -1;
                    } else // end special case
                    {
                        return Collator.getInstance().compare(a.getName(), b.getName());
                    }
                }
            };
            Arrays.sort(items, comparator);
        }
        return items;
    } else if (input instanceof Attr) {
        Attr attr = (Attr) input;
        DOMExtensionItem item = DOMExtensionItem.createItemForAttributeText(attr.getOwnerElement(), attr);
        DOMExtensionItem[] items = { item };
        return items;
    }
    return EMPTY_ARRAY;
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) HashMap(java.util.HashMap) Element(org.w3c.dom.Element) Attr(org.w3c.dom.Attr) Comparator(java.util.Comparator) CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) Iterator(java.util.Iterator) Collection(java.util.Collection) TreeContentHelper(org.eclipse.wst.xml.ui.internal.tabletree.TreeContentHelper) ModelQuery(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery) List(java.util.List) CMAttributeDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration)

Example 74 with ModelQuery

use of org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery in project webtools.sourceediting by eclipse.

the class AbstractXMLElementContentAssistRequest method getAvailableContentNodes.

protected Iterator<CMNode> getAvailableContentNodes(IDOMDocument domDocument, Node ancestorNode, int includeOptions) {
    ModelQuery modelQuery = ModelQueryUtil.getModelQuery(domDocument);
    CMElementDeclaration cmElementDec = modelQuery.getCMElementDeclaration((Element) ancestorNode);
    List<CMNode> cmNodeList = modelQuery.getAvailableContent((Element) ancestorNode, cmElementDec, includeOptions);
    Iterator<CMNode> cmNodeIt = cmNodeList.iterator();
    return cmNodeIt;
}
Also used : CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) ModelQuery(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode)

Example 75 with ModelQuery

use of org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery in project webtools.sourceediting by eclipse.

the class AbstractXMLElementContentAssistRequest method getAvailableChildrenAtIndex.

protected List getAvailableChildrenAtIndex(Element parent, int index, int validityChecking) {
    List list = new ArrayList();
    CMElementDeclaration parentDecl = getCMElementDeclaration(parent);
    if (parentDecl != null) {
        ModelQuery modelQuery = ModelQueryUtil.getModelQuery(parent.getOwnerDocument());
        // taken from ActionManagers
        // int editMode = modelQuery.getEditMode();
        int editMode = ModelQuery.EDIT_MODE_UNCONSTRAINED;
        int ic = (editMode == ModelQuery.EDIT_MODE_CONSTRAINED_STRICT) ? ModelQuery.INCLUDE_CHILD_NODES | ModelQuery.INCLUDE_SEQUENCE_GROUPS : ModelQuery.INCLUDE_CHILD_NODES;
        modelQuery.getInsertActions(parent, parentDecl, index, ic, validityChecking, list);
    }
    return list;
}
Also used : CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) List(java.util.List) ModelQuery(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery)

Aggregations

ModelQuery (org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery)76 CMElementDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration)38 List (java.util.List)22 ArrayList (java.util.ArrayList)19 CMNode (org.eclipse.wst.xml.core.internal.contentmodel.CMNode)18 CMNamedNodeMap (org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)16 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)15 CMDocument (org.eclipse.wst.xml.core.internal.contentmodel.CMDocument)15 Element (org.w3c.dom.Element)15 Document (org.w3c.dom.Document)14 ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)13 Node (org.w3c.dom.Node)12 Iterator (java.util.Iterator)10 CMAttributeDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration)10 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)10 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)10 NodeList (org.w3c.dom.NodeList)10 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)7 IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)7 IFile (org.eclipse.core.resources.IFile)6