Search in sources :

Example 61 with XSDComplexTypeDefinition

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

the class AddXSDAttributeGroupDefinitionCommand method getNewName.

protected String getNewName(String description) {
    // $NON-NLS-1$
    String candidateName = "New" + description;
    XSDConcreteComponent parent = xsdComplexTypeDefinition;
    names = new ArrayList();
    int i = 1;
    if (parent instanceof XSDComplexTypeDefinition) {
        XSDComplexTypeDefinition ct = (XSDComplexTypeDefinition) parent;
        walkUpInheritance(ct);
        boolean ready = false;
        while (!ready) {
            ready = true;
            for (Iterator iter = names.iterator(); iter.hasNext(); ) {
                String attrName = (String) iter.next();
                if (candidateName.equals(attrName)) {
                    ready = false;
                    // $NON-NLS-1$
                    candidateName = "New" + description + String.valueOf(i);
                    i++;
                }
            }
        }
    }
    return candidateName;
}
Also used : XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition)

Example 62 with XSDComplexTypeDefinition

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

the class AddXSDElementCommand method createXSDElementDeclaration.

protected XSDParticle createXSDElementDeclaration() {
    // $NON-NLS-1$
    XSDSimpleTypeDefinition type = xsdModelGroup.getSchema().getSchemaForSchema().resolveSimpleTypeDefinition("string");
    XSDElementDeclaration element = XSDFactory.eINSTANCE.createXSDElementDeclaration();
    XSDConcreteComponent comp = xsdModelGroup.getContainer();
    ArrayList usedAttributeNames = new ArrayList();
    XSDCommonUIUtils.resetVisitedGroupsStack();
    usedAttributeNames.addAll(XSDCommonUIUtils.getChildElements(xsdModelGroup));
    while (comp != null) {
        if (comp instanceof XSDModelGroupDefinition) {
            usedAttributeNames.addAll(XSDCommonUIUtils.getAllAttributes((XSDModelGroupDefinition) comp));
            break;
        } else if (comp instanceof XSDComplexTypeDefinition) {
            usedAttributeNames.addAll(XSDCommonUIUtils.getAllAttributes((XSDComplexTypeDefinition) comp));
            usedAttributeNames.addAll(XSDCommonUIUtils.getInheritedAttributes((XSDComplexTypeDefinition) comp));
            break;
        }
        comp = comp.getContainer();
    }
    element.setName(XSDCommonUIUtils.createUniqueElementName(nameToAdd == null ? "NewElement" : nameToAdd, // $NON-NLS-1$
    usedAttributeNames));
    element.setTypeDefinition(type);
    XSDParticle particle = XSDFactory.eINSTANCE.createXSDParticle();
    particle.setContent(element);
    addedXSDConcreteComponent = element;
    return particle;
}
Also used : XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) ArrayList(java.util.ArrayList) XSDModelGroupDefinition(org.eclipse.xsd.XSDModelGroupDefinition) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDParticle(org.eclipse.xsd.XSDParticle)

Example 63 with XSDComplexTypeDefinition

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

the class AddXSDEnumerationFacetAction method calculateEnabled.

protected boolean calculateEnabled() {
    boolean parentResult = super.calculateEnabled();
    boolean endResult = true;
    Object selection = ((IStructuredSelection) getSelection()).getFirstElement();
    if (selection instanceof XSDComplexTypeDefinitionAdapter) {
        XSDComplexTypeDefinition definition = ((XSDComplexTypeDefinitionAdapter) selection).getXSDComplexTypeDefinition();
        XSDTypeDefinition baseType = definition.getBaseType();
        if (baseType instanceof XSDSimpleTypeDefinition)
            endResult = false;
    }
    endResult = endResult & parentResult;
    return endResult;
}
Also used : XSDComplexTypeDefinitionAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDComplexTypeDefinitionAdapter) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition)

Example 64 with XSDComplexTypeDefinition

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

the class AddXSDEnumerationFacetAction method run.

