Search in sources :

Example 6 with XSDAnnotation

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

the class DataModelMainPage method getElementType.

private int getElementType(Object decl) {
    if (Util.getParent(decl) == decl) {
        if (Util.checkConcept((XSDElementDeclaration) decl)) {
            return 0;
        }
        return 1;
    }
    if (decl instanceof XSDComplexTypeDefinition) {
        return 2;
    }
    if (decl instanceof XSDIdentityConstraintDefinition) {
        return 3;
    }
    if (decl instanceof XSDXPathDefinition) {
        return 4;
    }
    if (decl instanceof XSDSimpleTypeDefinition) {
        return 5;
    }
    if (decl instanceof XSDAnnotation) {
        return 6;
    }
    if (decl instanceof XSDParticle) {
        return 7;
    }
    if (decl instanceof XSDModelGroup) {
        return 8;
    }
    if (decl instanceof XSDWhiteSpaceFacet) {
        return 201;
    }
    if (decl instanceof XSDLengthFacet) {
        return 202;
    }
    if (decl instanceof XSDMinLengthFacet) {
        return 203;
    }
    if (decl instanceof XSDMaxLengthFacet) {
        return 204;
    }
    if (decl instanceof XSDTotalDigitsFacet) {
        return 205;
    }
    if (decl instanceof XSDFractionDigitsFacet) {
        return 206;
    }
    if (decl instanceof XSDMaxInclusiveFacet) {
        return 207;
    }
    if (decl instanceof XSDMaxExclusiveFacet) {
        return 208;
    }
    if (decl instanceof XSDMinInclusiveFacet) {
        return 209;
    }
    if (decl instanceof XSDMinExclusiveFacet) {
        return 210;
    }
    if (decl instanceof XSDPatternFacet) {
        return 211;
    }
    if (decl instanceof XSDEnumerationFacet) {
        return 212;
    }
    if (decl instanceof Element) {
        Element e = (Element) decl;
        if (e.getLocalName().equals("appinfo")) {
        // $NON-NLS-1$
        }
        // $NON-NLS-1$
        String source = e.getAttribute("source");
        if (source != null) {
            if (source.startsWith("X_Label_")) {
                // $NON-NLS-1$
                return 101;
            } else if (source.equals("X_ForeignKey")) {
                // $NON-NLS-1$
                return 102;
            } else if (source.equals("X_ForeignKeyInfo")) {
                // $NON-NLS-1$
                return 103;
            } else if (source.equals("X_SourceSystem")) {
                // $NON-NLS-1$
                return 104;
            } else if (source.equals("X_TargetSystem")) {
                // $NON-NLS-1$
                return 105;
            } else if (source.startsWith("X_Description_")) {
                // $NON-NLS-1$
                return 106;
            } else if (source.equals("X_Write")) {
                // $NON-NLS-1$
                return 107;
            } else if (source.equals("X_Hide")) {
                // $NON-NLS-1$
                return 108;
            } else if (source.equals("X_Schematron")) {
                // $NON-NLS-1$
                return 109;
            } else if (source.startsWith("X_Facet_")) {
                // $NON-NLS-1$
                return 110;
            } else if (source.startsWith("X_Workflow")) {
                // $NON-NLS-1$
                return 111;
            } else if (source.startsWith("X_ForeignKey_Filter")) {
                // $NON-NLS-1$
                return 112;
            } else if (source.startsWith("X_Display_Format_")) {
                // $NON-NLS-1$
                return 113;
            } else if (source.equals("X_Lookup_Field")) {
                // $NON-NLS-1$
                return 114;
            } else if (source.equals("X_PrimaryKeyInfo")) {
                // $NON-NLS-1$
                return 115;
            } else if (source.equals("X_Visible_Rule")) {
                // $NON-NLS-1$
                return 116;
            } else if (source.equals("X_Default_Value_Rule")) {
                // $NON-NLS-1$
                return 117;
            } else if (source.equals("X_Deny_Create")) {
                // $NON-NLS-1$
                return 118;
            } else if (source.equals("X_Deny_PhysicalDelete")) {
                // $NON-NLS-1$
                return 119;
            } else if (source.equals("X_Deny_LogicalDelete")) {
                // $NON-NLS-1$
                return 120;
            } else if (source.equals("X_FKIntegrity")) {
                // $NON-NLS-1$
                return 121;
            } else if (source.equals("X_FKIntegrity_Override")) {
                // $NON-NLS-1$
                return 122;
            } else if (source.equals("X_ForeignKeyInfoFormat")) {
                // $NON-NLS-1$
                return 123;
            }
        }
    }
    return -1;
}
Also used : XSDPatternFacet(org.eclipse.xsd.XSDPatternFacet) XSDMinInclusiveFacet(org.eclipse.xsd.XSDMinInclusiveFacet) XSDFractionDigitsFacet(org.eclipse.xsd.XSDFractionDigitsFacet) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) XSDWhiteSpaceFacet(org.eclipse.xsd.XSDWhiteSpaceFacet) Element(org.w3c.dom.Element) XSDLengthFacet(org.eclipse.xsd.XSDLengthFacet) XSDMaxExclusiveFacet(org.eclipse.xsd.XSDMaxExclusiveFacet) XSDEnumerationFacet(org.eclipse.xsd.XSDEnumerationFacet) XSDTotalDigitsFacet(org.eclipse.xsd.XSDTotalDigitsFacet) XSDIdentityConstraintDefinition(org.eclipse.xsd.XSDIdentityConstraintDefinition) XSDMinLengthFacet(org.eclipse.xsd.XSDMinLengthFacet) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDXPathDefinition(org.eclipse.xsd.XSDXPathDefinition) XSDAnnotation(org.eclipse.xsd.XSDAnnotation) XSDMaxLengthFacet(org.eclipse.xsd.XSDMaxLengthFacet) XSDMaxInclusiveFacet(org.eclipse.xsd.XSDMaxInclusiveFacet) XSDMinExclusiveFacet(org.eclipse.xsd.XSDMinExclusiveFacet) XSDParticle(org.eclipse.xsd.XSDParticle)

