Search in sources :

Example 16 with XSDParticle

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

the class Util method collectElementPaths.

public static void collectElementPaths(IStructuredContentProvider provider, Object input, XSDParticle toSearch, Set<String> paths, String inputPath) {
    if (input == null || paths == null || provider == null) {
        return;
    }
    Object[] elems = provider.getElements(input);
    if (elems != null && elems.length > 0) {
        for (Object obj : elems) {
            if (obj == null) {
                continue;
            }
            String curPath = inputPath;
            if (obj instanceof XSDElementDeclaration) {
                String name = ((XSDElementDeclaration) obj).getName();
                if (curPath == null) {
                    curPath = name;
                } else {
                    // $NON-NLS-1$
                    curPath += "/" + name;
                }
            }
            if (obj instanceof XSDParticle) {
                XSDParticleContent content = ((XSDParticle) obj).getContent();
                if (content instanceof XSDElementDeclaration) {
                    String name = ((XSDElementDeclaration) content).getName();
                    // $NON-NLS-1$
                    curPath += "/" + name;
                }
                if (obj == toSearch) {
                    paths.add(curPath);
                    break;
                }
            }
            collectElementPaths(provider, obj, toSearch, paths, curPath);
        }
    }
}
Also used : XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDParticleContent(org.eclipse.xsd.XSDParticleContent) XObject(com.sun.org.apache.xpath.internal.objects.XObject) TreeObject(com.amalto.workbench.models.TreeObject) EObject(org.eclipse.emf.ecore.EObject) XSDParticle(org.eclipse.xsd.XSDParticle)

Example 17 with XSDParticle

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

the class Util method updateReferenceToXSDTypeDefinition.

/**
 * update reference to newType
 *
 * @param elem
 * @param newType
 * @param provider
 */
public static void updateReferenceToXSDTypeDefinition(Object elem, XSDTypeDefinition newType, IStructuredContentProvider provider) {
    if (newType instanceof XSDComplexTypeDefinition) {
        updateChildrenReferenceToComplexType((XSDComplexTypeDefinition) newType);
    }
    List<Object> objList = new ArrayList<Object>();
    Object[] allNodes = getAllObject(elem, objList, provider);
    for (Object node : allNodes) {
        if (node instanceof XSDElementDeclaration) {
            XSDElementDeclaration xsdElem = (XSDElementDeclaration) node;
            if (xsdElem.getTypeDefinition() == newType) {
                xsdElem.setTypeDefinition(newType);
            }
        } else if (node instanceof XSDParticle) {
            XSDParticle particle = (XSDParticle) node;
            if (particle.getTerm() instanceof XSDModelGroup) {
                XSDModelGroup group = (XSDModelGroup) particle.getTerm();
                EList<XSDParticle> elist = group.getContents();
                for (XSDParticle pt : elist) {
                    if (pt.getContent() instanceof XSDElementDeclaration) {
                        if (((XSDElementDeclaration) pt.getContent()).getTypeDefinition() == newType) {
                            ((XSDElementDeclaration) pt.getContent()).setTypeDefinition(newType);
                        }
                    }
                }
            } else if (particle.getTerm() instanceof XSDElementDeclaration) {
                XSDElementDeclaration xsdElem = (XSDElementDeclaration) particle.getTerm();
                if (xsdElem.getTypeDefinition() == newType) {
                    xsdElem.setTypeDefinition(newType);
                }
            }
        }
    }
}
Also used : EList(org.eclipse.emf.common.util.EList) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) ArrayList(java.util.ArrayList) 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) XSDParticle(org.eclipse.xsd.XSDParticle)

Example 18 with XSDParticle

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

the class XSDDeleteConceptWrapAction method doAction.

