Search in sources :

Example 6 with XSDWildcard

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

the class AddXSDAnyElementCommand method execute.

public void execute() {
    try {
        if (doCreateModelGroupForComplexType) {
            Assert.isNotNull(complexType);
            beginRecording(complexType.getElement());
            createModelGroup();
        } else {
            beginRecording(parent.getElement());
        }
        XSDWildcard wildCard = XSDFactory.eINSTANCE.createXSDWildcard();
        XSDParticle particle = XSDFactory.eINSTANCE.createXSDParticle();
        particle.setContent(wildCard);
        parent.getContents().add(particle);
        addedXSDConcreteComponent = wildCard;
        formatChild(parent.getElement());
    } finally {
        endRecording();
    }
}
Also used : XSDWildcard(org.eclipse.xsd.XSDWildcard) XSDParticle(org.eclipse.xsd.XSDParticle)

Example 7 with XSDWildcard

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

the class XSDAnyElementContentsSection method doWidgetSelected.

public void doWidgetSelected(SelectionEvent e) {
    XSDConcreteComponent concreteComponent = (XSDConcreteComponent) input;
    if (concreteComponent instanceof XSDWildcard) {
        XSDWildcard wildcard = (XSDWildcard) concreteComponent;
        if (e.widget == namespaceCombo) {
            String newValue = namespaceCombo.getText();
            boolean removeAttribute = false;
            if (newValue.length() == 0) {
                removeAttribute = true;
            }
            // element); //$NON-NLS-1$
            if (removeAttribute) {
                wildcard.unsetLexicalNamespaceConstraint();
            } else {
                wildcard.setStringLexicalNamespaceConstraint(newValue);
            }
        // endRecording(element);
        } else if (e.widget == processContentsCombo) {
            String newValue = processContentsCombo.getText();
            boolean removeAttribute = false;
            if (newValue.length() == 0) {
                removeAttribute = true;
            }
            // element); //$NON-NLS-1$
            if (removeAttribute) {
                wildcard.unsetProcessContents();
            } else {
                wildcard.setProcessContents(XSDProcessContents.get(processContentsCombo.getItem(processContentsCombo.getSelectionIndex())));
            }
        // endRecording(element);
        }
    }
    super.doWidgetSelected(e);
}
Also used : XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) XSDWildcard(org.eclipse.xsd.XSDWildcard)

Example 8 with XSDWildcard

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

the class XSDCommonUIUtils method getInputXSDAnnotation.

