Search in sources :

Example 6 with XSDAnnotationsStructure

use of com.amalto.workbench.utils.XSDAnnotationsStructure in project tmdm-studio-se by Talend.

the class XSDSetAnnotationForeignKeyAction method doAction.

@Override
public IStatus doAction() {
    try {
        IStructuredSelection selection = (TreeSelection) page.getTreeViewer().getSelection();
        XSDComponent xSDCom = null;
        if (selection.getFirstElement() instanceof Element) {
            TreePath tPath = ((TreeSelection) selection).getPaths()[0];
            for (int i = 0; i < tPath.getSegmentCount(); i++) {
                if (tPath.getSegment(i) instanceof XSDAnnotation) {
                    xSDCom = (XSDAnnotation) (tPath.getSegment(i));
                }
            }
        } else {
            xSDCom = (XSDComponent) selection.getFirstElement();
        }
        XSDAnnotationsStructure struc = null;
        if (xSDCom != null) {
            struc = new XSDAnnotationsStructure(xSDCom);
        }
        if (struc == null || struc.getAnnotation() == null) {
            throw new RuntimeException(Messages.bind(Messages.UnableEditType, xSDCom.getClass().getName()));
        }
        sxid = getNewSimpleXpathInputDlg(struc.getForeignKey());
        sxid.setLock(true);
        sxid.setPKXpaths(XSDUtil.getAllPKXpaths(schema));
        String fksep = struc.getForeignKeyNotSep();
        if (fksep != null) {
            sxid.setFkSep(Boolean.valueOf(fksep));
        }
        sxid.setBlockOnOpen(true);
        int ret = sxid.open();
        if (ret == Window.CANCEL) {
            return Status.CANCEL_STATUS;
        }
        // $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
        String fk = "".equals(sxid.getXpath()) ? null : sxid.getXpath().replaceAll("'|\"", "");
        // keep the foreignkey in memory to improve performance
        if (Util.getForeignKeys() != null && fk != null) {
            if (struc.getForeignKey() != null) {
                Util.getForeignKeys().remove(Util.getConceptFromPath(struc.getForeignKey()));
            }
            Util.getForeignKeys().add(Util.getConceptFromPath(fk));
        }
        struc.setForeignKey(fk);
        Boolean sep = sxid.getSepFk();
        struc.setForeignKeyNotSep(sep);
        updateAnnotationStructure(struc);
        if (struc.hasChanged()) {
            page.refresh();
            page.getTreeViewer().expandToLevel(xSDCom, 2);
            page.markDirty();
        }
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages.ErrorForeignKey, e.getLocalizedMessage()));
        return Status.CANCEL_STATUS;
    }
    return Status.OK_STATUS;
}
Also used : TreePath(org.eclipse.jface.viewers.TreePath) TreeSelection(org.eclipse.jface.viewers.TreeSelection) XSDAnnotationsStructure(com.amalto.workbench.utils.XSDAnnotationsStructure) Element(org.w3c.dom.Element) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) XSDAnnotation(org.eclipse.xsd.XSDAnnotation) XSDComponent(org.eclipse.xsd.XSDComponent)

Example 7 with XSDAnnotationsStructure

use of com.amalto.workbench.utils.XSDAnnotationsStructure in project tmdm-studio-se by Talend.

the class XSDNewParticleFromParticleAction method doAction.

