Search in sources :

Example 41 with XSDFactory

use of org.eclipse.xsd.XSDFactory in project webtools.sourceediting by eclipse.

the class AddXSDModelGroupDefinitionCommand method createModelGroup.

protected XSDModelGroup createModelGroup() {
    XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory();
    XSDParticle particle = factory.createXSDParticle();
    XSDModelGroup modelGroup = factory.createXSDModelGroup();
    modelGroup.setCompositor(XSDCompositor.SEQUENCE_LITERAL);
    particle.setContent(modelGroup);
    return modelGroup;
}
Also used : XSDFactory(org.eclipse.xsd.XSDFactory) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDParticle(org.eclipse.xsd.XSDParticle)

Example 42 with XSDFactory

use of org.eclipse.xsd.XSDFactory in project webtools.sourceediting by eclipse.

the class AddXSDModelGroupDefinitionCommand method execute.

/*
   * (non-Javadoc)
   * 
   * @see org.eclipse.gef.commands.Command#execute()
   */
public void execute() {
    if (parent instanceof XSDSchema) {
        ensureSchemaElement((XSDSchema) parent);
    }
    try {
        beginRecording(parent.getElement());
        if (!isReference) {
            XSDModelGroupDefinition def = createXSDModelGroupDefinition();
            addedXSDConcreteComponent = def;
        } else {
            XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory();
            XSDModelGroupDefinition def = factory.createXSDModelGroupDefinition();
            XSDParticle particle = XSDFactory.eINSTANCE.createXSDParticle();
            particle.setContent(def);
            List list = parent.getSchema().getModelGroupDefinitions();
            int length = list.size();
            if (length > 1) {
                for (int i = 0; i < length; i++) {
                    XSDModelGroupDefinition gr = (XSDModelGroupDefinition) list.get(i);
                    if (gr.getModelGroup() != parent) {
                        def.setResolvedModelGroupDefinition(gr);
                    }
                }
            } else if (length <= 1) {
                XSDModelGroupDefinition newGroupDef = createXSDModelGroupDefinition();
                def.setResolvedModelGroupDefinition(newGroupDef);
            }
            if (parent instanceof XSDModelGroup) {
                ((XSDModelGroup) parent).getContents().add(particle);
            }
            formatChild(def.getElement());
            addedXSDConcreteComponent = def;
        }
    } finally {
        endRecording();
    }
}
Also used : XSDFactory(org.eclipse.xsd.XSDFactory) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) List(java.util.List) XSDModelGroupDefinition(org.eclipse.xsd.XSDModelGroupDefinition) XSDParticle(org.eclipse.xsd.XSDParticle) XSDSchema(org.eclipse.xsd.XSDSchema)

Example 43 with XSDFactory

use of org.eclipse.xsd.XSDFactory in project webtools.sourceediting by eclipse.

the class AddXSDModelGroupCommand method createModelGroup.

protected XSDModelGroup createModelGroup() {
    XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory();
    XSDParticle particle = factory.createXSDParticle();
    XSDModelGroup modelGroup = factory.createXSDModelGroup();
    modelGroup.setCompositor(xsdCompositor);
    particle.setContent(modelGroup);
    addedXSDConcreteComponent = modelGroup;
    return modelGroup;
}
Also used : XSDFactory(org.eclipse.xsd.XSDFactory) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDParticle(org.eclipse.xsd.XSDParticle)

Example 44 with XSDFactory

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

the class XSDNewXPathAction method doAction.

