Search in sources :

Example 1 with DOMAttribute

use of org.eclipse.wst.xsd.ui.internal.actions.DOMAttribute in project webtools.sourceediting by eclipse.

the class XSDSimpleTypeSection method addCreateElementActionIfNotExist.

// issue (cs) this method seems to be utilizing 'old' classes, can we reimplement?
// (e.g. ChangeElementAction, XSDDOMHelper, etc)
protected boolean addCreateElementActionIfNotExist(String elementTag, String label, Element parent, Node relativeNode) {
    XSDSimpleTypeDefinition st = (XSDSimpleTypeDefinition) input;
    List attributes = new ArrayList();
    String reuseType = null;
    // parent); //$NON-NLS-1$
    if (elementTag.equals(XSDConstants.RESTRICTION_ELEMENT_TAG)) {
        Element listNode = getFirstChildNodeIfExists(parent, XSDConstants.LIST_ELEMENT_TAG, false);
        if (listNode != null) {
            if (listNode.hasAttribute(XSDConstants.ITEMTYPE_ATTRIBUTE))
                reuseType = listNode.getAttribute(XSDConstants.ITEMTYPE_ATTRIBUTE);
            XSDDOMHelper.removeNodeAndWhitespace(listNode);
        }
        Element unionNode = getFirstChildNodeIfExists(parent, XSDConstants.UNION_ELEMENT_TAG, false);
        if (unionNode != null) {
            if (unionNode.hasAttribute(XSDConstants.MEMBERTYPES_ATTRIBUTE)) {
                String memberAttr = unionNode.getAttribute(XSDConstants.MEMBERTYPES_ATTRIBUTE);
                StringTokenizer stringTokenizer = new StringTokenizer(memberAttr);
                reuseType = stringTokenizer.nextToken();
            }
            XSDDOMHelper.removeNodeAndWhitespace(unionNode);
        }
        if (reuseType == null) {
            reuseType = getBuiltInStringQName();
        }
        attributes.add(new DOMAttribute(XSDConstants.BASE_ATTRIBUTE, reuseType));
        st.setItemTypeDefinition(null);
    } else if (elementTag.equals(XSDConstants.LIST_ELEMENT_TAG)) {
        Element restrictionNode = getFirstChildNodeIfExists(parent, XSDConstants.RESTRICTION_ELEMENT_TAG, false);
        if (restrictionNode != null) {
            reuseType = restrictionNode.getAttribute(XSDConstants.BASE_ATTRIBUTE);
            XSDDOMHelper.removeNodeAndWhitespace(restrictionNode);
        }
        Element unionNode = getFirstChildNodeIfExists(parent, XSDConstants.UNION_ELEMENT_TAG, false);
        if (unionNode != null) {
            String memberAttr = unionNode.getAttribute(XSDConstants.MEMBERTYPES_ATTRIBUTE);
            if (memberAttr != null) {
                StringTokenizer stringTokenizer = new StringTokenizer(memberAttr);
                reuseType = stringTokenizer.nextToken();
            }
            XSDDOMHelper.removeNodeAndWhitespace(unionNode);
        }
        attributes.add(new DOMAttribute(XSDConstants.ITEMTYPE_ATTRIBUTE, reuseType));
    } else if (elementTag.equals(XSDConstants.UNION_ELEMENT_TAG)) {
        Element listNode = getFirstChildNodeIfExists(parent, XSDConstants.LIST_ELEMENT_TAG, false);
        if (listNode != null) {
            reuseType = listNode.getAttribute(XSDConstants.ITEMTYPE_ATTRIBUTE);
            XSDDOMHelper.removeNodeAndWhitespace(listNode);
        }
        Element restrictionNode = getFirstChildNodeIfExists(parent, XSDConstants.RESTRICTION_ELEMENT_TAG, false);
        if (restrictionNode != null) {
            reuseType = restrictionNode.getAttribute(XSDConstants.BASE_ATTRIBUTE);
            XSDDOMHelper.removeNodeAndWhitespace(restrictionNode);
        }
        attributes.add(new DOMAttribute(XSDConstants.MEMBERTYPES_ATTRIBUTE, reuseType));
        st.setItemTypeDefinition(null);
    }
    if (getFirstChildNodeIfExists(parent, elementTag, false) == null) {
        Action action = addCreateElementAction(elementTag, label, attributes, parent, relativeNode);
        action.run();
    }
    st.setElement(parent);
    st.updateElement();
    // endRecording(parent);
    return true;
}
Also used : StringTokenizer(com.ibm.icu.util.StringTokenizer) CreateElementAction(org.eclipse.wst.xsd.ui.internal.actions.CreateElementAction) Action(org.eclipse.jface.action.Action) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) DOMAttribute(org.eclipse.wst.xsd.ui.internal.actions.DOMAttribute) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) List(java.util.List)

Aggregations

StringTokenizer (com.ibm.icu.util.StringTokenizer)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Action (org.eclipse.jface.action.Action)1 CreateElementAction (org.eclipse.wst.xsd.ui.internal.actions.CreateElementAction)1 DOMAttribute (org.eclipse.wst.xsd.ui.internal.actions.DOMAttribute)1 XSDSimpleTypeDefinition (org.eclipse.xsd.XSDSimpleTypeDefinition)1 Element (org.w3c.dom.Element)1 NodeList (org.w3c.dom.NodeList)1