Search in sources :

Example 21 with XSDAttributeUse

use of org.eclipse.xsd.XSDAttributeUse in project webtools.sourceediting by eclipse.

the class UpdateMinOccursCommand method execute.

public void execute() {
    Element element = component.getElement();
    try {
        beginRecording(element);
        removeMinOccursAttribute = (!(element.hasAttribute(XSDConstants.MINOCCURS_ATTRIBUTE))) ? true : false;
        if (component instanceof XSDParticle) {
            oldMinOccurs = ((XSDParticle) component).getMinOccurs();
            ((XSDParticle) component).setMinOccurs(newMinOccurs);
        } else if (component instanceof XSDAttributeUse) {
            oldMinOccurs = (((XSDAttributeUse) component).getUse() == XSDAttributeUseCategory.REQUIRED_LITERAL ? 1 : 0);
            if (newMinOccurs == 1)
                ((XSDAttributeUse) component).setUse(XSDAttributeUseCategory.REQUIRED_LITERAL);
            else
                ((XSDAttributeUse) component).setUse(XSDAttributeUseCategory.OPTIONAL_LITERAL);
        }
    } finally {
        endRecording();
    }
}
Also used : XSDAttributeUse(org.eclipse.xsd.XSDAttributeUse) Element(org.w3c.dom.Element) XSDParticle(org.eclipse.xsd.XSDParticle)

Example 22 with XSDAttributeUse

use of org.eclipse.xsd.XSDAttributeUse in project webtools.sourceediting by eclipse.

the class DeleteCommand method execute.

