Search in sources :

Example 81 with CMElementDeclaration

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

the class BaseNodeActionManager method contributeReplaceActions.

protected void contributeReplaceActions(IMenuManager menu, List selectedNodeList, int ic, int vc) {
    // 'Replace With...' actions
    // 
    IMenuManager replaceWithMenu = new MyMenuManager(XMLUIMessages._UI_MENU_REPLACE_WITH);
    menu.add(replaceWithMenu);
    if ((modelQuery.getEditMode() == ModelQuery.EDIT_MODE_CONSTRAINED_STRICT) && (selectedNodeList.size() > 0)) {
        Node node = (Node) selectedNodeList.get(0);
        Node parentNode = node.getParentNode();
        if ((parentNode != null) && (parentNode.getNodeType() == Node.ELEMENT_NODE)) {
            Element parentElement = (Element) parentNode;
            CMElementDeclaration parentED = modelQuery.getCMElementDeclaration(parentElement);
            if (parentED != null) {
                List replaceActionList = new Vector();
                modelQuery.getReplaceActions(parentElement, parentED, selectedNodeList, ic, vc, replaceActionList);
                addActionHelper(replaceWithMenu, replaceActionList);
            }
        }
    }
}
Also used : CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) Node(org.w3c.dom.Node) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) List(java.util.List) IMenuManager(org.eclipse.jface.action.IMenuManager) Vector(java.util.Vector)

Example 82 with CMElementDeclaration

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

the class XMLTableTreePropertyDescriptorFactory method createTextPropertyDescriptor.

public IPropertyDescriptor createTextPropertyDescriptor(Text text) {
    IPropertyDescriptor result = null;
    Node parentNode = text.getParentNode();
    if ((parentNode != null) && (parentNode.getNodeType() == Node.ELEMENT_NODE)) {
        Element parentElement = (Element) parentNode;
        ModelQuery mq = ModelQueryUtil.getModelQuery(text.getOwnerDocument());
        CMElementDeclaration ed = null;
        if (mq != null) {
            ed = mq.getCMElementDeclaration(parentElement);
        }
        if (ed != null) {
            result = createPropertyDescriptorHelper(HACK, parentElement, ed);
        } else {
            result = createDefaultPropertyDescriptor(parentElement.getNodeName());
        }
    }
    if (result == null) {
        result = new TextPropertyDescriptor(HACK, HACK);
    }
    return result;
}
Also used : CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) Node(org.w3c.dom.Node) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) Element(org.w3c.dom.Element) ModelQuery(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery) TextPropertyDescriptor(org.eclipse.ui.views.properties.TextPropertyDescriptor) IPropertyDescriptor(org.eclipse.ui.views.properties.IPropertyDescriptor)

Example 83 with CMElementDeclaration

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

the class XMLTreeExtension method getElementValueHelper.

public String getElementValueHelper(Element element) {
    String result = null;
    ModelQuery mq = ModelQueryUtil.getModelQuery(element.getOwnerDocument());
    if ((result == null) && (mq != null)) {
        CMElementDeclaration ed = mq.getCMElementDeclaration(element);
        if ((ed != null) && !Boolean.TRUE.equals(ed.getProperty("isInferred"))) {
            // $NON-NLS-1$
            result = decriptionBuilder.buildDescription(ed);
        }
    }
    // $NON-NLS-1$
    return result != null ? result : "";
}
Also used : CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) ModelQuery(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery)

Example 84 with CMElementDeclaration

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

the class NewXMLGenerator method createXMLDocument.

public ByteArrayOutputStream createXMLDocument(String xmlFileName, String charset) throws Exception {
    if (charset == null) {
        charset = getUserPreferredCharset();
        if (charset == null) {
            // $NON-NLS-1$
            charset = "UTF-8";
        }
    }
    CMDocument cmDocument = getCMDocument();
    Assert.isNotNull(cmDocument);
    Assert.isNotNull(getRootElementName());
    // create the xml model
    CMNamedNodeMap nameNodeMap = cmDocument.getElements();
    CMElementDeclaration cmElementDeclaration = (CMElementDeclaration) nameNodeMap.getNamedItem(getRootElementName());
    Document xmlDocument = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
    DOMContentBuilderImpl contentBuilder = new DOMContentBuilderImpl(xmlDocument);
    // this 'uglyTempHack' flag is required in order to supress the
    // creation a default encoding
    // we'll handle this later in the domWriter.print() method used below
    // 
    contentBuilder.supressCreationOfDoctypeAndXMLDeclaration = true;
    contentBuilder.setBuildPolicy(buildPolicy);
    contentBuilder.setOptionalElementDepthLimit(optionalElementDepthLimit);
    contentBuilder.setExternalCMDocumentSupport(new MyExternalCMDocumentSupport(namespaceInfoList, xmlFileName));
    contentBuilder.createDefaultRootContent(cmDocument, cmElementDeclaration, namespaceInfoList);
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream, charset);
    DOMWriter domWriter = new DOMWriter(outputStreamWriter);
    // TODO... instead of relying on file extensions, we need to keep
    // track of the grammar type
    // better yet we should reate an SSE document so that we can format it
    // nicely before saving
    // then we won't need the DOMWriter at all
    // 
    domWriter.print(xmlDocument, charset, cmDocument.getNodeName(), getNonWhitespaceString(getPublicId()), getNonWhitespaceString(getSystemId()));
    outputStream.flush();
    outputStream.close();
    return outputStream;
}
Also used : CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) DOMContentBuilderImpl(org.eclipse.wst.xml.core.internal.contentmodel.util.DOMContentBuilderImpl) DOMWriter(org.eclipse.wst.xml.core.internal.contentmodel.util.DOMWriter) CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) OutputStreamWriter(java.io.OutputStreamWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap) Document(org.w3c.dom.Document) CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument)

Example 85 with CMElementDeclaration

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

the class XMLTableTreeContentProvider method getElementValueHelper.

private String getElementValueHelper(Element element) {
    String result = null;
    ModelQuery mq = ModelQueryUtil.getModelQuery(element.getOwnerDocument());
    if ((result == null) && (mq != null)) {
        CMElementDeclaration ed = mq.getCMElementDeclaration(element);
        if ((ed != null) && !Boolean.TRUE.equals(ed.getProperty("isInferred"))) {
            // $NON-NLS-1$
            result = descriptionBuilder.buildDescription(ed);
        }
    }
    // $NON-NLS-1$
    return result != null ? result : "";
}
Also used : CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) ModelQuery(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery)

Aggregations

CMElementDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration)147 CMNode (org.eclipse.wst.xml.core.internal.contentmodel.CMNode)53 List (java.util.List)46 CMNamedNodeMap (org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)43 Element (org.w3c.dom.Element)41 ModelQuery (org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery)38 CMDocument (org.eclipse.wst.xml.core.internal.contentmodel.CMDocument)37 ArrayList (java.util.ArrayList)35 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)33 Node (org.w3c.dom.Node)32 CMAttributeDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration)30 NodeList (org.w3c.dom.NodeList)28 ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)24 Iterator (java.util.Iterator)19 CMNodeList (org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList)19 CustomCompletionProposal (org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal)17 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)17 NamedNodeMap (org.w3c.dom.NamedNodeMap)17 Image (org.eclipse.swt.graphics.Image)15 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)15