public IStatus doAction() {
    try {
        IStructuredSelection selection = (IStructuredSelection) page.getTreeViewer().getSelection();
        selParticle = (XSDParticle) selection.getFirstElement();
        if (!(selParticle.getContainer() instanceof XSDModelGroup))
            return Status.CANCEL_STATUS;
        ;
        XSDModelGroup group = (XSDModelGroup) selParticle.getContainer();
        // get position of the selected particle in the container
        int index = 0;
        int i = 0;
        for (Iterator<XSDParticle> iter = group.getContents().iterator(); iter.hasNext(); ) {
            XSDParticle p = (XSDParticle) iter.next();
            if (p.equals(selParticle)) {
                index = i;
                break;
            }
            i++;
        }
        EList<XSDElementDeclaration> eDecls = schema.getElementDeclarations();
        List<String> elementDeclarations = new ArrayList<String>();
        for (Iterator<XSDElementDeclaration> iter = eDecls.iterator(); iter.hasNext(); ) {
            XSDElementDeclaration d = (XSDElementDeclaration) iter.next();
            if (d.getTargetNamespace() != null && d.getTargetNamespace().equals(IConstants.DEFAULT_NAME_SPACE))
                continue;
            // $NON-NLS-1$//$NON-NLS-2$
            elementDeclarations.add(d.getQName() + (d.getTargetNamespace() != null ? " : " + d.getTargetNamespace() : ""));
        }
        // $NON-NLS-1$
        elementDeclarations.add("");
        dialog = new BusinessElementInputDialog(this, page.getSite().getShell(), Messages._AddANewBusinessElement, null, null, elementDeclarations, 0, 1, true, false);
        dialog.setBlockOnOpen(true);
        int ret = dialog.open();
        if (ret == Dialog.CANCEL) {
            return Status.CANCEL_STATUS;
        }
        XSDElementDeclaration elem = (XSDElementDeclaration) selParticle.getContent();
        if (Util.changeElementTypeToSequence(elem, maxOccurs) == Status.CANCEL_STATUS) {
            return Status.CANCEL_STATUS;
        }
        XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory();
        XSDElementDeclaration decl = factory.createXSDElementDeclaration();
        decl.setName(this.elementName);
        if (!refName.equals("")) {
            // $NON-NLS-1$
            XSDElementDeclaration ref = Util.findReference(refName, schema);
            if (ref != null) {
                decl.setResolvedElementDeclaration(ref);
            }
        } else {
            decl.setTypeDefinition(schema.resolveSimpleTypeDefinition(schema.getSchemaForSchemaNamespace(), simpleTypeName));
        }
        XSDParticle particle = factory.createXSDParticle();
        particle.setContent(decl);
        particle.setMinOccurs(this.minOccurs);
        if (maxOccurs > -1) {
            particle.setMaxOccurs(this.maxOccurs);
        } else {
            particle.setMaxOccurs(this.maxOccurs);
            group.getContents().add(group.getContents().size(), particle);
            group.updateElement();
            if (// $NON-NLS-1$
            particle.getElement().getAttributeNode("maxOccurs") != null)
                // $NON-NLS-1$//$NON-NLS-2$
                particle.getElement().getAttributeNode("maxOccurs").setNodeValue("unbounded");
            else {
                // $NON-NLS-1$//$NON-NLS-2$
                particle.getElement().setAttribute("maxOccurs", "unbounded");
            }
        }
        if (maxOccurs > -1) {
            group.getContents().add(group.getContents().size(), particle);
            group.updateElement();
        }
        if (dialog.isInherit()) {
            XSDTerm totm = particle.getTerm();
            XSDElementDeclaration concept = null;
            if (Util.getParent(selParticle) instanceof XSDElementDeclaration)
                concept = (XSDElementDeclaration) Util.getParent(selParticle);
            else if (Util.getParent(selParticle) instanceof XSDComplexTypeDefinition) {
                if (selParticle instanceof XSDParticle)
                    concept = (XSDElementDeclaration) ((XSDParticle) selParticle).getContent();
                else if (selParticle instanceof XSDElementDeclaration)
                    concept = (XSDElementDeclaration) selParticle;
            }
            XSDAnnotation fromannotation = null;
            if (concept != null)
                fromannotation = concept.getAnnotation();
            if (fromannotation != null) {
                XSDAnnotationsStructure struc = new XSDAnnotationsStructure(totm);
                if (((XSDElementDeclaration) totm).getType() != null)
                    addAnnotion(struc, fromannotation);
            }
        }
        page.refresh();
        page.getTreeViewer().setSelection(new StructuredSelection(particle), true);
        page.markDirty();
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages._ErrorCreatBusinessElement, e.getLocalizedMessage()));
        return Status.CANCEL_STATUS;
    }
    return Status.OK_STATUS;
}
Also used : XSDFactory(org.eclipse.xsd.XSDFactory) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDAnnotationsStructure(com.amalto.workbench.utils.XSDAnnotationsStructure) ArrayList(java.util.ArrayList) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) BusinessElementInputDialog(com.amalto.workbench.dialogs.BusinessElementInputDialog) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDTerm(org.eclipse.xsd.XSDTerm) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDAnnotation(org.eclipse.xsd.XSDAnnotation) XSDParticle(org.eclipse.xsd.XSDParticle)

Example 8 with XSDAnnotationsStructure

use of com.amalto.workbench.utils.XSDAnnotationsStructure in project tmdm-studio-se by Talend.

the class DisplayFormatCommitHandler method doSubmit.