public void execute() {
    XSDVisitor visitor = new XSDVisitor() {

        public void visitElementDeclaration(org.eclipse.xsd.XSDElementDeclaration element) {
            if (element.getTypeDefinition() == target) {
                // $NON-NLS-1$
                XSDSimpleTypeDefinition type = target.getSchema().getSchemaForSchema().resolveSimpleTypeDefinition("string");
                element.setTypeDefinition(type);
            }
            super.visitElementDeclaration(element);
        }
    };
    XSDConcreteComponent parent = target.getContainer();
    XSDSchema schema = target.getSchema();
    try {
        beginRecording(parent.getElement());
        boolean doCleanup = false;
        if (target instanceof XSDModelGroup || target instanceof XSDElementDeclaration || target instanceof XSDModelGroupDefinition) {
            doCleanup = true;
            if (parent instanceof XSDParticle) {
                if (parent.getContainer() instanceof XSDModelGroup) {
                    XSDModelGroup modelGroup = (XSDModelGroup) ((XSDParticle) parent).getContainer();
                    modelGroup.getContents().remove(parent);
                } else if (parent.getContainer() instanceof XSDComplexTypeDefinition) {
                    XSDComplexTypeDefinition complexType = (XSDComplexTypeDefinition) parent.getContainer();
                    complexType.setContent(null);
                }
            } else if (parent instanceof XSDSchema) {
                visitor.visitSchema(target.getSchema());
                ((XSDSchema) parent).getContents().remove(target);
            } else if (parent instanceof XSDRedefine) {
                Object adapter = target.eAdapters().get(0);
                if (adapter instanceof XSDModelGroupDefinitionAdapter) {
                    ((XSDModelGroupDefinitionAdapter) adapter).setReadOnly(true);
                    ((XSDModelGroupDefinitionAdapter) adapter).setChangeReadOnlyField(true);
                }
                ((XSDRedefine) parent).getContents().remove(target);
            }
        } else if (target instanceof XSDAttributeDeclaration) {
            doCleanup = true;
            if (parent instanceof XSDAttributeUse) {
                EObject obj = parent.eContainer();
                XSDComplexTypeDefinition complexType = null;
                while (obj != null) {
                    if (obj instanceof XSDComplexTypeDefinition) {
                        complexType = (XSDComplexTypeDefinition) obj;
                        break;
                    }
                    obj = obj.eContainer();
                }
                if (complexType != null) {
                    complexType.getAttributeContents().remove(parent);
                }
                if (parent.getContainer() instanceof XSDAttributeGroupDefinition) {
                    XSDAttributeGroupDefinition attrGroup = (XSDAttributeGroupDefinition) parent.getContainer();
                    attrGroup.getContents().remove(parent);
                }
            } else if (parent instanceof XSDSchema) {
                visitor.visitSchema(target.getSchema());
                ((XSDSchema) parent).getContents().remove(target);
            }
        } else if (target instanceof XSDAttributeGroupDefinition && parent instanceof XSDComplexTypeDefinition) {
            doCleanup = true;
            ((XSDComplexTypeDefinition) parent).getAttributeContents().remove(target);
        } else if (target instanceof XSDEnumerationFacet) {
            XSDEnumerationFacet enumerationFacet = (XSDEnumerationFacet) target;
            enumerationFacet.getSimpleTypeDefinition().getFacetContents().remove(enumerationFacet);
        } else if (target instanceof XSDWildcard) {
            if (parent instanceof XSDParticle) {
                if (parent.getContainer() instanceof XSDModelGroup) {
                    XSDModelGroup modelGroup = (XSDModelGroup) ((XSDParticle) parent).getContainer();
                    modelGroup.getContents().remove(parent);
                }
            } else if (parent instanceof XSDComplexTypeDefinition) {
                ((XSDComplexTypeDefinition) parent).setAttributeWildcardContent(null);
            } else if (parent instanceof XSDAttributeGroupDefinition) {
                ((XSDAttributeGroupDefinition) parent).setAttributeWildcardContent(null);
            }
        } else if (target instanceof XSDTypeDefinition && parent instanceof XSDElementDeclaration) {
            doCleanup = true;
            ((XSDElementDeclaration) parent).setTypeDefinition(target.resolveSimpleTypeDefinition(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001, "string"));
        } else {
            if (parent instanceof XSDSchema) {
                doCleanup = true;
                visitor.visitSchema(target.getSchema());
                ((XSDSchema) parent).getContents().remove(target);
            } else if (parent instanceof XSDRedefine) {
                doCleanup = false;
                EList contents = ((XSDRedefine) parent).getContents();
                Object adapter = target.eAdapters().get(0);
                if (adapter instanceof XSDComplexTypeDefinitionAdapter) {
                    ((XSDComplexTypeDefinitionAdapter) adapter).setReadOnly(true);
                    ((XSDComplexTypeDefinitionAdapter) adapter).setChangeReadOnlyField(true);
                } else if (adapter instanceof XSDSimpleTypeDefinitionAdapter) {
                    ((XSDSimpleTypeDefinitionAdapter) adapter).setReadOnly(true);
                    ((XSDSimpleTypeDefinitionAdapter) adapter).setChangeReadOnlyField(true);
                } else if (adapter instanceof XSDAttributeGroupDefinitionAdapter) {
                    ((XSDAttributeGroupDefinitionAdapter) adapter).setReadOnly(true);
                    ((XSDAttributeGroupDefinitionAdapter) adapter).setChangeReadOnlyField(true);
                }
                contents.remove(target);
            }
        }
        if (doCleanup)
            XSDDirectivesManager.removeUnusedXSDImports(schema);
    } finally {
        endRecording();
    }
}
Also used : XSDAttributeUse(org.eclipse.xsd.XSDAttributeUse) XSDRedefine(org.eclipse.xsd.XSDRedefine) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDVisitor(org.eclipse.wst.xsd.ui.internal.adapters.XSDVisitor) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition) XSDSimpleTypeDefinitionAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDSimpleTypeDefinitionAdapter) XSDEnumerationFacet(org.eclipse.xsd.XSDEnumerationFacet) EObject(org.eclipse.emf.ecore.EObject) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDParticle(org.eclipse.xsd.XSDParticle) XSDSchema(org.eclipse.xsd.XSDSchema) XSDComplexTypeDefinitionAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDComplexTypeDefinitionAdapter) XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) XSDAttributeGroupDefinitionAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDAttributeGroupDefinitionAdapter) XSDWildcard(org.eclipse.xsd.XSDWildcard) XSDAttributeGroupDefinition(org.eclipse.xsd.XSDAttributeGroupDefinition) EList(org.eclipse.emf.common.util.EList) XSDModelGroupDefinitionAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDModelGroupDefinitionAdapter) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) EObject(org.eclipse.emf.ecore.EObject) XSDModelGroupDefinition(org.eclipse.xsd.XSDModelGroupDefinition) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration)

