Search in sources :

Example 11 with XSDTerm

use of org.eclipse.xsd.XSDTerm 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 12 with XSDTerm

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

Example 13 with XSDTerm

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

the class XSDNewParticleFromParticleAction method doAction.

public IStatus doAction() {
    try {
        IStructuredSelection selection = (IStructuredSelection) page.getTreeViewer().getSelection();
        selParticle = (XSDParticle) selection.getFirstElement();
        if (!(selParticle.getContainer() instanceof XSDModelGroup))
            return Status.CANCEL_STATUS;
        ;
        XSDModelGroup group = (XSDModelGroup) selParticle.getContainer();
        // get position of the selected particle in the container
        int index = 0;
        int i = 0;
        for (Iterator<XSDParticle> iter = group.getContents().iterator(); iter.hasNext(); ) {
            XSDParticle p = (XSDParticle) iter.next();
            if (p.equals(selParticle)) {
                index = i;
                break;
            }
            i++;
        }
        EList<XSDElementDeclaration> eDecls = schema.getElementDeclarations();
        List<String> elementDeclarations = new ArrayList<String>();
        for (Iterator<XSDElementDeclaration> iter = eDecls.iterator(); iter.hasNext(); ) {
            XSDElementDeclaration d = (XSDElementDeclaration) iter.next();
            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, null, null, elementDeclarations, 0, 1, true, false);
        dialog.setBlockOnOpen(true);
        int ret = dialog.open();
        if (ret == Dialog.CANCEL) {
            return Status.CANCEL_STATUS;
        }
        XSDElementDeclaration elem = (XSDElementDeclaration) selParticle.getContent();
        if (Util.changeElementTypeToSequence(elem, maxOccurs) == Status.CANCEL_STATUS) {
            return Status.CANCEL_STATUS;
        }
        XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory();
        XSDElementDeclaration decl = factory.createXSDElementDeclaration();
        decl.setName(this.elementName);
        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);
        if (maxOccurs > -1) {
            particle.setMaxOccurs(this.maxOccurs);
        } else {
            particle.setMaxOccurs(this.maxOccurs);
            group.getContents().add(group.getContents().size(), particle);
            group.updateElement();
            if (// $NON-NLS-1$
            particle.getElement().getAttributeNode("maxOccurs") != null)
                // $NON-NLS-1$//$NON-NLS-2$
                particle.getElement().getAttributeNode("maxOccurs").setNodeValue("unbounded");
            else {
                // $NON-NLS-1$//$NON-NLS-2$
                particle.getElement().setAttribute("maxOccurs", "unbounded");
            }
        }
        if (maxOccurs > -1) {
            group.getContents().add(group.getContents().size(), particle);
            group.updateElement();
        }
        if (dialog.isInherit()) {
            XSDTerm totm = particle.getTerm();
            XSDElementDeclaration concept = null;
            if (Util.getParent(selParticle) instanceof XSDElementDeclaration)
                concept = (XSDElementDeclaration) Util.getParent(selParticle);
            else if (Util.getParent(selParticle) instanceof XSDComplexTypeDefinition) {
                if (selParticle instanceof XSDParticle)
                    concept = (XSDElementDeclaration) ((XSDParticle) selParticle).getContent();
                else if (selParticle instanceof XSDElementDeclaration)
                    concept = (XSDElementDeclaration) selParticle;
            }
            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) ArrayList(java.util.ArrayList) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) 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 14 with XSDTerm

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

the class XSDSkipToFKAction method run.