Example 7 with XSDAnnotation

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

the class FKIntegrityComposite method refresh.

private void refresh() {
    XSDAnnotation annotation = xsdComponent.getAnnotation();
    if (annotation == null) {
        annotation = XSDFactory.eINSTANCE.createXSDAnnotation();
    }
    Element fkIntegrityElement = null;
    Element fkIntegrityOverrideElement = null;
    EList<Element> appInfo = annotation.getApplicationInformation();
    for (Element currentElement : appInfo) {
        // $NON-NLS-1$
        String source = currentElement.getAttribute("source");
        if (X_FK_INTEGRITY.endsWith(source)) {
            fkIntegrityElement = currentElement;
        } else if (X_FK_INTEGRITY_OVERRIDE.endsWith(source)) {
            fkIntegrityOverrideElement = currentElement;
        }
    }
    if (fkIntegrityElement != null) {
        String textContent = fkIntegrityElement.getTextContent();
        boolean enabled = textContent == null ? true : Boolean.valueOf(textContent);
        btnEnforceFkIntegrity.setSelection(enabled);
    } else {
        // default is true
        btnEnforceFkIntegrity.setSelection(true);
    }
    if (fkIntegrityOverrideElement != null) {
        String textContent = fkIntegrityOverrideElement.getTextContent();
        boolean enabled = textContent == null ? true : Boolean.valueOf(textContent);
        btnAllowFkIntegrity.setSelection(enabled);
    } else {
        // default is false for override
        btnAllowFkIntegrity.setSelection(false);
    }
    // refresh buttion enabled
    if (xsdComponent.getAnnotation() == null) {
        btnEnforceFkIntegrity.setEnabled(false);
        btnAllowFkIntegrity.setEnabled(false);
    } else {
        btnEnforceFkIntegrity.setEnabled(true);
        btnAllowFkIntegrity.setEnabled(btnEnforceFkIntegrity.getSelection());
    }
}
Also used : Element(org.w3c.dom.Element) XSDAnnotation(org.eclipse.xsd.XSDAnnotation)

Example 8 with XSDAnnotation