Example 23 with XSDAttributeUse

use of org.eclipse.xsd.XSDAttributeUse in project webtools.sourceediting by eclipse.

the class XSDTabbedPropertySheetPage method selectionChanged.

/* (non-Javadoc)
   * @see org.eclipse.ui.ISelectionListener#selectionChanged(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
   */
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
    Object selected = ((IStructuredSelection) selection).getFirstElement();
    if (selected instanceof XSDBaseAdapter) {
        XSDBaseAdapter adapter = (XSDBaseAdapter) selected;
        if (oldSelection != null) {
            oldSelection.unregisterListener(this);
            if (oldSelection instanceof XSDElementDeclarationAdapter) {
                XSDElementDeclaration elem = (XSDElementDeclaration) ((XSDElementDeclarationAdapter) oldSelection).getTarget();
                if (elem.getContainer() != null) {
                    Adapter adap = XSDAdapterFactory.getInstance().adapt(elem.getContainer());
                    if (adap instanceof XSDParticleAdapter) {
                        XSDParticleAdapter particleAdapter = (XSDParticleAdapter) adap;
                        particleAdapter.unregisterListener(this);
                    }
                }
                if (elem.isElementDeclarationReference()) {
                    XSDElementDeclarationAdapter resolvedElementAdapter = (XSDElementDeclarationAdapter) XSDAdapterFactory.getInstance().adapt(elem.getResolvedElementDeclaration());
                    resolvedElementAdapter.unregisterListener(this);
                }
            }
        }
        if (adapter instanceof XSDElementDeclarationAdapter) {
            XSDElementDeclaration elem = (XSDElementDeclaration) ((XSDElementDeclarationAdapter) adapter).getTarget();
            Adapter adap = XSDAdapterFactory.getInstance().adapt(elem.getContainer());
            if (adap instanceof XSDParticleAdapter) {
                XSDParticleAdapter particleAdapter = (XSDParticleAdapter) adap;
                particleAdapter.registerListener(this);
            }
            if (elem.isElementDeclarationReference()) {
                XSDElementDeclarationAdapter resolvedElementAdapter = (XSDElementDeclarationAdapter) XSDAdapterFactory.getInstance().adapt(elem.getResolvedElementDeclaration());
                resolvedElementAdapter.registerListener(this);
            }
        } else if (adapter instanceof XSDAttributeUseAdapter) {
            XSDAttributeUseAdapter attributeUse = (XSDAttributeUseAdapter) adapter;
            XSDAttributeUse xsdAttrUse = (XSDAttributeUse) attributeUse.getTarget();
            adapter = (XSDBaseAdapter) XSDAdapterFactory.getInstance().adapt(xsdAttrUse.getAttributeDeclaration());
        }
        adapter.registerListener(this);
        oldSelection = adapter;
        Object model = adapter.getTarget();
        if (xsdModelAdapter != null && xsdModelAdapter.getModelReconcileAdapter() != null) {
            xsdModelAdapter.getModelReconcileAdapter().removeListener(internalNodeAdapter);
        }
        Element element = ((XSDConcreteComponent) adapter.getTarget()).getElement();
        if (element != null) {
            xsdModelAdapter = XSDModelAdapter.lookupOrCreateModelAdapter(element.getOwnerDocument());
        }
        if (xsdModelAdapter != null && xsdModelAdapter.getModelReconcileAdapter() != null) {
            xsdModelAdapter.getModelReconcileAdapter().addListener(internalNodeAdapter);
        }
        if (model instanceof XSDConcreteComponent) {
            selection = new StructuredSelection(model);
        }
        super.selectionChanged(part, selection);
        return;
    }
    super.selectionChanged(part, selection);
}
Also used : XSDAttributeUse(org.eclipse.xsd.XSDAttributeUse) XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) Element(org.w3c.dom.Element) XSDParticleAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDParticleAdapter) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) XSDBaseAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter) XSDParticleAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDParticleAdapter) Adapter(org.eclipse.emf.common.notify.Adapter) XSDModelAdapter(org.eclipse.wst.xsd.ui.internal.text.XSDModelAdapter) XSDElementDeclarationAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDElementDeclarationAdapter) INodeAdapter(org.eclipse.wst.sse.core.internal.provisional.INodeAdapter) XSDBaseAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter) XSDAttributeUseAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDAttributeUseAdapter) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) XSDElementDeclarationAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDElementDeclarationAdapter) XSDAttributeUseAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDAttributeUseAdapter)

