Search in sources :

Example 21 with XSDComplexTypeDefinition

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

the class XSDAddComplexTypeElementAction method transformToComplexType.

private boolean transformToComplexType(XSDParticle particle) {
    XSDElementDeclaration decl = (XSDElementDeclaration) particle.getContent();
    List<XSDComplexTypeDefinition> types = Util.getComplexTypes(schema);
    XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory();
    // $NON-NLS-1$
    boolean anonymous = (typeName == null) || ("".equals(typeName));
    boolean alreadyExists = false;
    XSDComplexTypeDefinition complexType = null;
    // the sub element created if needed
    XSDParticle subParticle = null;
    XSDParticle groupParticle = null;
    XSDElementDeclaration subElement = null;
    XSDElementDeclaration parent = null;
    Object pObject = Util.getParent(decl);
    if (pObject instanceof XSDElementDeclaration) {
        parent = (XSDElementDeclaration) pObject;
    }
    if (!anonymous) {
        if (typeName.lastIndexOf(" : ") != -1) {
            // $NON-NLS-1$
            // $NON-NLS-1$
            typeName = typeName.substring(0, typeName.lastIndexOf(" : "));
        }
        for (XSDComplexTypeDefinition td : types) {
            if ((td.getName().equals(typeName))) {
                alreadyExists = true;
                complexType = td;
                break;
            }
        }
    } else {
        if (decl.getTypeDefinition() instanceof XSDSimpleTypeDefinition) {
            alreadyExists = false;
        }
    }
    if (alreadyExists) {
        XSDParticle partCnt = (XSDParticle) complexType.getContentType();
        partCnt.unsetMaxOccurs();
        partCnt.unsetMinOccurs();
        XSDTypeDefinition superType = null;
        for (XSDTypeDefinition type : types) {
            if (type.getName().equals(superTypeName)) {
                superType = type;
                break;
            }
        }
        if (superType != null) {
            XSDModelGroup mdlGrp = (XSDModelGroup) partCnt.getTerm();
            boolean status = updateCompositorType(superType, mdlGrp);
            if (!status) {
                return false;
            }
            complexType.setDerivationMethod(XSDDerivationMethod.EXTENSION_LITERAL);
            complexType.setBaseTypeDefinition(superType);
        }
        if (isAbstract) {
            complexType.setAbstract(isAbstract);
        } else {
            complexType.unsetAbstract();
        }
        if (parent != null) {
            parent.updateElement();
        }
        if (complexType != null) {
            complexType.updateElement();
        }
    } else {
        // Create if does not exist
        // add an element declaration
        subElement = factory.createXSDElementDeclaration();
        // $NON-NLS-1$
        subElement.setName("subelement");
        subElement.setTypeDefinition(schema.resolveSimpleTypeDefinition(schema.getSchemaForSchemaNamespace(), defaultTypeName));
        subParticle = factory.createXSDParticle();
        subParticle.unsetMaxOccurs();
        subParticle.unsetMinOccurs();
        subParticle.setContent(subElement);
        subParticle.updateElement();
        // create group
        XSDModelGroup group = factory.createXSDModelGroup();
        if (isChoice) {
            group.setCompositor(XSDCompositor.CHOICE_LITERAL);
        } else if (isAll) {
            group.setCompositor(XSDCompositor.ALL_LITERAL);
        } else {
            group.setCompositor(XSDCompositor.SEQUENCE_LITERAL);
        }
        group.getContents().add(0, subParticle);
        group.updateElement();
        // create the complex type
        complexType = factory.createXSDComplexTypeDefinition();
        // complexType.setDerivationMethod(XSDDerivationMethod.EXTENSION_LITERAL);
        if (!anonymous) {
            // if (true) {
            XSDTypeDefinition superType = null;
            for (XSDTypeDefinition type : types) {
                if (type.getName().equals(superTypeName)) {
                    superType = type;
                    break;
                }
            }
            complexType.setName(typeName);
            if (superType != null) {
                boolean status = updateCompositorType(superType, group);
                if (!status) {
                    return false;
                }
                complexType.setDerivationMethod(XSDDerivationMethod.EXTENSION_LITERAL);
                complexType.setBaseTypeDefinition(superType);
            }
            if (isAbstract) {
                complexType.setAbstract(isAbstract);
            } else {
                complexType.unsetAbstract();
            }
            schema.getContents().add(complexType);
        }
        complexType.updateElement();
        // add the group
        groupParticle = factory.createXSDParticle();
        groupParticle.unsetMaxOccurs();
        groupParticle.unsetMinOccurs();
        groupParticle.setContent(group);
        groupParticle.updateElement();
        complexType.setContent(groupParticle);
        complexType.updateElement();
    }
    // set complex type to concept
    if (anonymous) {
        decl.setAnonymousTypeDefinition(complexType);
    } else {
        decl.setTypeDefinition(complexType);
    }
    decl.updateElement();
    schema.update();
    return true;
}
Also used : XSDFactory(org.eclipse.xsd.XSDFactory) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDParticle(org.eclipse.xsd.XSDParticle) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition)