public static XSDAnnotation getInputXSDAnnotation(XSDConcreteComponent input, boolean createIfNotExist) {
    XSDAnnotation xsdAnnotation = null;
    XSDFactory factory = XSDFactory.eINSTANCE;
    if (input instanceof XSDAttributeDeclaration) {
        XSDAttributeDeclaration xsdComp = (XSDAttributeDeclaration) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDAttributeGroupDefinition) {
        XSDAttributeGroupDefinition xsdComp = (XSDAttributeGroupDefinition) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDElementDeclaration) {
        XSDElementDeclaration xsdComp = (XSDElementDeclaration) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDNotationDeclaration) {
        XSDNotationDeclaration xsdComp = (XSDNotationDeclaration) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDXPathDefinition) {
        XSDXPathDefinition xsdComp = (XSDXPathDefinition) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDModelGroup) {
        XSDModelGroup xsdComp = (XSDModelGroup) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDModelGroupDefinition) {
        XSDModelGroupDefinition xsdComp = (XSDModelGroupDefinition) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDIdentityConstraintDefinition) {
        XSDIdentityConstraintDefinition xsdComp = (XSDIdentityConstraintDefinition) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDWildcard) {
        XSDWildcard xsdComp = (XSDWildcard) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDSchema) {
        XSDSchema xsdComp = (XSDSchema) input;
        List list = xsdComp.getAnnotations();
        if (list.size() > 0) {
            xsdAnnotation = (XSDAnnotation) list.get(0);
        } else {
            if (createIfNotExist && xsdAnnotation == null) {
                xsdAnnotation = factory.createXSDAnnotation();
                if (xsdComp.getContents() != null) {
                    xsdComp.getContents().add(0, xsdAnnotation);
                }
            }
        }
        return xsdAnnotation;
    } else if (input instanceof XSDFacet) {
        XSDFacet xsdComp = (XSDFacet) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDTypeDefinition) {
        XSDTypeDefinition xsdComp = (XSDTypeDefinition) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDInclude) {
        XSDInclude xsdComp = (XSDInclude) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDImport) {
        XSDImport xsdComp = (XSDImport) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDRedefine) {
        XSDRedefine xsdComp = (XSDRedefine) input;
        List contents = xsdComp.getContents();
        for (int i = 0; i < contents.size(); i++) {
            Object content = contents.get(i);
            if (content instanceof XSDAnnotation) {
                xsdAnnotation = (XSDAnnotation) content;
                break;
            }
        }
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            contents.add(0, xsdAnnotation);
        }
        return xsdAnnotation;
    } else if (input instanceof XSDAnnotation) {
        xsdAnnotation = (XSDAnnotation) input;
    }
    if (createIfNotExist) {
        formatAnnotation(xsdAnnotation);
    }
    return xsdAnnotation;
}
Also used : XSDFactory(org.eclipse.xsd.XSDFactory) XSDRedefine(org.eclipse.xsd.XSDRedefine) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDWildcard(org.eclipse.xsd.XSDWildcard) XSDAttributeGroupDefinition(org.eclipse.xsd.XSDAttributeGroupDefinition) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition) XSDNotationDeclaration(org.eclipse.xsd.XSDNotationDeclaration) XSDFacet(org.eclipse.xsd.XSDFacet) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDIdentityConstraintDefinition(org.eclipse.xsd.XSDIdentityConstraintDefinition) List(java.util.List) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList) EObject(org.eclipse.emf.ecore.EObject) XSDModelGroupDefinition(org.eclipse.xsd.XSDModelGroupDefinition) XSDImport(org.eclipse.xsd.XSDImport) XSDAnnotation(org.eclipse.xsd.XSDAnnotation) XSDXPathDefinition(org.eclipse.xsd.XSDXPathDefinition) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration) XSDSchema(org.eclipse.xsd.XSDSchema) XSDInclude(org.eclipse.xsd.XSDInclude)

Example 9 with XSDWildcard

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

the class XSDWildcardAdapter method getText.

public String getText() {
    XSDWildcard xsdWildcard = (XSDWildcard) target;
    StringBuffer result = new StringBuffer();
    Element element = xsdWildcard.getElement();
    if (element != null) {
        result.append(element.getNodeName());
        boolean hasMinOccurs = element.hasAttribute(XSDConstants.MINOCCURS_ATTRIBUTE);
        boolean hasMaxOccurs = element.hasAttribute(XSDConstants.MAXOCCURS_ATTRIBUTE);
        if (hasMinOccurs || hasMaxOccurs) {
            // $NON-NLS-1$
            result.append(" [");
            if (hasMinOccurs) {
                int min = ((XSDParticle) xsdWildcard.getContainer()).getMinOccurs();
                if (min == XSDParticle.UNBOUNDED) {
                    // $NON-NLS-1$
                    result.append("*");
                } else {
                    result.append(String.valueOf(min));
                }
            } else // print default
            {
                int min = ((XSDParticle) xsdWildcard.getContainer()).getMinOccurs();
                result.append(String.valueOf(min));
            }
            if (hasMaxOccurs) {
                int max = ((XSDParticle) xsdWildcard.getContainer()).getMaxOccurs();
                // $NON-NLS-1$
                result.append("..");
                if (max == XSDParticle.UNBOUNDED) {
                    // $NON-NLS-1$
                    result.append("*");
                } else {
                    result.append(String.valueOf(max));
                }
            } else // print default
            {
                // $NON-NLS-1$
                result.append("..");
                int max = ((XSDParticle) xsdWildcard.getContainer()).getMaxOccurs();
                result.append(String.valueOf(max));
            }
            // $NON-NLS-1$
            result.append("]");
        }
    }
    return result.toString();
}
Also used : IGraphElement(org.eclipse.wst.xsd.ui.internal.adt.design.editparts.model.IGraphElement) Element(org.w3c.dom.Element) XSDWildcard(org.eclipse.xsd.XSDWildcard) XSDParticle(org.eclipse.xsd.XSDParticle)

