Search in sources :

Example 31 with XSDParticle

use of org.eclipse.xsd.XSDParticle in project tmdm-studio-se by Talend.

the class XSDNewParticleFromParticleAction method widgetSelected.

public void widgetSelected(SelectionEvent e) {
    if (dialog.getReturnCode() == -1)
        // there was a validation error
        return;
    elementName = dialog.getElementName();
    refName = dialog.getRefName();
    minOccurs = dialog.getMinOccurs();
    maxOccurs = dialog.getMaxOccurs();
    // check that this element does not already exist
    XSDModelGroup group = (XSDModelGroup) selParticle.getContainer();
    // get position of the selected particle in the container
    for (Iterator<XSDParticle> iter = group.getContents().iterator(); iter.hasNext(); ) {
        XSDParticle p = (XSDParticle) iter.next();
        if (p.getTerm() instanceof XSDElementDeclaration) {
            XSDElementDeclaration thisDecl = (XSDElementDeclaration) p.getTerm();
            if (thisDecl.getName().equals(elementName)) {
                MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages._TheBusinessElement, elementName));
                return;
            }
        }
    }
    // for
    dialog.close();
}
Also used : XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDParticle(org.eclipse.xsd.XSDParticle)

Example 32 with XSDParticle

use of org.eclipse.xsd.XSDParticle in project tmdm-studio-se by Talend.

the class XSDNewParticleFromTypeAction method doAction.

@Override
public IStatus doAction() {
    try {
        IStructuredSelection selection = (IStructuredSelection) page.getTreeViewer().getSelection();
        if (selection.getFirstElement() instanceof XSDComplexTypeDefinition) {
            ctd = (XSDComplexTypeDefinition) selection.getFirstElement();
            if (!(ctd.getContent() instanceof XSDParticle)) {
                return Status.CANCEL_STATUS;
            }
            if (!(((XSDParticle) ctd.getContent()).getTerm() instanceof XSDModelGroup)) {
                return Status.CANCEL_STATUS;
            }
            ;
            group = (XSDModelGroup) ((XSDParticle) ctd.getContent()).getTerm();
        } else if (selection.getFirstElement() instanceof XSDParticle) {
            group = (XSDModelGroup) ((XSDParticle) selection.getFirstElement()).getTerm();
        } else if (selection.getFirstElement() instanceof XSDModelGroup) {
            group = (XSDModelGroup) selection.getFirstElement();
        } else {
            log.info(Messages.bind(Messages._UnkownSection, selection.getFirstElement().getClass().getName(), selection.getFirstElement().toString()));
            return Status.CANCEL_STATUS;
        }
        EList<XSDElementDeclaration> eDecls = schema.getElementDeclarations();
        List<String> elementDeclarations = new LinkedList<String>();
        for (XSDElementDeclaration xsdElementDeclaration : eDecls) {
            XSDElementDeclaration d = xsdElementDeclaration;
            if (d.getTargetNamespace() != null && d.getTargetNamespace().equals(IConstants.DEFAULT_NAME_SPACE)) {
                continue;
            }
            // $NON-NLS-1$//$NON-NLS-2$
            elementDeclarations.add(d.getQName() + (d.getTargetNamespace() != null ? " : " + d.getTargetNamespace() : ""));
        }
        // $NON-NLS-1$
        elementDeclarations.add("");
        dialog = new BusinessElementInputDialog(this, page.getSite().getShell(), Messages._AddANewBusinessElement, "", "", elementDeclarations, 0, 1, true, // $NON-NLS-1$//$NON-NLS-2$;
        false);
        dialog.setBlockOnOpen(true);
        int ret = dialog.open();
        if (ret == Dialog.CANCEL) {
            return Status.CANCEL_STATUS;
        }
        XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory();
        XSDElementDeclaration decl = factory.createXSDElementDeclaration();
        decl.setName(this.elementName);
        // simpleTypeName));
        if (!refName.equals("")) {
            // $NON-NLS-1$
            XSDElementDeclaration ref = Util.findReference(refName, schema);
            if (ref != null) {
                decl.setResolvedElementDeclaration(ref);
            }
        } else {
            decl.setTypeDefinition(schema.resolveSimpleTypeDefinition(schema.getSchemaForSchemaNamespace(), simpleTypeName));
        }
        XSDParticle particle = factory.createXSDParticle();
        particle.setContent(decl);
        particle.setMinOccurs(this.minOccurs);
        particle.setMaxOccurs(this.maxOccurs);
        group.getContents().add(group.getContents().size(), particle);
        group.updateElement();
        if (Util.changeElementTypeToSequence(decl, maxOccurs) == Status.CANCEL_STATUS) {
            return Status.CANCEL_STATUS;
        }
        if (dialog.isInherit()) {
            XSDTerm totm = particle.getTerm();
            XSDElementDeclaration concept = null;
            Object obj = Util.getParent(particle);
            if (obj instanceof XSDElementDeclaration) {
                concept = (XSDElementDeclaration) obj;
            } else {
                concept = (XSDElementDeclaration) particle.getContent();
            }
            XSDAnnotation fromannotation = null;
            if (concept != null) {
                fromannotation = concept.getAnnotation();
            }
            if (fromannotation != null) {
                XSDAnnotationsStructure struc = new XSDAnnotationsStructure(totm);
                if (((XSDElementDeclaration) totm).getType() != null) {
                    addAnnotion(struc, fromannotation);
                }
            }
        }
        page.refresh();
        page.getTreeViewer().setSelection(new StructuredSelection(particle), true);
        page.markDirty();
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages._ErrorCreatBusinessElement, e.getLocalizedMessage()));
        return Status.CANCEL_STATUS;
    }
    return Status.OK_STATUS;
}
Also used : XSDFactory(org.eclipse.xsd.XSDFactory) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDAnnotationsStructure(com.amalto.workbench.utils.XSDAnnotationsStructure) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) LinkedList(java.util.LinkedList) BusinessElementInputDialog(com.amalto.workbench.dialogs.BusinessElementInputDialog) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDTerm(org.eclipse.xsd.XSDTerm) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDAnnotation(org.eclipse.xsd.XSDAnnotation) XSDParticle(org.eclipse.xsd.XSDParticle)

