Search in sources :

Example 6 with XSDAttributeGroupContent

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());
    }
}
Also used : XSDAttributeUse(org.eclipse.xsd.XSDAttributeUse) XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) Iterator(java.util.Iterator) List(java.util.List) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration) XSDAttributeGroupContent(org.eclipse.xsd.XSDAttributeGroupContent)

Aggregations

Iterator (java.util.Iterator)6 XSDAttributeGroupContent (org.eclipse.xsd.XSDAttributeGroupContent)6 XSDAttributeUse (org.eclipse.xsd.XSDAttributeUse)5 List (java.util.List)4 XSDAttributeGroupDefinition (org.eclipse.xsd.XSDAttributeGroupDefinition)4 ArrayList (java.util.ArrayList)2 TargetConnectionSpaceFiller (org.eclipse.wst.xsd.ui.internal.design.editparts.model.TargetConnectionSpaceFiller)2 XSDAttributeDeclaration (org.eclipse.xsd.XSDAttributeDeclaration)2 EList (org.eclipse.emf.common.util.EList)1 XSDAttributeGroupDefinitionAdapter (org.eclipse.wst.xsd.ui.internal.adapters.XSDAttributeGroupDefinitionAdapter)1 XSDBaseAdapter (org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter)1 XSDComplexTypeContent (org.eclipse.xsd.XSDComplexTypeContent)1 XSDConcreteComponent (org.eclipse.xsd.XSDConcreteComponent)1 XSDParticle (org.eclipse.xsd.XSDParticle)1 XSDSimpleTypeDefinition (org.eclipse.xsd.XSDSimpleTypeDefinition)1