Search in sources :

Example 1 with XSDIdentityConstraintDefinition

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

the class XpathSelectDialog method provideViwerContent.

// changeDomTree(
protected void provideViwerContent(XSDSchema xsdSchema, String filter) {
    drillDownAdapter = new DrillDownAdapter(domViewer);
    domViewer.setLabelProvider(new XSDTreeLabelProvider(selectionFilter));
    XPathTreeContentProvider provider = new XPathTreeContentProvider(this.site, xsdSchema, parent, filter);
    // filter the entity with the filter text but not the concept name.
    // provider.setConceptName(this.conceptName);
    domViewer.setContentProvider(provider);
    domViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent e) {
            StructuredSelection sel = (StructuredSelection) e.getSelection();
            xpath = getXpath(sel);
            xpathText.setText(xpath);
            boolean enable = false;
            if (selectionFilter == null) {
                enable = xpath.length() > 0;
            } else {
                enable = xpath.length() > 0 && (selectionFilter.check(sel.getFirstElement()) == FilterResult.ENABLE);
            }
            getButton(IDialogConstants.OK_ID).setEnabled(enable);
        }
    });
    domViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true));
    domViewer.setSorter(new ViewerSorter() {

        @Override
        public int category(Object element) {
            // SimpleTypeDefinition
            if (element instanceof XSDFacet) {
                return 100;
            }
            // unique keys after element declarations and before other keys
            if (element instanceof XSDIdentityConstraintDefinition) {
                XSDIdentityConstraintDefinition icd = (XSDIdentityConstraintDefinition) element;
                if (icd.getIdentityConstraintCategory().equals(XSDIdentityConstraintCategory.UNIQUE_LITERAL)) {
                    return 300;
                } else if (icd.getIdentityConstraintCategory().equals(XSDIdentityConstraintCategory.KEY_LITERAL)) {
                    return 301;
                } else {
                    return 302;
                }
            }
            return 200;
        }

        @Override
        public int compare(Viewer theViewer, Object e1, Object e2) {
            int cat1 = category(e1);
            int cat2 = category(e2);
            return cat1 - cat2;
        }
    });
    domViewer.setInput(site);
}
Also used : DrillDownAdapter(org.eclipse.ui.part.DrillDownAdapter) XSDTreeLabelProvider(com.amalto.workbench.providers.XSDTreeLabelProvider) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) ViewerSorter(org.eclipse.jface.viewers.ViewerSorter) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) TreeViewer(org.eclipse.jface.viewers.TreeViewer) Viewer(org.eclipse.jface.viewers.Viewer) XPathTreeContentProvider(com.amalto.workbench.providers.XPathTreeContentProvider) XSDFacet(org.eclipse.xsd.XSDFacet) GridData(org.eclipse.swt.layout.GridData) XSDIdentityConstraintDefinition(org.eclipse.xsd.XSDIdentityConstraintDefinition) TreeObject(com.amalto.workbench.models.TreeObject)

Example 2 with XSDIdentityConstraintDefinition

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

the class Util method checkConcept.

public static boolean checkConcept(XSDElementDeclaration decl) {
    boolean isConcept = false;
    EList<XSDIdentityConstraintDefinition> list = decl.getIdentityConstraintDefinitions();
    for (Iterator<XSDIdentityConstraintDefinition> iter = list.iterator(); iter.hasNext(); ) {
        XSDIdentityConstraintDefinition icd = iter.next();
        if (icd.getIdentityConstraintCategory().equals(XSDIdentityConstraintCategory.UNIQUE_LITERAL)) {
            isConcept = true;
            break;
        }
    }
    return isConcept;
}
Also used : XSDIdentityConstraintDefinition(org.eclipse.xsd.XSDIdentityConstraintDefinition)

Example 3 with XSDIdentityConstraintDefinition

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

the class Util method getRealKeyInfos.

public static List<Object> getRealKeyInfos(XSDElementDeclaration currentEntity, XSDParticle son) {
    if (currentEntity == null || son == null) {
        return null;
    }
    if (!isDirectChild(currentEntity, son)) {
        return null;
    }
    List<Object> list = new ArrayList<Object>();
    XSDTerm term = son.getTerm();
    if (term instanceof XSDElementDeclaration) {
        String primaryKey = ((XSDElementDeclaration) term).getName();
        EList<XSDIdentityConstraintDefinition> idtylist = currentEntity.getIdentityConstraintDefinitions();
        for (XSDIdentityConstraintDefinition idty : idtylist) {
            EList<XSDXPathDefinition> fields = idty.getFields();
            for (XSDXPathDefinition path : fields) {
                if ((path.getValue()).equals(primaryKey)) {
                    list.add(idty);
                    list.add(path);
                    break;
                }
            }
        }
    }
    return list;
}
Also used : XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) ArrayList(java.util.ArrayList) XSDTerm(org.eclipse.xsd.XSDTerm) XSDIdentityConstraintDefinition(org.eclipse.xsd.XSDIdentityConstraintDefinition) XObject(com.sun.org.apache.xpath.internal.objects.XObject) TreeObject(com.amalto.workbench.models.TreeObject) EObject(org.eclipse.emf.ecore.EObject) XSDXPathDefinition(org.eclipse.xsd.XSDXPathDefinition)

