Search in sources :

Example 16 with XSDComplexTypeDefinition

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

the class XSDDeleteTypeDefinition method doAction.

@Override
public IStatus doAction() {
    IStructuredSelection selection = (IStructuredSelection) page.getTreeViewer().getSelection();
    ArrayList<Object> objList = new ArrayList<Object>();
    Util.getAllObject(page.getSite(), objList, (IStructuredContentProvider) page.getSchemaContentProvider());
    Util.getAllObject(page.getSite(), objList, (IStructuredContentProvider) page.getTypeContentProvider());
    XSDTypeDefinition usingElement = findUsingElement(selection, objList);
    if (usingElement != null) {
        String message = getInfoDialogMessage(usingElement);
        MessageDialog.openInformation(page.getSite().getShell(), Messages.XSDDeleteTypeDefinition_ConfirmDel, message);
        return Status.CANCEL_STATUS;
    }
    // edit by ymli; fix the bug:0012228. Made the multiple types can be deleted.
    for (Iterator<XSDTypeDefinition> iter = selection.iterator(); iter.hasNext(); ) {
        XSDTypeDefinition type = iter.next();
        if (type instanceof XSDSimpleTypeDefinition) {
            XSDSimpleTypeDefinition simpleType = (XSDSimpleTypeDefinition) type;
            if (xsdSimpType != null) {
                simpleType = xsdSimpType;
            }
            schema.getContents().remove(simpleType);
        } else {
            XSDComplexTypeDefinition complxType = (XSDComplexTypeDefinition) type;
            if (xsdCmpexType != null) {
                complxType = xsdCmpexType;
            }
            schema.getContents().remove(complxType);
        }
    }
    xsdSimpType = null;
    xsdCmpexType = null;
    page.refresh();
    page.markDirty();
    return Status.OK_STATUS;
}
Also used : XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition)

Example 17 with XSDComplexTypeDefinition

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

the class XSDEditComplexTypeAction method doAction.

@Override
public IStatus doAction() {
    try {
        ISelection selection = page.getTreeViewer().getSelection();
        IStructuredContentProvider provider = (IStructuredContentProvider) page.getSchemaContentProvider();
        XSDComplexTypeDefinition decl = (XSDComplexTypeDefinition) ((IStructuredSelection) selection).getFirstElement();
        String oldName = decl.getName();
        InputDialog id = new InputDialog(page.getSite().getShell(), Messages.XSDEditComplexTypeAction_EditComplexType, Messages.XSDEditComplexTypeAction_EnterNameForEntity, oldName, new IInputValidator() {

            public String isValid(String newText) {
                if (// $NON-NLS-1$
                (newText == null) || "".equals(newText))
                    return Messages.XSDEditComplexTypeAction_ComplexTypeCannotBeEmpty;
                if (// $NON-NLS-1$
                Pattern.compile("^\\s+\\w+\\s*").matcher(newText).matches() || // $NON-NLS-1$//$NON-NLS-2$
                newText.trim().replaceAll("\\s", "").length() != newText.trim().length())
                    return Messages.XSDEditComplexTypeAction_NameCannotContainEmpty;
                if (!XSDUtil.isValidatedXSDName(newText)) {
                    return Messages.InvalidName_Message;
                }
                EList list = schema.getTypeDefinitions();
                for (Iterator iter = list.iterator(); iter.hasNext(); ) {
                    Object d = iter.next();
                    if (d instanceof XSDComplexTypeDefinition) {
                        XSDComplexTypeDefinition type = (XSDComplexTypeDefinition) d;
                        if (type.getName().equals(newText.trim()))
                            return Messages.XSDEditComplexTypeAction_ComplexAlreadyExists;
                    }
                }
                return null;
            }
        });
        id.setBlockOnOpen(true);
        int ret = id.open();
        if (ret == Dialog.CANCEL) {
            return Status.CANCEL_STATUS;
        }
        decl.setName(id.getValue().trim());
        Util.updateReferenceToXSDTypeDefinition(page.getSite(), decl, provider);
        page.refresh();
        page.markDirty();
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.XSDEditComplexTypeAction_ErrorEditEntity + e.getLocalizedMessage());
        return Status.CANCEL_STATUS;
    }
    return Status.OK_STATUS;
}
Also used : InputDialog(org.eclipse.jface.dialogs.InputDialog) EList(org.eclipse.emf.common.util.EList) ISelection(org.eclipse.jface.viewers.ISelection) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) Iterator(java.util.Iterator) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Example 18 with XSDComplexTypeDefinition

use of org.eclipse.xsd.XSDComplexTypeDefinition 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 19 with XSDComplexTypeDefinition

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

Example 20 with XSDComplexTypeDefinition

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

the class XSDAddComplexTypeElementAction method openDialog.

private int openDialog() {
    XSDSimpleTypeDefinition simpleTypeDefinition = schema.resolveSimpleTypeDefinition(schema.getSchemaForSchemaNamespace(), defaultTypeName);
    List<XSDComplexTypeDefinition> types = Util.getComplexTypes(schema);
    dialogR = new ComplexTypeInputDialogR(page.getSite().getShell(), Messages._AddCType, modelGroup, schema, types, simpleTypeDefinition, false, false);
    dialogR.setBlockOnOpen(true);
    int ret = dialogR.open();
    return ret;
}
Also used : ComplexTypeInputDialogR(com.amalto.workbench.dialogs.ComplexTypeInputDialogR) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition)

Aggregations

XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)162 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)93 XSDModelGroup (org.eclipse.xsd.XSDModelGroup)76 XSDParticle (org.eclipse.xsd.XSDParticle)75 XSDTypeDefinition (org.eclipse.xsd.XSDTypeDefinition)66 XSDSimpleTypeDefinition (org.eclipse.xsd.XSDSimpleTypeDefinition)53 ArrayList (java.util.ArrayList)43 XSDSchema (org.eclipse.xsd.XSDSchema)37 Test (org.junit.Test)37 EList (org.eclipse.emf.common.util.EList)25 XSDConcreteComponent (org.eclipse.xsd.XSDConcreteComponent)25 XSDFactory (org.eclipse.xsd.XSDFactory)23 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)22 XSDIdentityConstraintDefinition (org.eclipse.xsd.XSDIdentityConstraintDefinition)21 XSDTerm (org.eclipse.xsd.XSDTerm)21 XSDAnnotation (org.eclipse.xsd.XSDAnnotation)20 XSDComplexTypeContent (org.eclipse.xsd.XSDComplexTypeContent)20 Iterator (java.util.Iterator)19 List (java.util.List)19 XSDAttributeGroupDefinition (org.eclipse.xsd.XSDAttributeGroupDefinition)16