use of org.eclipse.xsd.XSDAttributeGroupContent in project webtools.sourceediting by eclipse.
the class MoveXSDAttributeAction method moveUnderXSDAttributeGroupDefinition.
protected void moveUnderXSDAttributeGroupDefinition(XSDAttributeGroupDefinition parentGroup) {
int originalIndex = 0;
for (Iterator iterator = parentGroup.getContents().iterator(); iterator.hasNext(); ) {
XSDAttributeGroupContent attributeGroupContent = (XSDAttributeGroupContent) iterator.next();
if (attributeGroupContent instanceof XSDAttributeUse) {
XSDAttributeDeclaration attribute = ((XSDAttributeUse) attributeGroupContent).getContent();
if (attribute == selected) {
parentGroup.getContents().remove(attribute.getContainer());
break;
}
}
originalIndex++;
}
int index = 0;
boolean addedBack = false;
if (insertType == INSERT_DIRECT) {
XSDConcreteComponent container = selected.getContainer();
if (container != null) {
if (insertAtEnd)
((XSDAttributeGroupDefinition) parentComponent).getResolvedAttributeGroupDefinition().getContents().add(container);
else
((XSDAttributeGroupDefinition) parentComponent).getResolvedAttributeGroupDefinition().getContents().add(0, container);
addedBack = true;
}
return;
}
List attributeGroupContents = parentGroup.getContents();
for (Iterator iterator = attributeGroupContents.iterator(); iterator.hasNext(); ) {
XSDAttributeGroupContent attributeGroupContent = (XSDAttributeGroupContent) iterator.next();
if (attributeGroupContent instanceof XSDAttributeUse) {
XSDAttributeDeclaration attribute = ((XSDAttributeUse) attributeGroupContent).getContent();
if (insertType == INSERT_BEFORE) {
if (attribute == nextRefComponent) {
parentGroup.getContents().add(index, selected.getContainer());
addedBack = true;
break;
}
if (selected == nextRefComponent && originalIndex == index) {
parentGroup.getContents().add(index, selected.getContainer());
addedBack = true;
break;
}
} else if (insertType == INSERT_AFTER) {
if (attribute == previousRefComponent) {
parentGroup.getContents().add(index + 1, selected.getContainer());
addedBack = true;
break;
}
if (selected == previousRefComponent && originalIndex == index) {
parentGroup.getContents().add(index, selected.getContainer());
addedBack = true;
break;
}
}
}
index++;
}
if (attributeGroupContents.size() == 0) {
parentGroup.getContents().add(selected.getContainer());
addedBack = true;
}
if (!addedBack) {
parentGroup.getContents().add(originalIndex, selected.getContainer());
}
}
Aggregations