Example 24 with XSDAttributeUse

use of org.eclipse.xsd.XSDAttributeUse in project webtools.sourceediting by eclipse.

the class MoveXSDAttributeAction method moveUnderXSDComplexTypeDefinition.

protected void moveUnderXSDComplexTypeDefinition(XSDComplexTypeDefinition complexType) {
    int originalIndex = 0;
    for (Iterator iterator = complexType.getAttributeContents().iterator(); iterator.hasNext(); ) {
        XSDAttributeGroupContent attributeGroupContent = (XSDAttributeGroupContent) iterator.next();
        if (attributeGroupContent instanceof XSDAttributeUse) {
            XSDAttributeDeclaration attribute = ((XSDAttributeUse) attributeGroupContent).getContent();
            if (attribute == selected) {
                complexType.getAttributeContents().remove(attribute.getContainer());
                break;
            }
        }
        originalIndex++;
    }
    int index = 0;
    boolean addedBack = false;
    List attributeGroupContents = complexType.getAttributeContents();
    for (Iterator iterator = attributeGroupContents.iterator(); iterator.hasNext(); ) {
        XSDAttributeGroupContent attributeGroupContent = (XSDAttributeGroupContent) iterator.next();
        if (attributeGroupContent instanceof XSDAttributeUse) {
            XSDAttributeDeclaration attribute = ((XSDAttributeUse) attributeGroupContent).getContent();
            if (insertType == INSERT_AFTER) {
                if (attribute == previousRefComponent) {
                    complexType.getAttributeContents().add(index + 1, selected.getContainer());
                    addedBack = true;
                    break;
                }
            } else if (insertType == INSERT_BEFORE) {
                if (attribute == nextRefComponent) {
                    complexType.getAttributeContents().add(index, selected.getContainer());
                    addedBack = true;
                    break;
                }
            }
        }
        index++;
    }
    if (attributeGroupContents.size() == 0) {
        complexType.getAttributeContents().add(selected.getContainer());
        addedBack = true;
    }
    if (!addedBack) {
        complexType.getAttributeContents().add(originalIndex, selected.getContainer());
    }
}
Also used : XSDAttributeUse(org.eclipse.xsd.XSDAttributeUse) Iterator(java.util.Iterator) List(java.util.List) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration) XSDAttributeGroupContent(org.eclipse.xsd.XSDAttributeGroupContent)

Example 25 with XSDAttributeUse

use of org.eclipse.xsd.XSDAttributeUse 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

XSDAttributeUse (org.eclipse.xsd.XSDAttributeUse)28 Iterator (java.util.Iterator)17 XSDAttributeGroupDefinition (org.eclipse.xsd.XSDAttributeGroupDefinition)17 XSDAttributeDeclaration (org.eclipse.xsd.XSDAttributeDeclaration)14 XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)14 XSDParticle (org.eclipse.xsd.XSDParticle)12 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)11 XSDSimpleTypeDefinition (org.eclipse.xsd.XSDSimpleTypeDefinition)11 XSDModelGroup (org.eclipse.xsd.XSDModelGroup)10 XSDConcreteComponent (org.eclipse.xsd.XSDConcreteComponent)9 XSDSchema (org.eclipse.xsd.XSDSchema)9 List (java.util.List)8 XSDWildcard (org.eclipse.xsd.XSDWildcard)8 ArrayList (java.util.ArrayList)7 EList (org.eclipse.emf.common.util.EList)7 Element (org.w3c.dom.Element)7 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)6 XSDIdentityConstraintDefinition (org.eclipse.xsd.XSDIdentityConstraintDefinition)6 XSDTypeDefinition (org.eclipse.xsd.XSDTypeDefinition)6 XSDXPathDefinition (org.eclipse.xsd.XSDXPathDefinition)6