Example 22 with XSDComplexTypeDefinition

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

the class XSDChangeToComplexTypeAction method doAction.

@Override
public IStatus doAction() {
    try {
        IStructuredSelection selection = (IStructuredSelection) page.getTreeViewer().getSelection();
        isConcept = false;
        TreePath tPath = null;
        if (((TreeSelection) selection).getPaths().length > 0) {
            tPath = ((TreeSelection) selection).getPaths()[0];
        }
        // declNew is the new created one not the selected one in tree vew
        if (declNew != null) {
            decl = declNew;
            checkConcept();
        } else if (selection.getFirstElement() instanceof XSDModelGroup) {
            for (int i = 0; i < tPath.getSegmentCount(); i++) {
                if (tPath.getSegment(i) instanceof XSDElementDeclaration) {
                    decl = (XSDElementDeclaration) tPath.getSegment(i);
                } else if (tPath.getSegment(i) instanceof XSDParticle) {
                    decl = (XSDElementDeclaration) ((XSDParticle) tPath.getSegment(i)).getTerm();
                }
            }
            checkConcept();
        } else if (selection.getFirstElement() instanceof XSDElementDeclaration) {
            decl = (XSDElementDeclaration) selection.getFirstElement();
            // check if concept or "just" element
            checkConcept();
        } else if (selection.getFirstElement() instanceof XSDParticle) {
            // if it's a particle,it should change the element of its
            // content
            decl = (XSDElementDeclaration) ((XSDParticle) selection.getFirstElement()).getContent();
        } else {
            // if(selection.getFirstElement() instanceof XSDParticle )
            if (selection.getFirstElement() != null) {
                // a sub element
                decl = (XSDElementDeclaration) ((XSDParticle) selection.getFirstElement()).getTerm();
            }
        }
        // /save current Type Definition
        // XSDTypeDefinition current = decl.getTypeDefinition();
        List<XSDComplexTypeDefinition> types = Util.getComplexTypes(decl.getSchema());
        if (showDlg) {
            if (decl.getTypeDefinition() instanceof XSDComplexTypeDefinition) {
                boolean confirm = MessageDialog.openConfirm(page.getSite().getShell(), Messages.Warning, Messages.XSDChangeToCXX_ChangeToAnotherTypeWarning);
                if (!confirm) {
                    return Status.CANCEL_STATUS;
                }
            }
            if (tPath != null) {
                for (int i = 0; i < tPath.getSegmentCount(); i++) {
                    if (tPath.getSegment(i) instanceof XSDElementDeclaration) {
                        XSDTypeDefinition type = (((XSDElementDeclaration) tPath.getSegment(i)).getTypeDefinition());
                        if (!type.equals(decl.getTypeDefinition())) {
                            types.remove(type);
                        }
                    }
                    if (tPath.getSegment(i) instanceof XSDParticle) {
                        XSDTypeDefinition type = ((XSDElementDeclaration) (((XSDParticle) tPath.getSegment(i)).getTerm())).getTypeDefinition();
                        if (!type.equals(decl.getTypeDefinition())) {
                            types.remove(type);
                        }
                    }
                }
            }
            dialog = new // $NON-NLS-1$
            ComplexTypeInputDialog(// $NON-NLS-1$
            this, // $NON-NLS-1$
            page.getSite().getShell(), // $NON-NLS-1$
            "", // $NON-NLS-1$
            schema, // $NON-NLS-1$
            decl.getTypeDefinition(), // $NON-NLS-1$
            types, isXSDModelGroup);
            dialog.setBlockOnOpen(true);
            int ret = dialog.open();
            if (ret == Dialog.CANCEL) {
                return Status.CANCEL_STATUS;
            }
        }
        if (!showDlg && !validateType()) {
            return Status.CANCEL_STATUS;
        }
        XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory();
        // $NON-NLS-1$
        boolean anonymous = (typeName == null) || ("".equals(typeName));
        boolean alreadyExists = false;
        XSDComplexTypeDefinition complexType = null;
        // the sub element created if needed
        XSDParticle subParticle = null;
        XSDParticle groupParticle = null;
        XSDElementDeclaration subElement = null;
        // check if already exist
        // add by ymli; fix the bug:0012278;
        XSDElementDeclaration parent = null;
        Object pObject = Util.getParent(decl);
        if (pObject instanceof XSDElementDeclaration) {
            parent = (XSDElementDeclaration) pObject;
        }
        if (!anonymous) {
            List<XSDComplexTypeDefinition> list = Util.getComplexTypes(schema);
            if (typeName.lastIndexOf(" : ") != -1) {
                // $NON-NLS-1$
                // $NON-NLS-1$
                typeName = typeName.substring(0, typeName.lastIndexOf(" : "));
            }
            for (XSDComplexTypeDefinition td : list) {
                if ((td.getName().equals(typeName))) {
                    alreadyExists = true;
                    complexType = td;
                    break;
                }
            }
        } else {
            XSDComplexTypeDefinition declComplexType = null;
            if (parent != null && decl.getTypeDefinition() instanceof XSDComplexTypeDefinition) {
                declComplexType = (XSDComplexTypeDefinition) decl.getTypeDefinition();
            }
            if (declComplexType != null && declComplexType.getSchema() != null && declComplexType.getName() == null) {
                alreadyExists = true;
            }
            if (decl.getTypeDefinition() instanceof XSDSimpleTypeDefinition) {
                alreadyExists = false;
            }
        }
        if (alreadyExists) {
            XSDParticle partCnt = (XSDParticle) complexType.getContentType();
            partCnt.unsetMaxOccurs();
            partCnt.unsetMinOccurs();
            XSDTypeDefinition superType = null;
            for (XSDTypeDefinition type : types) {
                if (type.getName().equals(superTypeName)) {
                    superType = type;
                    break;
                }
            }
            if (superType != null) {
                XSDModelGroup mdlGrp = (XSDModelGroup) partCnt.getTerm();
                boolean status = updateCompositorType(superType, mdlGrp);
                if (!status) {
                    return Status.CANCEL_STATUS;
                }
                complexType.setDerivationMethod(XSDDerivationMethod.EXTENSION_LITERAL);
                complexType.setBaseTypeDefinition(superType);
            }
            if (isAbstract) {
                complexType.setAbstract(isAbstract);
            } else {
                complexType.unsetAbstract();
            }
            if (parent != null) {
                parent.updateElement();
            }
            if (complexType != null) {
                complexType.updateElement();
            }
        } else {
            // Create if does not exist
            // add an element declaration
            subElement = factory.createXSDElementDeclaration();
            if (declNew != null) {
                // crate a new entity
                if (declNew.getName() != null) {
                    // $NON-NLS-1$
                    subElement.setName(declNew.getName() + "Id");
                }
            } else {
                // create a complex element
                // $NON-NLS-1$
                subElement.setName("subelement");
            }
            // $NON-NLS-1$
            subElement.setTypeDefinition(schema.resolveSimpleTypeDefinition(schema.getSchemaForSchemaNamespace(), "string"));
            subParticle = factory.createXSDParticle();
            subParticle.unsetMaxOccurs();
            subParticle.unsetMinOccurs();
            subParticle.setContent(subElement);
            subParticle.updateElement();
            // create group
            XSDModelGroup group = factory.createXSDModelGroup();
            if (isChoice) {
                group.setCompositor(XSDCompositor.CHOICE_LITERAL);
            } else if (isAll) {
                group.setCompositor(XSDCompositor.ALL_LITERAL);
            } else {
                group.setCompositor(XSDCompositor.SEQUENCE_LITERAL);
            }
            group.getContents().add(0, subParticle);
            group.updateElement();
            // create the complex type
            complexType = factory.createXSDComplexTypeDefinition();
            if (!anonymous) {
                XSDTypeDefinition superType = null;
                for (XSDTypeDefinition type : types) {
                    if (type.getName().equals(superTypeName)) {
                        superType = type;
                        break;
                    }
                }
                complexType.setName(typeName);
                if (superType != null) {
                    complexType.setDerivationMethod(XSDDerivationMethod.EXTENSION_LITERAL);
                    complexType.setBaseTypeDefinition(superType);
                    updateCompositorType(superType, group);
                }
                if (isAbstract) {
                    complexType.setAbstract(isAbstract);
                } else {
                    complexType.unsetAbstract();
                }
                schema.getContents().add(complexType);
            }
            complexType.updateElement();
            // add the group
            groupParticle = factory.createXSDParticle();
            groupParticle.unsetMaxOccurs();
            groupParticle.unsetMinOccurs();
            groupParticle.setContent(group);
            groupParticle.updateElement();
            complexType.setContent(groupParticle);
            complexType.updateElement();
        }
        // set complex type to concept
        if (anonymous) {
            decl.setAnonymousTypeDefinition(complexType);
        } else {
            decl.setTypeDefinition(complexType);
        }
        if (isConcept) {
            buildUniqueKey(factory, decl, complexType, anonymous, alreadyExists);
        }
        // if isConcept
        decl.updateElement();
        schema.update();
        page.refresh();
        declNew = null;
        page.markDirty();
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages.XSDChangeToCXX_ErrorMsg1, e.getLocalizedMessage()));
        return Status.CANCEL_STATUS;
    }
    return Status.OK_STATUS;
}
Also used : XSDFactory(org.eclipse.xsd.XSDFactory) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition) TreePath(org.eclipse.jface.viewers.TreePath) TreeSelection(org.eclipse.jface.viewers.TreeSelection) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDParticle(org.eclipse.xsd.XSDParticle)