@Override
public void run() {
    TreeViewer treeViewer = page.getTreeViewer();
    ISelection selection = treeViewer.getSelection();
    Object selObj = ((IStructuredSelection) selection).getFirstElement();
    if (selObj instanceof XSDParticle) {
        XSDTerm term = ((XSDParticle) selObj).getTerm();
        if (term instanceof XSDElementDeclaration) {
            XSDElementDeclaration element = (XSDElementDeclaration) term;
            String fkPath = getFKInfo(element);
            if (fkPath == null) {
                MessageDialog.openInformation(null, Messages.XSDSkipToFKAction_actionTitle, Messages.XSDSkipToFKAction_NotFoundFkInfo);
                return;
            }
            String entityName = getEntityName(fkPath);
            EList<XSDElementDeclaration> elementDeclarations = page.getXSDSchema().getElementDeclarations();
            for (XSDElementDeclaration elementDeclaration : elementDeclarations) {
                String name = elementDeclaration.getName();
                if (entityName.equals(name)) {
                    StructuredSelection fkSelection = new StructuredSelection(elementDeclaration);
                    page.getElementsViewer().setSelection(fkSelection);
                    break;
                }
            }
        }
    }
}
Also used : TreeViewer(org.eclipse.jface.viewers.TreeViewer) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) ISelection(org.eclipse.jface.viewers.ISelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) XSDTerm(org.eclipse.xsd.XSDTerm) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) XSDParticle(org.eclipse.xsd.XSDParticle)

Example 15 with XSDTerm

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

the class XPathTreeContentProvider method getXSDParticleChildren.

private Object[] getXSDParticleChildren(XSDParticle particle) {
    // System.out.println("getXSDParticleChildren() CLASS "+particle.getClass().getName());
    // System.out.println("getXSDParticleChildren() TERM "+particle.getTerm().getClass().getName()+": "+particle.getTerm());
    XSDTerm term = particle.getTerm();
    if (term instanceof XSDElementDeclaration) {
        XSDTypeDefinition typeDef = ((XSDElementDeclaration) term).getTypeDefinition();
        if (typeDef == null)
            // elements with not type declaration (allowed)
            return new Object[0];
        ArrayList<Object> list = new ArrayList<Object>();
        if (typeDef instanceof XSDComplexTypeDefinition) {
            list.addAll(getComplexTypeDefinitionChildren((XSDComplexTypeDefinition) typeDef));
        } else {
            list.add(typeDef);
        }
        // }
        return list.toArray(new Object[list.size()]);
    }
    if (term instanceof XSDModelGroup) {
        // a ModelGroup skip it and get children directtly
        EList list = ((XSDModelGroup) term).getContents();
        return list.toArray(new XSDParticle[list.size()]);
    }
    if (term instanceof XSDWildcard) {
    }
    return new Object[] {};
}
Also used : EList(org.eclipse.emf.common.util.EList) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) ArrayList(java.util.ArrayList) XSDTerm(org.eclipse.xsd.XSDTerm) XSDWildcard(org.eclipse.xsd.XSDWildcard) TreeObject(com.amalto.workbench.models.TreeObject) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition)

Aggregations

XSDTerm (org.eclipse.xsd.XSDTerm)36 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)32 XSDParticle (org.eclipse.xsd.XSDParticle)31 XSDModelGroup (org.eclipse.xsd.XSDModelGroup)28 XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)21 XSDAnnotation (org.eclipse.xsd.XSDAnnotation)16 XSDTypeDefinition (org.eclipse.xsd.XSDTypeDefinition)13 XSDIdentityConstraintDefinition (org.eclipse.xsd.XSDIdentityConstraintDefinition)10 XSDSimpleTypeDefinition (org.eclipse.xsd.XSDSimpleTypeDefinition)10 TreeObject (com.amalto.workbench.models.TreeObject)9 ArrayList (java.util.ArrayList)9 EList (org.eclipse.emf.common.util.EList)9 XSDComplexTypeContent (org.eclipse.xsd.XSDComplexTypeContent)8 XSDWildcard (org.eclipse.xsd.XSDWildcard)8 XSDXPathDefinition (org.eclipse.xsd.XSDXPathDefinition)8 Iterator (java.util.Iterator)6 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)6 XSDAttributeGroupDefinition (org.eclipse.xsd.XSDAttributeGroupDefinition)6 Element (org.w3c.dom.Element)6 XSDAnnotationsStructure (com.amalto.workbench.utils.XSDAnnotationsStructure)5