public void run() {
    Object selection = ((IStructuredSelection) getSelection()).getFirstElement();
    if (selection instanceof XSDBaseAdapter) {
        selection = ((XSDBaseAdapter) selection).getTarget();
        int index = -1;
        AddEnumerationsCommand command = null;
        XSDSimpleTypeDefinition st = null;
        if (selection instanceof XSDSimpleTypeDefinition) {
            st = (XSDSimpleTypeDefinition) selection;
            command = new AddEnumerationsCommand(getText(), st);
        } else if (selection instanceof XSDEnumerationFacet) {
            st = ((XSDEnumerationFacet) selection).getSimpleTypeDefinition();
            index = st.getFacetContents().indexOf(selection);
            doDirectEdit = true;
            command = new AddEnumerationsCommand(getText(), st, getId(), index);
        } else if (// Support for Complex Type's simple Content with enumerations
        selection instanceof XSDComplexTypeDefinition) {
            st = (XSDSimpleTypeDefinition) ((XSDComplexTypeDefinition) selection).getContent();
            command = new AddEnumerationsCommand(getText(), st);
        } else // null
        {
            return;
        }
        List enumList = st.getEnumerationFacets();
        // $NON-NLS-1$
        String newName = XSDCommonUIUtils.createUniqueEnumerationValue("value", enumList);
        command.setValue(newName);
        getCommandStack().execute(command);
        addedComponent = command.getAddedComponent();
        Adapter adapter = XSDAdapterFactory.getInstance().adapt(addedComponent);
        selectAddedComponent(adapter);
    }
}
Also used : XSDEnumerationFacet(org.eclipse.xsd.XSDEnumerationFacet) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) XSDBaseAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter) List(java.util.List) XSDComplexTypeDefinitionAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDComplexTypeDefinitionAdapter) Adapter(org.eclipse.emf.common.notify.Adapter) XSDBaseAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) AddEnumerationsCommand(org.eclipse.wst.xsd.ui.internal.common.commands.AddEnumerationsCommand)

Example 65 with XSDComplexTypeDefinition

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

the class RedefineComplexTypeCommand method doExecute.

protected void doExecute() {
    XSDComplexTypeDefinition redefinedComplexTypeDefinition = XSDFactory.eINSTANCE.createXSDComplexTypeDefinition();
    redefinedComplexTypeDefinition.setName(redefinableComponent.getName());
    redefinedComplexTypeDefinition.setContent(XSDFactory.eINSTANCE.createXSDComplexTypeDefinition().getContent());
    redefinedComplexTypeDefinition.setDerivationMethod(XSDDerivationMethod.EXTENSION_LITERAL);
    redefinedComplexTypeDefinition.setBaseTypeDefinition((XSDComplexTypeDefinition) redefinableComponent);
    addedXSDConcreteComponent = redefinedComplexTypeDefinition;
}
Also used : XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition)

Aggregations

XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)162 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)93 XSDModelGroup (org.eclipse.xsd.XSDModelGroup)76 XSDParticle (org.eclipse.xsd.XSDParticle)75 XSDTypeDefinition (org.eclipse.xsd.XSDTypeDefinition)66 XSDSimpleTypeDefinition (org.eclipse.xsd.XSDSimpleTypeDefinition)53 ArrayList (java.util.ArrayList)43 XSDSchema (org.eclipse.xsd.XSDSchema)37 Test (org.junit.Test)37 EList (org.eclipse.emf.common.util.EList)25 XSDConcreteComponent (org.eclipse.xsd.XSDConcreteComponent)25 XSDFactory (org.eclipse.xsd.XSDFactory)23 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)22 XSDIdentityConstraintDefinition (org.eclipse.xsd.XSDIdentityConstraintDefinition)21 XSDTerm (org.eclipse.xsd.XSDTerm)21 XSDAnnotation (org.eclipse.xsd.XSDAnnotation)20 XSDComplexTypeContent (org.eclipse.xsd.XSDComplexTypeContent)20 Iterator (java.util.Iterator)19 List (java.util.List)19 XSDAttributeGroupDefinition (org.eclipse.xsd.XSDAttributeGroupDefinition)16