Search in sources :

Example 41 with XSDElementDeclaration

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

the class TreeExpandHelper method getExpandedEntityElements.

// ///
private Object[] getExpandedEntityElements(DataModelMainPage mainPage) {
    TreeViewer elementsViewer = mainPage.getElementsViewer();
    SchemaTreeContentProvider contentProvider = (SchemaTreeContentProvider) elementsViewer.getContentProvider();
    Object[] xsdDeclarations = getChildren(contentProvider.getXsdSchema(), contentProvider);
    // 
    List<Object> result = new ArrayList<Object>();
    // 
    Deque<ExpandInfoNode> nodeStack = new LinkedList<ExpandInfoNode>();
    // 
    Deque<Object> elementStack = new LinkedList<Object>();
    // record entities
    Map<ExpandInfoNode, XSDElementDeclaration> expandedRoots = new HashMap<ExpandInfoNode, XSDElementDeclaration>();
    for (Object obj : xsdDeclarations) {
        if (obj instanceof XSDElementDeclaration) {
            XSDElementDeclaration decl = (XSDElementDeclaration) obj;
            String name = decl.getName();
            for (ExpandInfoNode node : expandedElements) {
                if (name.equals(node.name)) {
                    expandedRoots.put(node, decl);
                    result.add(decl);
                    // /
                    nodeStack.add(node);
                    // /
                    elementStack.add(decl);
                    break;
                }
            }
        }
    }
    while (!nodeStack.isEmpty() && !elementStack.isEmpty()) {
        ExpandInfoNode node = nodeStack.pollFirst();
        Object element = elementStack.pollFirst();
        List<ExpandInfoNode> nodes = node.childs;
        Object[] elementChildren = getChildren(element, contentProvider);
        if (nodes != null && nodes.size() > 0 && elementChildren != null) {
            Map<ExpandInfoNode, Object> nodeElementPairs = getNodeElementPairs(elementChildren, nodes);
            for (ExpandInfoNode node2 : nodeElementPairs.keySet()) {
                nodeStack.add(node2);
                elementStack.add(nodeElementPairs.get(node2));
                result.add(nodeElementPairs.get(node2));
            }
        }
    }
    return result.toArray();
}
Also used : HashMap(java.util.HashMap) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) SchemaTreeContentProvider(com.amalto.workbench.providers.datamodel.SchemaTreeContentProvider) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration)

Example 42 with XSDElementDeclaration

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

the class UserVariableDialog method getUserFields.

private List<String> getUserFields() {
    try {
        if (schema != null) {
            XSDSchema xsd = Util.createXsdSchema(schema, null);
            List<String> results = new ArrayList<String>();
            EList<XSDElementDeclaration> elementDeclarations = xsd.getElementDeclarations();
            for (XSDElementDeclaration decl : elementDeclarations) {
                if (decl.getName().equals(USER)) {
                    // $NON-NLS-1$
                    Map<String, XSDParticle> childElements = Util.getChildElements("", decl, true, new HashSet<Object>());
                    for (String element : childElements.keySet()) {
                        // $NON-NLS-1$
                        String prefix = "//";
                        if (element.startsWith(prefix)) {
                            element = element.substring(prefix.length());
                        }
                        results.add(element);
                    }
                }
            }
            return results;
        }
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }
    return null;
}
Also used : XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) ArrayList(java.util.ArrayList) XSDParticle(org.eclipse.xsd.XSDParticle) XSDSchema(org.eclipse.xsd.XSDSchema)

Example 43 with XSDElementDeclaration

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

the class ElementInfoConfigComposite method refreshPK.

private void refreshPK() {
    if (curXSDParticle != null) {
        this.section.getTreeObject();
        XSDElementDeclaration decl = (XSDElementDeclaration) curXSDParticle.getContent();
        List<Object> keyInfo = Util.getKeyInfo(decl);
        boolean isPK = keyInfo != null && keyInfo.size() > 0;
        comboReference.setEnabled(!isPK);
        spinMin.setEnabled(!isPK);
        spinMax.setEnabled(!isPK);
    }
}
Also used : XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration)

Example 44 with XSDElementDeclaration

use of org.eclipse.xsd.XSDElementDeclaration 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 45 with XSDElementDeclaration

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

Aggregations

XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)222 XSDParticle (org.eclipse.xsd.XSDParticle)103 XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)93 XSDModelGroup (org.eclipse.xsd.XSDModelGroup)87 ArrayList (java.util.ArrayList)60 XSDTypeDefinition (org.eclipse.xsd.XSDTypeDefinition)57 XSDSchema (org.eclipse.xsd.XSDSchema)48 XSDSimpleTypeDefinition (org.eclipse.xsd.XSDSimpleTypeDefinition)47 Test (org.junit.Test)44 XSDIdentityConstraintDefinition (org.eclipse.xsd.XSDIdentityConstraintDefinition)38 XSDFactory (org.eclipse.xsd.XSDFactory)37 XSDTerm (org.eclipse.xsd.XSDTerm)32 XSDConcreteComponent (org.eclipse.xsd.XSDConcreteComponent)30 EList (org.eclipse.emf.common.util.EList)29 XSDAnnotation (org.eclipse.xsd.XSDAnnotation)28 Iterator (java.util.Iterator)27 XSDAttributeDeclaration (org.eclipse.xsd.XSDAttributeDeclaration)27 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)24 XSDXPathDefinition (org.eclipse.xsd.XSDXPathDefinition)21 Element (org.w3c.dom.Element)21