Example 23 with XSDComplexTypeDefinition

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

the class XSDChangeToSimpleTypeAction method doAction.

@Override
public IStatus doAction() {
    try {
        XSDElementDeclaration decl = null;
        IStructuredSelection selection = (IStructuredSelection) page.getTreeViewer().getSelection();
        // declNew is the new created one not the selected one in tree vew
        if (declNew != null) {
            decl = declNew;
        } else if (selection.getFirstElement() instanceof XSDElementDeclaration) {
            isConcept = true;
            decl = (XSDElementDeclaration) selection.getFirstElement();
        } else {
            isConcept = false;
            if (selection.getFirstElement() != null) {
                decl = (XSDElementDeclaration) ((XSDParticle) selection.getFirstElement()).getTerm();
            }
        }
        // build list of custom types and built in types
        List<String> customTypes = new ArrayList<String>();
        for (XSDTypeDefinition type : schema.getTypeDefinitions()) {
            if (type instanceof XSDSimpleTypeDefinition) {
                if (type.getTargetNamespace() != null && !type.getTargetNamespace().equals(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001) || type.getTargetNamespace() == null) {
                    customTypes.add(type.getName());
                }
            }
        }
        List<String> builtInTypes = XSDUtil.getBuiltInTypes();
        if (showDlg) {
            String name = decl.getTypeDefinition().getName();
            if (decl.getTypeDefinition() instanceof XSDComplexTypeDefinition) {
                name = null;
                boolean confirm = MessageDialog.openConfirm(page.getSite().getShell(), Messages.Warning, Messages.XSDChangeToCXX_ChangeToAnotherTypeWarning);
                if (!confirm) {
                    return Status.CANCEL_STATUS;
                }
            }
            dialog = new SimpleTypeInputDialog(this, page.getSite().getShell(), schema, Messages.XSDChangeToXX_DialogTitle, customTypes, builtInTypes, name);
            dialog.setBlockOnOpen(true);
            int ret = dialog.open();
            if (ret == Window.CANCEL) {
                return Status.CANCEL_STATUS;
            }
        }
        // remove all unique keys and make new one
        if (isConcept) {
            // remove exisitng unique key(s)
            ArrayList keys = new ArrayList();
            EList list = decl.getIdentityConstraintDefinitions();
            for (Iterator iter = list.iterator(); iter.hasNext(); ) {
                XSDIdentityConstraintDefinition icd = (XSDIdentityConstraintDefinition) iter.next();
                if (icd.getIdentityConstraintCategory().equals(XSDIdentityConstraintCategory.UNIQUE_LITERAL)) {
                    keys.add(icd);
                }
            }
            decl.getIdentityConstraintDefinitions().removeAll(keys);
            // add new unique Key
            XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory();
            XSDIdentityConstraintDefinition uniqueKey = factory.createXSDIdentityConstraintDefinition();
            uniqueKey.setIdentityConstraintCategory(XSDIdentityConstraintCategory.UNIQUE_LITERAL);
            uniqueKey.setName(decl.getName());
            XSDXPathDefinition selector = factory.createXSDXPathDefinition();
            selector.setVariety(XSDXPathVariety.SELECTOR_LITERAL);
            // $NON-NLS-1$
            selector.setValue(".");
            uniqueKey.setSelector(selector);
            XSDXPathDefinition field = factory.createXSDXPathDefinition();
            field.setVariety(XSDXPathVariety.FIELD_LITERAL);
            // $NON-NLS-1$
            field.setValue(".");
            uniqueKey.getFields().add(field);
            decl.getIdentityConstraintDefinitions().add(uniqueKey);
        }
        // Save current type definition
        XSDTypeDefinition current = decl.getTypeDefinition();
        // set new one
        if (builtIn) {
            decl.setTypeDefinition(schema.resolveSimpleTypeDefinition(schema.getSchemaForSchemaNamespace(), typeName));
        } else {
            // check if concept already exists
            if (typeName != null && typeName.length() > 0) {
                XSDSimpleTypeDefinition std = null;
                // $NON-NLS-1$
                String ns = "";
                if (typeName.lastIndexOf(" : ") != -1) {
                    // $NON-NLS-1$
                    // $NON-NLS-1$
                    ns = typeName.substring(typeName.lastIndexOf(" : ") + 3);
                    // $NON-NLS-1$
                    typeName = typeName.substring(0, typeName.lastIndexOf(" : "));
                }
                for (XSDTypeDefinition typeDef : schema.getTypeDefinitions()) {
                    if (typeDef instanceof XSDSimpleTypeDefinition) {
                        if (typeDef.getName().equals(typeName)) {
                            std = (XSDSimpleTypeDefinition) typeDef;
                            break;
                        }
                    }
                }
                if (std == null) {
                    std = schema.resolveSimpleTypeDefinition(typeName);
                    std.setBaseTypeDefinition(schema.resolveSimpleTypeDefinition(schema.getSchemaForSchemaNamespace(), // $NON-NLS-1$
                    "string"));
                    if (typeName.equals(EUUIDCustomType.MULTI_LINGUAL.getName())) {
                        XSDPatternFacet f = XSDSchemaBuildingTools.getXSDFactory().createXSDPatternFacet();
                        // $NON-NLS-1$
                        f.setLexicalValue("(\\[\\w+\\:[^\\[\\]]*\\]){0,}");
                        std.getFacetContents().add(f);
                    }
                    schema.getContents().add(std);
                }
                decl.setTypeDefinition(std);
            } else {
                XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory();
                simpleType = factory.createXSDSimpleTypeDefinition();
                simpleType.setBaseTypeDefinition(schema.resolveSimpleTypeDefinition(schema.getSchemaForSchemaNamespace(), // $NON-NLS-1$
                "string"));
                decl.setAnonymousTypeDefinition(simpleType);
            }
        }
        decl.updateElement();
        // remove current if no more in use
        // if (current != null) {
        // if ( (current.getName()!=null) && //anonymous type
        // (!schema.getSchemaForSchemaNamespace().equals(current.getTargetNamespace()))
        // ){
        // List eut =Util.findElementsUsingType(schema, current.getTargetNamespace(), current.getName());
        // if (eut.size()==0)
        // schema.getContents().remove(current);
        // }
        // }
        declNew = null;
        page.refresh();
        page.markDirty();
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages.XSDChangeToXX_ErrorMsg1, e.getLocalizedMessage()));
        return Status.CANCEL_STATUS;
    }
    return Status.OK_STATUS;
}
Also used : XSDPatternFacet(org.eclipse.xsd.XSDPatternFacet) XSDFactory(org.eclipse.xsd.XSDFactory) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition) EList(org.eclipse.emf.common.util.EList) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) Iterator(java.util.Iterator) XSDIdentityConstraintDefinition(org.eclipse.xsd.XSDIdentityConstraintDefinition) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) SimpleTypeInputDialog(com.amalto.workbench.dialogs.SimpleTypeInputDialog) XSDXPathDefinition(org.eclipse.xsd.XSDXPathDefinition)