@Override
protected boolean doSubmit() throws CommitException {
    XSDAnnotationsStructure xsdAnnoStruct = getXSDAnnotationStruct();
    LinkedHashMap<String, String> langCode2Value = new LinkedHashMap<String, String>();
    for (Entry<String, LanguageInfo> eachLangCode2LangInfo : getCommitedObj().getLangCode2LangInfo().entrySet()) langCode2Value.put(eachLangCode2LangInfo.getKey(), eachLangCode2LangInfo.getValue().getLabel());
    return xsdAnnoStruct.setDisplayFormat(langCode2Value);
}
Also used : LanguageInfo(com.amalto.workbench.detailtabs.sections.model.annotationinfo.langinfo.LanguageInfo) XSDAnnotationsStructure(com.amalto.workbench.utils.XSDAnnotationsStructure) LinkedHashMap(java.util.LinkedHashMap)

Example 9 with XSDAnnotationsStructure

use of com.amalto.workbench.utils.XSDAnnotationsStructure in project tmdm-studio-se by Talend.

the class ElementForeighKeyCommitHandler method doSubmit.

@Override
protected boolean doSubmit() throws CommitException {
    XSDAnnotationsStructure xsdAnnoStruct = getXSDAnnotationStruct();
    String[] values = getCommitedObj().getValues();
    if (Util.getForeignKeys() != null && values != null) {
        if (xsdAnnoStruct.getForeignKey() != null)
            Util.getForeignKeys().remove(Util.getConceptFromPath(xsdAnnoStruct.getForeignKey()));
        Util.getForeignKeys().add(Util.getConceptFromPath(values[0]));
    }
    if (values.length > 1) {
        xsdAnnoStruct.setForeignKeyNotSep(Boolean.valueOf(values[1]));
    }
    boolean setForeignKey = xsdAnnoStruct.setForeignKey(values[0]);
    doUpdateFKAnnotationStructure(xsdAnnoStruct);
    return setForeignKey;
}
Also used : XSDAnnotationsStructure(com.amalto.workbench.utils.XSDAnnotationsStructure)

Example 10 with XSDAnnotationsStructure

use of com.amalto.workbench.utils.XSDAnnotationsStructure in project tmdm-studio-se by Talend.

the class ElementForeignKeyInfosCommitHandler method doSubmit.

@Override
protected boolean doSubmit() throws CommitException {
    XSDAnnotationsStructure xsdAnnoStruct = getXSDAnnotationStruct();
    try {
        xsdAnnoStruct.setForeignKeyInfos(Arrays.asList(getCommitedObj().getInfos()));
        xsdAnnoStruct.setFormatForeignKeyInfo(getCommitedObj().getFormatFkInfo());
        doUpdateFKAnnotationStructure(xsdAnnoStruct);
    } catch (Exception e) {
        throw new CommitException(e.getMessage(), e);
    }
    return true;
}
Also used : CommitException(com.amalto.workbench.detailtabs.exception.CommitException) XSDAnnotationsStructure(com.amalto.workbench.utils.XSDAnnotationsStructure) CommitException(com.amalto.workbench.detailtabs.exception.CommitException) CommitValidationException(com.amalto.workbench.detailtabs.exception.CommitValidationException)

Aggregations

XSDAnnotationsStructure (com.amalto.workbench.utils.XSDAnnotationsStructure)33 XSDAnnotation (org.eclipse.xsd.XSDAnnotation)17 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)16 XSDComponent (org.eclipse.xsd.XSDComponent)13 Element (org.w3c.dom.Element)13 TreePath (org.eclipse.jface.viewers.TreePath)12 TreeSelection (org.eclipse.jface.viewers.TreeSelection)12 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)10 XSDParticle (org.eclipse.xsd.XSDParticle)8 XSDModelGroup (org.eclipse.xsd.XSDModelGroup)7 ArrayList (java.util.ArrayList)6 SelectionEvent (org.eclipse.swt.events.SelectionEvent)5 SelectionListener (org.eclipse.swt.events.SelectionListener)5 XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)5 XSDTerm (org.eclipse.xsd.XSDTerm)5 AnnotationLanguageLabelsDialog (com.amalto.workbench.dialogs.AnnotationLanguageLabelsDialog)4 XSDFactory (org.eclipse.xsd.XSDFactory)4 CommitException (com.amalto.workbench.detailtabs.exception.CommitException)3 CommitValidationException (com.amalto.workbench.detailtabs.exception.CommitValidationException)3 LanguageInfo (com.amalto.workbench.detailtabs.sections.model.annotationinfo.langinfo.LanguageInfo)3