@Override
public IStatus doAction() {
    try {
        int index = 0;
        IStructuredSelection selection = (IStructuredSelection) page.getTreeViewer().getSelection();
        if (selection.getFirstElement() instanceof XSDIdentityConstraintDefinition) {
            icd = (XSDIdentityConstraintDefinition) selection.getFirstElement();
        } else if (selection.getFirstElement() instanceof XSDXPathDefinition) {
            XSDXPathDefinition xpath = (XSDXPathDefinition) selection.getFirstElement();
            icd = (XSDIdentityConstraintDefinition) xpath.getContainer();
            if (xpath.getVariety().equals(XSDXPathVariety.FIELD_LITERAL))
                index = icd.getFields().indexOf(xpath) + 1;
            else
                index = 0;
        } else {
            MessageDialog.openError(this.page.getSite().getShell(), Messages._Error, Messages.XSDNewXPathAction_Huhhh + selection.getFirstElement().getClass().getName());
            return Status.CANCEL_STATUS;
        }
        // InputDialog id = new InputDialog(
        // page.getSite().getShell(),
        // "New XPath",
        // "Enter a new XPath to the field",
        // null,
        // new IInputValidator() {
        // public String isValid(String newText) {
        // if ((newText==null) || "".equals(newText)) return "The XPath cannot be empty";
        // return null;
        // };
        // }
        // );
        // $NON-NLS-1$
        List<String> childNames = Util.getChildElementNames("", (XSDElementDeclaration) icd.getContainer());
        // filter the non top level fields
        List<String> topChilds = new ArrayList<String>();
        for (String child : childNames) {
            if (child.indexOf('/') == -1) {
                topChilds.add(child);
            }
        }
        // forbid to add already exists field
        EList<XSDXPathDefinition> fields = icd.getFields();
        for (XSDXPathDefinition fd : fields) {
            if (topChilds.contains(fd.getValue()))
                topChilds.remove(fd.getValue());
        }
        SelectFieldDialog id = new SelectFieldDialog(page.getSite().getShell(), Messages.XSDNewXPathAction_SelectOnField, topChilds, null);
        id.create();
        id.setBlockOnOpen(true);
        int ret = id.open();
        if (ret == Dialog.CANCEL) {
            return Status.CANCEL_STATUS;
        }
        String field = id.getField();
        if (field.length() == 0)
            return Status.CANCEL_STATUS;
        XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory();
        XSDXPathDefinition xpath = factory.createXSDXPathDefinition();
        xpath.setValue(field);
        xpath.setVariety(XSDXPathVariety.FIELD_LITERAL);
        icd.getFields().add(index, xpath);
        icd.updateElement();
        updateElementForAddedfield(icd, field);
        page.refresh();
        page.getTreeViewer().setSelection(new StructuredSelection(xpath), true);
        page.markDirty();
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages.ErrorMsg, e.getLocalizedMessage()));
        return Status.CANCEL_STATUS;
    }
    return Status.OK_STATUS;
}
Also used : XSDFactory(org.eclipse.xsd.XSDFactory) SelectFieldDialog(com.amalto.workbench.dialogs.SelectFieldDialog) ArrayList(java.util.ArrayList) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) XSDIdentityConstraintDefinition(org.eclipse.xsd.XSDIdentityConstraintDefinition) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) XSDXPathDefinition(org.eclipse.xsd.XSDXPathDefinition)

Example 45 with XSDFactory

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

the class XSDPasteConceptAction method doAction.