use of org.eclipse.xsd.XSDAnnotation 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 9 with XSDAnnotation

use of org.eclipse.xsd.XSDAnnotation 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 10 with XSDAnnotation

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

the class XSDPasteConceptAction method cloneXSDAnnotation.

public Map<String, List<String>> cloneXSDAnnotation(XSDAnnotation oldAnn) {
    XSDAnnotation xsdannotation = XSDFactory.eINSTANCE.createXSDAnnotation();
    Map<String, List<String>> infor = new HashMap<String, List<String>>();
    try {
        /*
             * List<Element> listAppInfo = new ArrayList<Element>(); List<Element> listUserInfo = new
             * ArrayList<Element>(); List<Attr> listAttri = new ArrayList<Attr>();
             */
        if (oldAnn != null) {
            for (int i = 0; i < oldAnn.getApplicationInformation().size(); i++) {
                Element oldElem = oldAnn.getApplicationInformation().get(i);
                // System.out.println(oldElem.getAttributes().getNamedItem(
                // "source").getNodeValue());
                String type = oldElem.getAttributes().getNamedItem(Messages.XSDPasteConceptAction_Source).getNodeValue();
                /*
                     * Element newElem = (Element) oldElem.cloneNode(true);
                     * listAppInfo.add(oldAnn.getApplicationInformation().get(i));
                     */
                if (!infor.containsKey(type)) {
                    List<String> typeList = new ArrayList<String>();
                    typeList.add(oldElem.getFirstChild().getNodeValue());
                    infor.put(type, typeList);
                } else {
                    infor.get(type).add(oldElem.getFirstChild().getNodeValue());
                }
            }
        /*
                 * xsdannotation.getApplicationInformation().addAll(listAppInfo);
                 *
                 * for (int i = 0; i < oldAnn.getUserInformation().size(); i++) { Element oldElemUserInfo =
                 * oldAnn.getUserInformation() .get(i); Element newElemUserInfo = (Element) oldElemUserInfo
                 * .cloneNode(true); listUserInfo.add(newElemUserInfo);
                 *
                 * } xsdannotation.getUserInformation().addAll(listUserInfo);
                 *
                 * for (int i = 0; i < oldAnn.getAttributes().size(); i++) { Attr oldAttri =
                 * oldAnn.getAttributes().get(i); Attr newAtri = (Attr) oldAttri.cloneNode(true);
                 * listAttri.add(newAtri); } xsdannotation.getAttributes().addAll(listAttri);
                 */
        }
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        MessageDialog.openError(this.page.getSite().getShell(), Messages._Error, Messages.bind(Messages.XSDPasteConceptAction_ErrorMsg2, e.getLocalizedMessage()));
    }
    return infor;
}
Also used : HashMap(java.util.HashMap) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList) List(java.util.List) XSDAnnotation(org.eclipse.xsd.XSDAnnotation)

Aggregations

XSDAnnotation (org.eclipse.xsd.XSDAnnotation)55 Element (org.w3c.dom.Element)33 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)28 XSDParticle (org.eclipse.xsd.XSDParticle)21 XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)20 XSDModelGroup (org.eclipse.xsd.XSDModelGroup)20 XSDAnnotationsStructure (com.amalto.workbench.utils.XSDAnnotationsStructure)17 ArrayList (java.util.ArrayList)16 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)16 XSDTerm (org.eclipse.xsd.XSDTerm)16 TreePath (org.eclipse.jface.viewers.TreePath)13 TreeSelection (org.eclipse.jface.viewers.TreeSelection)13 XSDComponent (org.eclipse.xsd.XSDComponent)13 XSDIdentityConstraintDefinition (org.eclipse.xsd.XSDIdentityConstraintDefinition)13 XSDSimpleTypeDefinition (org.eclipse.xsd.XSDSimpleTypeDefinition)12 XSDTypeDefinition (org.eclipse.xsd.XSDTypeDefinition)10 XSDXPathDefinition (org.eclipse.xsd.XSDXPathDefinition)10 EList (org.eclipse.emf.common.util.EList)9 XSDSchema (org.eclipse.xsd.XSDSchema)8 Iterator (java.util.Iterator)7