Example 33 with XSDParticle

use of org.eclipse.xsd.XSDParticle in project tmdm-studio-se by Talend.

the class XSDPasteConceptAction method addAnnotationForXSDElementDeclaration.

public void addAnnotationForXSDElementDeclaration(XSDElementDeclaration fromElem, XSDElementDeclaration toElem) {
    if (fromElem.getAnnotation() != null) {
        // toElem.setAnnotation(cloneXSDAnnotation(toElem.getAnnotation(),fromElem.getAnnotation()));
        XSDAnnotationsStructure struc = new XSDAnnotationsStructure(toElem);
        addAnnotion(struc, fromElem.getAnnotation());
    }
    if (fromElem.getTypeDefinition() instanceof XSDComplexTypeDefinition) {
        XSDComplexTypeContent fromcomplexType = ((XSDComplexTypeDefinition) fromElem.getTypeDefinition()).getContent();
        // in this situation,if not copy the complex type, the type change to simple type
        if (this.typeList.containsKey(toElem.getTypeDefinition().getName())) {
            this.copyTypeSet.add(this.typeList.get(toElem.getTypeDefinition().getName()));
        }
        if (toElem.getTypeDefinition() instanceof XSDComplexTypeDefinition) {
            XSDComplexTypeContent tocomplexType = ((XSDComplexTypeDefinition) toElem.getTypeDefinition()).getContent();
            if (fromcomplexType instanceof XSDParticle) {
                XSDParticle fromxsdParticle = (XSDParticle) fromcomplexType;
                XSDParticle toxsdParticle = (XSDParticle) tocomplexType;
                if (fromxsdParticle.getTerm() instanceof XSDModelGroup) {
                    XSDModelGroup frommodelGroup = ((XSDModelGroup) fromxsdParticle.getTerm());
                    XSDModelGroup tomodelGroup = ((XSDModelGroup) toxsdParticle.getTerm());
                    EList<XSDParticle> fromlist = frommodelGroup.getContents();
                    EList<XSDParticle> tolist = tomodelGroup.getContents();
                    Iterator<XSDParticle> toIt = tolist.iterator();
                    for (XSDParticle fromel : fromlist.toArray(new XSDParticle[fromlist.size()])) {
                        XSDParticle toel = toIt.next();
                        XSDTerm totm = toel.getTerm();
                        XSDTerm fromtm = fromel.getTerm();
                        if (fromtm instanceof XSDElementDeclaration) {
                            XSDAnnotation fromannotation = ((XSDElementDeclaration) fromtm).getAnnotation();
                            if (fromannotation != null) {
                                // ((XSDElementDeclaration)
                                // totm).setAnnotation(cloneXSDAnnotation(((XSDElementDeclaration)
                                // totm).getAnnotation(),fromannotation));
                                XSDAnnotationsStructure struc = new XSDAnnotationsStructure(totm);
                                if (((XSDElementDeclaration) totm).getType() != null) {
                                    addAnnotion(struc, fromannotation);
                                } else {
                                    MessageDialog.openInformation(page.getSite().getShell(), Messages.Warning, Messages.bind(Messages.XSDPasteConceptAction_Information, fromElem.getName()));
                                    return;
                                }
                            }
                            if (((XSDElementDeclaration) totm).getType() != null && this.typeList.containsKey(((XSDElementDeclaration) totm).getType().getName())) {
                                this.copyTypeSet.add(this.typeList.get(((XSDElementDeclaration) totm).getType().getName()));
                            }
                            addAnnotationForXSDElementDeclaration((XSDElementDeclaration) fromtm, (XSDElementDeclaration) totm);
                        }
                    }
                }
            }
        }
    } else {
        String simpleType = fromElem.getTypeDefinition().getName();
        if (this.typeList.containsKey(simpleType)) {
            this.copyTypeSet.add(fromElem.getTypeDefinition());
        }
    }
}
Also used : XSDAnnotationsStructure(com.amalto.workbench.utils.XSDAnnotationsStructure) XSDComplexTypeContent(org.eclipse.xsd.XSDComplexTypeContent) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDTerm(org.eclipse.xsd.XSDTerm) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDAnnotation(org.eclipse.xsd.XSDAnnotation) XSDParticle(org.eclipse.xsd.XSDParticle)