Example 4 with XSDIdentityConstraintDefinition

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

the class XSDUtil method getKeyFields.

public static List<String> getKeyFields(XSDElementDeclaration concept) {
    List<String> keyFields = new ArrayList<String>();
    EList<XSDIdentityConstraintDefinition> identityConstraintDefinitions = concept.getIdentityConstraintDefinitions();
    for (XSDIdentityConstraintDefinition icd : identityConstraintDefinitions) {
        if (concept.getName().equals(icd.getName())) {
            EList<XSDXPathDefinition> fields = icd.getFields();
            for (XSDXPathDefinition xpathdef : fields) {
                keyFields.add(xpathdef.getValue());
            }
        }
    }
    return keyFields;
}
Also used : ArrayList(java.util.ArrayList) XSDIdentityConstraintDefinition(org.eclipse.xsd.XSDIdentityConstraintDefinition) XSDXPathDefinition(org.eclipse.xsd.XSDXPathDefinition)

Example 5 with XSDIdentityConstraintDefinition

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

the class Util method getTopParent.

public static List<Object> getTopParent(Object son) {
    if (!((son instanceof XSDElementDeclaration))) {
        return null;
    }
    XSDElementDeclaration elem = null;
    elem = (XSDElementDeclaration) son;
    if (elem.getSchema() == null) {
        return null;
    }
    EList<XSDSchemaContent> parentList = elem.getSchema().getContents();
    List<Object> list = new ArrayList<Object>();
    for (XSDSchemaContent top : parentList) {
        list.clear();
        if (!(top instanceof XSDElementDeclaration)) {
            continue;
        }
        XSDElementDeclaration decl = (XSDElementDeclaration) top;
        if (decl.getTypeDefinition() instanceof XSDComplexTypeDefinition) {
            String primaryKey = getTopElement(decl, elem);
            if (!"".equalsIgnoreCase(primaryKey)) {
                // $NON-NLS-1$
                EList<XSDIdentityConstraintDefinition> idtylist = decl.getIdentityConstraintDefinitions();
                for (XSDIdentityConstraintDefinition idty : idtylist) {
                    EList<XSDXPathDefinition> fields = idty.getFields();
                    for (XSDXPathDefinition path : fields) {
                        if ((path.getValue()).equals(primaryKey)) {
                            list.add(idty);
                            list.add(path);
                            return list;
                        }
                    }
                }
            }
        }
    }
    return null;
}
Also used : XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) ArrayList(java.util.ArrayList) XSDSchemaContent(org.eclipse.xsd.XSDSchemaContent) XSDIdentityConstraintDefinition(org.eclipse.xsd.XSDIdentityConstraintDefinition) XObject(com.sun.org.apache.xpath.internal.objects.XObject) TreeObject(com.amalto.workbench.models.TreeObject) EObject(org.eclipse.emf.ecore.EObject) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDXPathDefinition(org.eclipse.xsd.XSDXPathDefinition)

Aggregations

XSDIdentityConstraintDefinition (org.eclipse.xsd.XSDIdentityConstraintDefinition)56 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)38 XSDXPathDefinition (org.eclipse.xsd.XSDXPathDefinition)32 XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)21 ArrayList (java.util.ArrayList)20 XSDParticle (org.eclipse.xsd.XSDParticle)19 XSDModelGroup (org.eclipse.xsd.XSDModelGroup)18 XSDSimpleTypeDefinition (org.eclipse.xsd.XSDSimpleTypeDefinition)18 Iterator (java.util.Iterator)15 XSDTypeDefinition (org.eclipse.xsd.XSDTypeDefinition)14 XSDAnnotation (org.eclipse.xsd.XSDAnnotation)13 XSDAttributeGroupDefinition (org.eclipse.xsd.XSDAttributeGroupDefinition)13 XSDFactory (org.eclipse.xsd.XSDFactory)13 XSDSchema (org.eclipse.xsd.XSDSchema)13 EList (org.eclipse.emf.common.util.EList)12 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)11 XSDAttributeDeclaration (org.eclipse.xsd.XSDAttributeDeclaration)10 XSDTerm (org.eclipse.xsd.XSDTerm)10 Element (org.w3c.dom.Element)10 TreeObject (com.amalto.workbench.models.TreeObject)9