@Override
public IStatus doAction() {
    List<IStatus> results = new ArrayList<IStatus>();
    try {
        IStructuredSelection selection = (IStructuredSelection) page.getTreeViewer().getSelection();
        if (delObjs.isEmpty()) {
            return Status.CANCEL_STATUS;
        } else {
            boolean sameType = checkInSameClassType(delObjs.toArray(), delObjs.get(0).getClass());
            String deleteLabel = Messages.DelLabel1;
            String elemDesc = ((Action) clsAction.get(delObjs.get(0).getClass())).getText();
            // $NON-NLS-1$
            int backPos = elemDesc.indexOf(" ");
            if (delObjs.size() > 1) {
                deleteLabel += elemDesc.substring(0, backPos) + Messages.DelLabel2 + delObjs.size() + Messages.DelLabel2A + (!sameType ? Messages.DelLabel2B : elemDesc.substring(backPos + 1));
                if (deleteLabel.endsWith("y")) {
                    // $NON-NLS-1$
                    deleteLabel = deleteLabel.substring(0, deleteLabel.length() - 1) + Messages.DelLabel3;
                } else {
                    deleteLabel = deleteLabel + Messages.XSDDeleteXX_DelLabel4;
                }
            } else {
                deleteLabel += elemDesc.substring(0, backPos) + Messages.XSDDeleteXX_DelLabel5 + (!sameType ? Messages.XSDDeleteXX_DelLabel5A : elemDesc.substring(backPos + 1));
            }
            if (!MessageDialog.openConfirm(page.getSite().getShell(), Messages.XSDDeleteXX_DialogTitle, deleteLabel)) {
                return Status.CANCEL_STATUS;
            }
        }
        for (Iterator iterator = delObjs.iterator(); iterator.hasNext(); ) {
            Object toDel = iterator.next();
            UndoAction delExecute = null;
            boolean isElem = true;
            if (toDel instanceof XSDElementDeclaration) {
                XSDElementDeclaration decl = (XSDElementDeclaration) toDel;
                EList l = decl.getIdentityConstraintDefinitions();
                for (Iterator iter = l.iterator(); iter.hasNext(); ) {
                    XSDIdentityConstraintDefinition icd = (XSDIdentityConstraintDefinition) iter.next();
                    if (icd.getIdentityConstraintCategory().equals(XSDIdentityConstraintCategory.UNIQUE_LITERAL)) {
                        isElem = false;
                        break;
                    }
                }
            }
            if (toDel instanceof XSDXPathDefinition) {
                XSDXPathDefinition xpath = (XSDXPathDefinition) toDel;
                if (!xpath.getVariety().equals(XSDXPathVariety.FIELD_LITERAL)) {
                    continue;
                }
            }
            delExecute = clsAction.get(toDel.getClass());
            if (isElem && toDel instanceof XSDElementDeclaration) {
                delExecute = clsAction.get(null);
            }
            if (delExecute instanceof XSDDeleteConceptAction && toDel instanceof XSDElementDeclaration) {
                ((XSDDeleteConceptAction) delExecute).setXSDTODel((XSDElementDeclaration) toDel);
            } else if (delExecute instanceof XSDDeleteElementAction && toDel instanceof XSDElementDeclaration) {
                ((XSDDeleteElementAction) delExecute).setXSDTODel((XSDElementDeclaration) toDel);
            } else if (delExecute instanceof XSDDeleteParticleAction && toDel instanceof XSDParticle) {
                ((XSDDeleteParticleAction) delExecute).setXSDTODel((XSDParticle) toDel);
            } else if (delExecute instanceof XSDDeleteXPathAction && toDel instanceof XSDXPathDefinition) {
                ((XSDDeleteXPathAction) delExecute).setXSDTODel((XSDXPathDefinition) toDel);
            } else if (delExecute instanceof XSDDeleteIdentityConstraintAction && toDel instanceof XSDIdentityConstraintDefinition) {
                ((XSDDeleteIdentityConstraintAction) delExecute).setXSDTODel((XSDIdentityConstraintDefinition) toDel);
            } else if (delExecute instanceof XSDDeleteTypeDefinition && toDel instanceof XSDComplexTypeDefinition) {
                ((XSDDeleteTypeDefinition) delExecute).setXSDTODel((XSDComplexTypeDefinition) toDel);
            } else if (delExecute instanceof XSDDeleteTypeDefinition && toDel instanceof XSDSimpleTypeDefinition) {
                ((XSDDeleteTypeDefinition) delExecute).setXSDTODel((XSDSimpleTypeDefinition) toDel);
            } else if (delExecute instanceof XSDDeleteAttributeAction && toDel instanceof XSDAttributeUse) {
                ((XSDDeleteAttributeAction) delExecute).setXSDAttributeUse((XSDAttributeUse) toDel);
            } else if (delExecute instanceof XSDDeleteAttributeAction && toDel instanceof XSDAttributeDeclaration) {
                ((XSDDeleteAttributeAction) delExecute).setXSDAttribute((XSDAttributeDeclaration) toDel);
            } else {
                return Status.CANCEL_STATUS;
            }
            results.add(delExecute.execute());
        }
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages.XSDDeleteXX_ErrorMsg, e.getLocalizedMessage()));
        return (results.indexOf(Status.OK_STATUS) >= 0 ? Status.OK_STATUS : Status.CANCEL_STATUS);
    }
    return (results.indexOf(Status.OK_STATUS) >= 0 ? Status.OK_STATUS : Status.CANCEL_STATUS);
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Action(org.eclipse.jface.action.Action) XSDAttributeUse(org.eclipse.xsd.XSDAttributeUse) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Iterator(java.util.Iterator) XSDXPathDefinition(org.eclipse.xsd.XSDXPathDefinition) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDParticle(org.eclipse.xsd.XSDParticle) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) EList(org.eclipse.emf.common.util.EList) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDIdentityConstraintDefinition(org.eclipse.xsd.XSDIdentityConstraintDefinition) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration)