Example 34 with XSDParticle

use of org.eclipse.xsd.XSDParticle in project tmdm-studio-se by Talend.

the class XSDPasteConceptAction method isExist.

public boolean isExist(XSDModelGroup toGroup, XSDParticle particle) {
    for (XSDParticle paticleContent : toGroup.getContents()) {
        if (paticleContent.getTerm() instanceof XSDElementDeclaration) {
            String contentName = ((XSDElementDeclaration) paticleContent.getTerm()).getName();
            String copyParticleName = ((XSDElementDeclaration) particle.getTerm()).getName();
            if (contentName.equals(copyParticleName)) {
                return true;
            }
        }
    }
    return false;
}
Also used : XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDParticle(org.eclipse.xsd.XSDParticle)

Example 35 with XSDParticle

use of org.eclipse.xsd.XSDParticle in project tmdm-studio-se by Talend.

the class XSDNewComplexTypeDefinition method checkParentType.

private boolean checkParentType(XSDTypeDefinition superType, XSDModelGroup currentGroup) {
    XSDParticle complexType = superType.getComplexType();
    XSDTerm term = complexType.getTerm();
    if (term instanceof XSDModelGroup) {
        XSDModelGroup group = (XSDModelGroup) term;
        if (group.getCompositor() == XSDCompositor.ALL_LITERAL) {
            if (MessageDialog.openConfirm(null, Messages._ChangeToSequenceType, Messages._ComplexTypeToSequence)) {
                group.setCompositor(XSDCompositor.SEQUENCE_LITERAL);
                complexType.updateElement();
                currentGroup.setCompositor(XSDCompositor.SEQUENCE_LITERAL);
                currentGroup.updateElement();
                return true;
            }
            return false;
        }
    }
    return true;
}
Also used : XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDTerm(org.eclipse.xsd.XSDTerm) XSDParticle(org.eclipse.xsd.XSDParticle)

Aggregations

XSDParticle (org.eclipse.xsd.XSDParticle)146 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)103 XSDModelGroup (org.eclipse.xsd.XSDModelGroup)93 XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)75 XSDTypeDefinition (org.eclipse.xsd.XSDTypeDefinition)36 ArrayList (java.util.ArrayList)34 XSDSimpleTypeDefinition (org.eclipse.xsd.XSDSimpleTypeDefinition)34 XSDTerm (org.eclipse.xsd.XSDTerm)31 XSDFactory (org.eclipse.xsd.XSDFactory)27 XSDComplexTypeContent (org.eclipse.xsd.XSDComplexTypeContent)24 XSDSchema (org.eclipse.xsd.XSDSchema)24 Test (org.junit.Test)23 Iterator (java.util.Iterator)21 XSDAnnotation (org.eclipse.xsd.XSDAnnotation)21 XSDIdentityConstraintDefinition (org.eclipse.xsd.XSDIdentityConstraintDefinition)19 EList (org.eclipse.emf.common.util.EList)17 XSDParticleContent (org.eclipse.xsd.XSDParticleContent)17 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)16 Element (org.w3c.dom.Element)16 List (java.util.List)15