Example 10 with XSDWildcard

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

the class XSDAttributeDragAndDropCommand method doDrop.

protected void doDrop(List siblings, GraphicalEditPart movingEditPart) {
    commonSetup(siblings, movingEditPart);
    if ((previousRefComponent instanceof XSDAttributeDeclaration || previousRefComponent instanceof XSDWildcard) && (nextRefComponent instanceof XSDAttributeDeclaration || nextRefComponent instanceof XSDWildcard)) {
        XSDConcreteComponent parent = previousRefComponent.getContainer().getContainer();
        if (closerSibling == BELOW_IS_CLOSER) {
            parent = nextRefComponent.getContainer().getContainer();
        }
        action = new MoveXSDAttributeAction(parent, xsdComponentToDrag, previousRefComponent, nextRefComponent);
    } else if (previousRefComponent == null && (nextRefComponent instanceof XSDAttributeDeclaration || nextRefComponent instanceof XSDWildcard)) {
        XSDConcreteComponent parent = nextRefComponent.getContainer().getContainer();
        if (closerSibling == ABOVE_IS_CLOSER) {
            if (leftSiblingEditPart == null) {
                action = new MoveXSDAttributeAction(parent, xsdComponentToDrag, previousRefComponent, nextRefComponent);
            } else if (parentEditPart != null) {
                action = new MoveXSDAttributeAction(parentEditPart.getXSDConcreteComponent(), xsdComponentToDrag, previousRefComponent, nextRefComponent);
            }
        } else {
            action = new MoveXSDAttributeAction(parent, xsdComponentToDrag, previousRefComponent, nextRefComponent);
        }
    } else if (previousRefComponent instanceof XSDAttributeDeclaration && nextRefComponent == null) {
        XSDConcreteComponent parent = previousRefComponent.getContainer().getContainer();
        if (closerSibling == ABOVE_IS_CLOSER) {
            action = new MoveXSDAttributeAction(parent, xsdComponentToDrag, previousRefComponent, nextRefComponent);
        } else {
            if (rightSiblingEditPart == null) {
                action = new MoveXSDAttributeAction(parent, xsdComponentToDrag, previousRefComponent, nextRefComponent);
            } else {
                action = new MoveXSDAttributeAction(parent, xsdComponentToDrag, previousRefComponent, nextRefComponent);
            }
        }
    }
    if (action != null)
        canExecute = action.canMove();
}
Also used : MoveXSDAttributeAction(org.eclipse.wst.xsd.ui.internal.actions.MoveXSDAttributeAction) XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) XSDWildcard(org.eclipse.xsd.XSDWildcard) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration)

Aggregations

XSDWildcard (org.eclipse.xsd.XSDWildcard)25 XSDModelGroup (org.eclipse.xsd.XSDModelGroup)16 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)15 XSDParticle (org.eclipse.xsd.XSDParticle)13 ArrayList (java.util.ArrayList)10 Iterator (java.util.Iterator)10 EList (org.eclipse.emf.common.util.EList)10 XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)9 XSDAttributeGroupDefinition (org.eclipse.xsd.XSDAttributeGroupDefinition)8 XSDAttributeUse (org.eclipse.xsd.XSDAttributeUse)8 XSDTerm (org.eclipse.xsd.XSDTerm)8 List (java.util.List)7 XSDTypeDefinition (org.eclipse.xsd.XSDTypeDefinition)7 XSDAttributeDeclaration (org.eclipse.xsd.XSDAttributeDeclaration)6 XSDModelGroupDefinition (org.eclipse.xsd.XSDModelGroupDefinition)6 XSDSimpleTypeDefinition (org.eclipse.xsd.XSDSimpleTypeDefinition)6 XSDAnnotation (org.eclipse.xsd.XSDAnnotation)5 XSDConcreteComponent (org.eclipse.xsd.XSDConcreteComponent)5 TreeObject (com.amalto.workbench.models.TreeObject)4 XSDIdentityConstraintDefinition (org.eclipse.xsd.XSDIdentityConstraintDefinition)4