Example 19 with XSDParticle

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

the class XSDAbstractNewXPathAction method updateElementForAddedfield.

protected void updateElementForAddedfield(XSDIdentityConstraintDefinition icd, String fieldName) {
    if (icd == null || fieldName == null)
        return;
    XSDElementDeclaration entity = (XSDElementDeclaration) icd.getContainer();
    XSDComplexTypeDefinition ctype = (XSDComplexTypeDefinition) entity.getTypeDefinition();
    if (ctype.getContent() instanceof XSDParticle) {
        XSDParticleImpl particle = (XSDParticleImpl) ctype.getContent();
        if (particle.getTerm() instanceof XSDModelGroup) {
            XSDModelGroup group = (XSDModelGroup) particle.getTerm();
            EList<XSDParticle> particles = group.getParticles();
            for (XSDParticle part : particles) {
                if (part.getTerm() instanceof XSDElementDeclaration) {
                    XSDElementDeclaration el = (XSDElementDeclaration) part.getTerm();
                    if (el.getTypeDefinition() instanceof XSDSimpleTypeDefinition) {
                        if (fieldName.equals(el.getName())) {
                            part.setMinOccurs(1);
                            part.setMaxOccurs(1);
                            break;
                        }
                    }
                }
            }
        }
    }
    entity.updateElement();
}
Also used : XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) XSDParticleImpl(org.eclipse.xsd.impl.XSDParticleImpl) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDParticle(org.eclipse.xsd.XSDParticle)

Example 20 with XSDParticle

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

the class XSDAddComplexTypeElementAction method init.

private boolean init() {
    IStructuredSelection selection = (IStructuredSelection) page.getTreeViewer().getSelection();
    if (selection.getFirstElement() instanceof XSDParticle) {
        selParticle = (XSDParticle) selection.getFirstElement();
        if (!(selParticle.getContainer() instanceof XSDModelGroup)) {
            return false;
        }
        modelGroup = (XSDModelGroup) selParticle.getContainer();
    } else {
        if (selection.getFirstElement() instanceof XSDComplexTypeDefinition) {
            XSDComplexTypeDefinition ctd = (XSDComplexTypeDefinition) selection.getFirstElement();
            if (!(ctd.getContent() instanceof XSDParticle)) {
                return false;
            }
            if (!(((XSDParticle) ctd.getContent()).getTerm() instanceof XSDModelGroup)) {
                return false;
            }
            ;
            modelGroup = (XSDModelGroup) ((XSDParticle) ctd.getContent()).getTerm();
        } else if (selection.getFirstElement() instanceof XSDParticle) {
            modelGroup = (XSDModelGroup) ((XSDParticle) selection.getFirstElement()).getTerm();
        } else if (selection.getFirstElement() instanceof XSDModelGroup) {
            modelGroup = (XSDModelGroup) selection.getFirstElement();
        } else {
            log.info(Messages.bind(Messages._UnkownSection, selection.getFirstElement().getClass().getName(), selection.getFirstElement().toString()));
            return false;
        }
    }
    return true;
}
Also used : XSDModelGroup(org.eclipse.xsd.XSDModelGroup) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) 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