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;
}
Aggregations