Example 24 with XSDComplexTypeDefinition

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

the class DataModelMainPage method fillContextMenu.

protected void fillContextMenu(IMenuManager manager, boolean isType) {
    IStructuredSelection selection;
    if (!isType) {
        selection = ((IStructuredSelection) viewer.getSelection());
    } else {
        selection = ((IStructuredSelection) typesViewer.getSelection());
    }
    Object[] selectedObjs = selection.toArray();
    Object obj = selection.getFirstElement();
    if (!isType) {
        manager.add(newConceptAction);
    } else {
        manager.add(newComplexTypeAction);
        manager.add(newSimpleTypeAction);
        // add by ymli; fix the bug:0012228. Made the multiple types can be deleted.
        XSDDeleteTypeDefinition deleteTypeDefinition1;
        if (selectedObjs.length > 1) {
            deleteTypeDefinition1 = new XSDDeleteTypeDefinition(this, true);
        } else {
            deleteTypeDefinition1 = new XSDDeleteTypeDefinition(this, false);
        }
        if (selectedObjs.length >= 1 && deleteTypeDefinition1.isTypeDefinition(selectedObjs)) {
            manager.add(deleteTypeDefinition1);
        }
        deleteConceptWrapAction.regisExtraClassToDel(XSDComplexTypeDefinitionImpl.class);
        if (selectedObjs.length > 1 && deleteConceptWrapAction.checkInDeletableType(selectedObjs)) {
            deleteConceptWrapAction.prepareToDelSelectedItems(selection, viewer);
        }
        if (selectedObjs.length > 1 && deleteConceptWrapAction.outPutDeleteActions() != null) {
            manager.add(deleteConceptWrapAction.outPutDeleteActions());
            if (deleteConceptWrapAction.checkOutAllConcept(selectedObjs)) {
                manager.add(newBrowseItemAction);
            }
        }
        if (exAdapter != null && obj instanceof XSDComplexTypeDefinition && selectedObjs.length == 1) {
            exAdapter.fillContextMenu(manager);
        }
    }
    manager.add(new Separator());
    if (!isType && ((selection == null) || (selection.getFirstElement() == null))) {
        if (WorkbenchClipboard.getWorkbenchClipboard().getConcepts().size() > 0) {
            manager.add(new Separator(ADDITIONMENUID));
            // add by ymli, fix bug 0009770
            // $NON-NLS-1$
            String title = "";
            if (WorkbenchClipboard.getWorkbenchClipboard().getConcepts().size() == 1) {
                title = Messages.PasteEntityText;
            } else if (WorkbenchClipboard.getWorkbenchClipboard().getConcepts().size() > 1) {
                title = Messages.PasteEntitiesText;
            }
            XSDPasteConceptAction pasteConceptAction = new XSDPasteConceptAction(this, title);
            if (pasteConceptAction.checkInPasteType()) {
                manager.add(new Separator());
                manager.add(pasteConceptAction);
            }
        }
        return;
    }
    // Element Declaration
    if (obj instanceof XSDElementDeclaration && selectedObjs.length == 1) {
        // check if concept or "just" element
        XSDElementDeclaration decl = (XSDElementDeclaration) obj;
        boolean isConcept = Util.checkConcept(decl);
        if (!Util.IsAImporedElement(decl, xsdSchema)) {
            if (isConcept) {
                manager.add(editConceptAction);
                manager.add(deleteConceptAction);
                manager.add(newBrowseItemAction);
            } else {
                manager.add(editElementAction);
                manager.add(deleteElementAction);
            }
            // add by ymli. fix bug 0009770 add the copy of concepts
            copyConceptAction.setText(Messages.CopyEntityText);
            if (Util.checkInCopy(selectedObjs)) {
                manager.add(new Separator());
                manager.add(copyConceptAction);
            }
            /*
                 * boolean isMulti = false; if(WorkbenchClipboard.getWorkbenchClipboard().getConcepts().size()>1)
                 * isMulti = true;
                 */
            // $NON-NLS-1$
            String title = "";
            if (WorkbenchClipboard.getWorkbenchClipboard().getConcepts().size() > 1) {
                title = Messages.PasteEntitiesText;
            } else if (WorkbenchClipboard.getWorkbenchClipboard().getConcepts().size() == 1) {
                title = Messages.PasteEntityText;
            } else if (WorkbenchClipboard.getWorkbenchClipboard().getParticles().size() > 1) {
                title = Messages.PasteElementsText;
            } else if (WorkbenchClipboard.getWorkbenchClipboard().getParticles().size() == 1) {
                title = Messages.PasteElement;
            }
            XSDPasteConceptAction pasteConceptAction = new XSDPasteConceptAction(this, title);
            if (pasteConceptAction.checkInPasteType()) {
                manager.add(pasteConceptAction);
            }
            manager.add(new Separator());
            manager.add(newElementAction);
            manager.add(new Separator());
            manager.add(changeToComplexTypeAction);
            manager.add(changeToSimpleTypeAction);
            // add by fliu, see bugID:0009157
            if (((XSDElementDeclaration) obj).getTypeDefinition() instanceof XSDSimpleTypeDefinition) {
                manager.add(setFacetMsgAction);
                manager.add(setAnnotationDisplayFomatAction);
            }
            manager.add(new Separator());
            manager.add(newIdentityConstraintAction);
        } else {
            if (isConcept) {
                manager.add(newBrowseItemAction);
            }
            manager.add(newElementAction);
        }
        // Annotations
        if (!Util.IsAImporedElement(decl, xsdSchema) || !Util.IsAImporedElement(decl.getTypeDefinition(), xsdSchema)) {
            setAnnotationActions2(obj, manager);
        }
    }
    // add by rhou.fix bug 0012073: Enable to create element from sub element group
    if (obj instanceof XSDModelGroup) {
        manager.add(new Separator());
        manager.add(getAddElementMenuForTypeClass(XSDModelGroup.class, Messages._AddElement));
        manager.add(new Separator());
        manager.add(changeSubElementGroupAction);
        manager.add(new Separator());
        manager.add(setAnnotationLabelAction);
        addPasteElementAction(manager);
    }
    if (obj instanceof XSDAttributeUse && selectedObjs.length == 1) {
        manager.add(deleteAttributeAction);
    }
    if (obj instanceof XSDAttributeDeclaration && selectedObjs.length == 1) {
        manager.add(deleteAttributeAction);
    }
    if (obj instanceof XSDParticle && selectedObjs.length == 1) {
        XSDTerm term = ((XSDParticle) obj).getTerm();
        if (!(term instanceof XSDWildcard)) {
            if (term instanceof XSDElementDeclaration) {
                manager.add(editParticleAction);
                if (!Util.IsAImporedElement(term, xsdSchema) || term.getContainer() instanceof XSDSchema) {
                    manager.add(getAddElementMenuForTypeClass(XSDParticle.class, Messages._AddElementAfter));
                    if (term instanceof XSDModelGroup) {
                        manager.add(getAddElementMenuForTypeClass(XSDModelGroup.class, Messages._AddElement));
                        manager.add(newGroupFromTypeAction);
                    }
                    manager.add(deleteParticleAction);
                    // edit by ymli. fix the bug:0011523
                    copyConceptAction.setText(Messages.CopyElementText);
                    manager.add(copyConceptAction);
                    if (((XSDElementDeclaration) term).getTypeDefinition() instanceof XSDComplexTypeDefinition) {
                        addPasteElementAction(manager);
                    }
                    manager.add(new Separator());
                    manager.add(changeToComplexTypeAction);
                    manager.add(changeToSimpleTypeAction);
                    // add by fliu, see bugID:0009157
                    manager.add(new Separator());
                    // Annotations
                    XSDTypeDefinition type = ((XSDElementDeclaration) term).getTypeDefinition();
                    setAnnotationActions(obj, manager);
                    if (((XSDElementDeclaration) term).getTypeDefinition() instanceof XSDSimpleTypeDefinition) {
                        manager.add(setFacetMsgAction);
                        manager.add(setAnnotationDisplayFomatAction);
                    }
                    // Xpath
                    manager.add(new Separator());
                    manager.add(getXPathAction);
                }
            }
        }
    }
    if (obj instanceof XSDComplexTypeDefinition && selectedObjs.length == 1 && ((XSDComplexTypeDefinition) obj).getTargetNamespace() == null) {
        if (!isType && !Util.IsAImporedElement((XSDParticle) obj, xsdSchema)) {
            manager.add(getAddElementMenuForTypeClass(XSDComplexTypeDefinition.class, Messages._AddElement));
            manager.add(newGroupFromTypeAction);
        }
        if (!Util.IsAImporedElement((XSDComplexTypeDefinition) obj, xsdSchema)) {
            // add by rhou.fix bug 0012073: Enable to create element from sub element group
            manager.add(new Separator());
            manager.add(getAddElementMenuForTypeClass(XSDComplexTypeDefinition.class, Messages._AddElement));
            manager.add(new Separator());
            manager.add(editComplexTypeAction);
        }
        manager.add(setAnnotationLabelAction);
        addPasteElementAction(manager);
    }
    if (obj instanceof XSDIdentityConstraintDefinition && selectedObjs.length == 1 && ((XSDIdentityConstraintDefinition) obj).getTargetNamespace() == null && !Util.IsAImporedElement((XSDIdentityConstraintDefinition) obj, xsdSchema)) {
        manager.add(deleteIdentityConstraintAction);
        manager.add(new Separator());
        manager.add(newXPathAction);
    }
    if (obj instanceof XSDXPathDefinition && selectedObjs.length == 1 && ((XSDXPathDefinition) obj).getSchema().getTargetNamespace() == null && !Util.IsAImporedElement((XSDXPathDefinition) obj, xsdSchema)) {
        manager.add(editXPathAction);
        manager.add(newXPathAction);
        XSDXPathDefinition xpath = (XSDXPathDefinition) obj;
        if (xpath.getVariety().equals(XSDXPathVariety.FIELD_LITERAL)) {
            manager.add(deleteXPathAction);
        }
    }
    // for the anonymous simpleType
    if (obj instanceof XSDSimpleTypeDefinition && selectedObjs.length == 1 && (!Util.IsAImporedElement((XSDSimpleTypeDefinition) obj, xsdSchema) || ((XSDSimpleTypeDefinition) obj).getName() == null)) {
        XSDSimpleTypeDefinition typedef = (XSDSimpleTypeDefinition) obj;
        manager.add(changeBaseTypeAction);
        manager.add(new Separator());
        if (typedef.getBaseTypeDefinition() != null) {
            EList list = typedef.getBaseTypeDefinition().getValidFacets();
            for (Iterator iter = list.iterator(); iter.hasNext(); ) {
                String element = (String) iter.next();
                manager.add(new XSDEditFacetAction(this, element));
            }
        }
    }
    if (selectedObjs.length > 1 && deleteConceptWrapAction.checkInDeletableType(selectedObjs)) {
        deleteConceptWrapAction.prepareToDelSelectedItems(selection, viewer);
    }
    if (selectedObjs.length > 1 && deleteConceptWrapAction.checkInAllElementType(selectedObjs)) {
        manager.add(newBrowseItemAction);
    }
    if (selectedObjs.length > 1 && deleteConceptWrapAction.outPutDeleteActions() != null) {
        if (!isType) {
            manager.add(deleteConceptWrapAction.outPutDeleteActions());
        }
        // $NON-NLS-1$
        String title = "";
        if (Util.checkInCopyTypeElement(selectedObjs)) {
            title = Messages.CopyEntitiesText;
        } else if (Util.checkInCOpyTypeParticle(selectedObjs)) {
            title = Messages.CopyElements;
        }
        copyConceptAction.setText(title);
        if (Util.checkInCopy(selectedObjs)) {
            manager.add(copyConceptAction);
        }
        // add by ymli; fix bug:0016645
        if (selectedObjs.length > 1 && isXSDParticles(selectedObjs)) {
            manager.add(getAddElementMenuForTypeClass(XSDParticle.class, Messages._AddElementAfter));
        }
    }
    if (exAdapter != null) {
        exAdapter.fillContextMenu(manager, selectedObjs);
    }
    // available models
    java.util.List<IAvailableModel> availablemodels = AvailableModelUtil.getAvailableModels(isLocalInput());
    for (int i = 0; i < availablemodels.size(); i++) {
        IAvailableModel model = availablemodels.get(i);
        model.fillContextMenu(obj, manager, this, dataModelName);
        if (i == 1) {
            manager.add(new Separator());
        }
    }
    // 
    manager.add(new Separator());
    drillDownAdapter.addNavigationActions(manager);
    // Other plug-ins can contribute there actions here
    manager.add(new Separator(ADDITIONMENUID));
    deleteConceptWrapAction.clearExtraClassToDel();
}
Also used : XSDAttributeUse(org.eclipse.xsd.XSDAttributeUse) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition) Iterator(java.util.Iterator) XSDTerm(org.eclipse.xsd.XSDTerm) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDXPathDefinition(org.eclipse.xsd.XSDXPathDefinition) XSDParticle(org.eclipse.xsd.XSDParticle) XSDSchema(org.eclipse.xsd.XSDSchema) IAvailableModel(com.amalto.workbench.availablemodel.IAvailableModel) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) XSDPasteConceptAction(com.amalto.workbench.actions.XSDPasteConceptAction) XSDWildcard(org.eclipse.xsd.XSDWildcard) EList(org.eclipse.emf.common.util.EList) XSDEditFacetAction(com.amalto.workbench.actions.XSDEditFacetAction) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDIdentityConstraintDefinition(org.eclipse.xsd.XSDIdentityConstraintDefinition) TreeObject(com.amalto.workbench.models.TreeObject) XSDDeleteTypeDefinition(com.amalto.workbench.actions.XSDDeleteTypeDefinition) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration) Separator(org.eclipse.jface.action.Separator)

Example 25 with XSDComplexTypeDefinition

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

the class DataModelMainPage method openXSDParticleInSchemaTree.

private void openXSDParticleInSchemaTree() {
    for (Object eachSelectedObj : getSelectionInSchemaTree()) {
        viewer.collapseToLevel(eachSelectedObj, 3);
        if (eachSelectedObj instanceof XSDModelGroup) {
            viewer.expandToLevel(eachSelectedObj, 1);
        }
        if (eachSelectedObj instanceof XSDElementDeclaration) {
            viewer.expandToLevel(eachSelectedObj, 1);
            XSDTypeDefinition type = ((XSDElementDeclaration) eachSelectedObj).getTypeDefinition();
            if (type instanceof XSDComplexTypeDefinition) {
                XSDModelGroup mg = (XSDModelGroup) ((XSDParticle) ((XSDComplexTypeDefinition) type).getContent()).getTerm();
                viewer.expandToLevel(mg, 1);
            }
        }
    }
}
Also used : XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) TreeObject(com.amalto.workbench.models.TreeObject) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition)

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