@Override
public IStatus doAction() {
    try {
        conceptList = WorkbenchClipboard.getWorkbenchClipboard().getConcepts();
        XSDFactory factory = XSDFactory.eINSTANCE;
        if (!conceptList.isEmpty()) {
            // List<String> concepts = new ArrayList<String>();
            int index = 0;
            for (Iterator<XSDElementDeclaration> it = conceptList.iterator(); it.hasNext(); ) {
                if (conceptList.get(index).getSchema() != null) {
                    // concepts = Util.getConcepts(conceptList.get(index).getSchema());
                    typeList = Util.getTypeDefinition(conceptList.get(index).getSchema());
                }
                index++;
                Object concept = it.next();
                if (concept instanceof XSDElementDeclaration) {
                    // edit by ymli,fix the bug:0011523. let the element(simple or complex) can be pasted
                    // if (concepts.contains(((XSDElementDeclaration) concept).getName())) {
                    XSDElementDeclaration copy_concept = (XSDElementDeclaration) concept;
                    XSDElementDeclaration new_copy_concept = factory.createXSDElementDeclaration();
                    new_copy_concept = (XSDElementDeclaration) copy_concept.cloneConcreteComponent(true, false);
                    InputDialog id = new InputDialog(page.getSite().getShell(), Messages.XSDPasteConceptAction_CopyElement, Messages.XSDPasteConceptAction_DialogTip, Messages.bind(Messages.XSDPasteConceptAction_CopyOf, copy_concept.getName()), new IInputValidator() {

                        public String isValid(String newText) {
                            if ((newText == null) || "".equals(newText)) {
                                return Messages.XSDPasteConceptAction_NameCannNotbeEmpty;
                            }
                            EList<XSDElementDeclaration> list = schema.getElementDeclarations();
                            for (XSDElementDeclaration d : list) {
                                if (d.getName().equalsIgnoreCase(newText)) {
                                    return Messages.XSDPasteConceptAction_EntityAlreadyExists;
                                }
                            }
                            return null;
                        }
                    });
                    id.setBlockOnOpen(true);
                    int ret = id.open();
                    if (ret == Window.CANCEL) {
                        return Status.CANCEL_STATUS;
                    }
                    new_copy_concept.setName(id.getValue());
                    for (int i = 0; i < new_copy_concept.getIdentityConstraintDefinitions().size(); i++) {
                        String name = new_copy_concept.getIdentityConstraintDefinitions().get(i).getName().replaceAll(copy_concept.getName(), new_copy_concept.getName());
                        new_copy_concept.getIdentityConstraintDefinitions().get(i).setName(name);
                    }
                    if (new_copy_concept.getAnonymousTypeDefinition() == null) {
                        XSDComplexTypeDefinition copyType = (XSDComplexTypeDefinition) copy_concept.getTypeDefinition().cloneConcreteComponent(true, false);
                        String originalName = copyType.getName();
                        // $NON-NLS-1$
                        String typeName = "Copy_of_" + originalName;
                        copyType.setName(typeName);
                        schema.getContents().add(copyType);
                        new_copy_concept.setTypeDefinition(copyType);
                    }
                    new_copy_concept.updateElement();
                    schema.getContents().add(new_copy_concept);
                    addAnnotationForXSDElementDeclaration(copy_concept, new_copy_concept);
                }
            }
            Map<String, XSDTypeDefinition> typeDef = Util.getTypeDefinition(schema);
            for (XSDTypeDefinition type : copyTypeSet) {
                if (typeDef.containsKey(type.getName())) {
                    continue;
                }
                XSDTypeDefinition typedefinitionClone = null;
                if (type instanceof XSDComplexTypeDefinition) {
                    typedefinitionClone = factory.createXSDComplexTypeDefinition();
                    typedefinitionClone = (XSDComplexTypeDefinition) type.cloneConcreteComponent(true, false);
                    schema.getContents().add(typedefinitionClone);
                    addAnnotationForComplexType((XSDComplexTypeDefinition) type, (XSDComplexTypeDefinition) typedefinitionClone);
                } else if (type instanceof XSDSimpleTypeDefinition) {
                    schema.getContents().add((XSDSimpleTypeDefinition) type.cloneConcreteComponent(true, false));
                }
            }
            schema.getElement();
            // WSDataModel wsObject = (WSDataModel)
            // (page.getXObject().getWsObject());
            // wsObject.getXsdSchema();//.setXsdSchema(Util.nodeToString(
            // schema.getDocument()));
            /*
                 * String schema1 = ((XSDTreeContentProvider) page.getViewer()
                 * .getContentProvider()).getXSDSchemaAsString(); wsObject.setXsdSchema(schema1); XMLEditor
                 * xmleditor=((XObjectEditor)page.getEditor()).getXmlEditor(); xmleditor.refresh(page.getXObject());
                 */
            page.markDirty();
            page.refresh();
            // page.refreshData();
            getOperationHistory();
            WorkbenchClipboard.getWorkbenchClipboard().conceptsReset();
            typeList.clear();
            return Status.OK_STATUS;
        } else if (WorkbenchClipboard.getWorkbenchClipboard().getParticles().size() > 0) {
            copyElements();
            WorkbenchClipboard.getWorkbenchClipboard().particlesReset();
            page.markDirty();
            page.refresh();
            // page.refreshData();
            getOperationHistory();
            return Status.OK_STATUS;
        } else {
            return Status.CANCEL_STATUS;
        }
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages.XSDPasteConceptAction_ErrorMsg1, e.getLocalizedMessage()));
    }
    return Status.OK_STATUS;
}
Also used : XSDFactory(org.eclipse.xsd.XSDFactory) InputDialog(org.eclipse.jface.dialogs.InputDialog) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition) EList(org.eclipse.emf.common.util.EList) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Aggregations

XSDFactory (org.eclipse.xsd.XSDFactory)50 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)37 XSDParticle (org.eclipse.xsd.XSDParticle)27 XSDModelGroup (org.eclipse.xsd.XSDModelGroup)26 XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)23 Test (org.junit.Test)19 XSDSimpleTypeDefinition (org.eclipse.xsd.XSDSimpleTypeDefinition)15 XSDIdentityConstraintDefinition (org.eclipse.xsd.XSDIdentityConstraintDefinition)13 ArrayList (java.util.ArrayList)12 XSDSchema (org.eclipse.xsd.XSDSchema)12 XSDTypeDefinition (org.eclipse.xsd.XSDTypeDefinition)12 XSDXPathDefinition (org.eclipse.xsd.XSDXPathDefinition)12 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)10 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)10 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)9 XSDAnnotation (org.eclipse.xsd.XSDAnnotation)8 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)6 HashSet (java.util.HashSet)5 Iterator (java.util.Iterator)5 List (java.util.List)5