Search in sources :

Example 26 with XSDAnnotationsStructure

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

the class DataModelMainPage method setLabelForElement.

private void setLabelForElement(XSDElementDeclaration xSDEle, boolean isAdd) {
    if (xSDEle.getTypeDefinition() instanceof XSDComplexTypeDefinition) {
        XSDAnnotationsStructure struc = null;
        String labelValue = null;
        List childrenList = Util.getComplexTypeDefinitionChildren((XSDComplexTypeDefinition) xSDEle.getTypeDefinition());
        for (int j = 0; j < childrenList.size(); j++) {
            List<XSDParticle> particles = new ArrayList<XSDParticle>();
            if (childrenList.get(j) instanceof XSDModelGroup) {
                particles = ((XSDModelGroup) childrenList.get(j)).getParticles();
            }
            for (int k = 0; k < particles.size(); k++) {
                XSDParticle xSDCom = particles.get(k);
                struc = new XSDAnnotationsStructure(xSDCom);
                if (xSDCom.getContent() instanceof XSDElementDeclaration) {
                    labelValue = ((XSDElementDeclaration) xSDCom.getContent()).getName();
                    setLabel(struc, labelValue, isAdd);
                    setLabelForElement((XSDElementDeclaration) xSDCom.getContent(), isAdd);
                }
            }
        }
    }
}
Also used : XSDAnnotationsStructure(com.amalto.workbench.utils.XSDAnnotationsStructure) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) ArrayList(java.util.ArrayList) List(java.util.List) EList(org.eclipse.emf.common.util.EList) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDParticle(org.eclipse.xsd.XSDParticle)

Example 27 with XSDAnnotationsStructure

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

the class DataModelMainPage method addLabelForTheItem.

private void addLabelForTheItem(TreeItem[] items, boolean isAdd) {
    XSDComponent xSDCom = null;
    for (TreeItem item : items) {
        XSDAnnotationsStructure struc = null;
        String labelValue = null;
        if (item.getData() instanceof XSDElementDeclaration) {
            xSDCom = (XSDElementDeclaration) item.getData();
            struc = new XSDAnnotationsStructure(xSDCom);
            labelValue = ((XSDElementDeclaration) xSDCom).getName();
            setLabel(struc, labelValue, isAdd);
            setLabelForElement((XSDElementDeclaration) xSDCom, isAdd);
        }
    }
}
Also used : TreeItem(org.eclipse.swt.widgets.TreeItem) XSDAnnotationsStructure(com.amalto.workbench.utils.XSDAnnotationsStructure) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDComponent(org.eclipse.xsd.XSDComponent)

Example 28 with XSDAnnotationsStructure

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

the class XSDPasteConceptAction method addAnnotationForComplexType.

public void addAnnotationForComplexType(XSDComplexTypeDefinition fromType, XSDComplexTypeDefinition toType) {
    XSDComplexTypeContent tocomplexType = toType.getContent();
    XSDComplexTypeContent fromcomplexType = fromType.getContent();
    if (fromcomplexType instanceof XSDParticle) {
        XSDParticle fromxsdParticle = (XSDParticle) fromcomplexType;
        XSDParticle toxsdParticle = (XSDParticle) tocomplexType;
        if (fromxsdParticle.getTerm() instanceof XSDModelGroup) {
            XSDModelGroup frommodelGroup = ((XSDModelGroup) fromxsdParticle.getTerm());
            XSDModelGroup tomodelGroup = ((XSDModelGroup) toxsdParticle.getTerm());
            EList<XSDParticle> fromlist = frommodelGroup.getContents();
            EList<XSDParticle> tolist = tomodelGroup.getContents();
            Iterator<XSDParticle> toIt = tolist.iterator();
            for (XSDParticle fromel : fromlist.toArray(new XSDParticle[fromlist.size()])) {
                XSDParticle toel = toIt.next();
                XSDTerm totm = toel.getTerm();
                XSDTerm fromtm = fromel.getTerm();
                if (fromtm instanceof XSDElementDeclaration) {
                    XSDAnnotation fromannotation = ((XSDElementDeclaration) fromtm).getAnnotation();
                    if (fromannotation != null) {
                        XSDAnnotationsStructure struc = new XSDAnnotationsStructure(totm);
                        addAnnotion(struc, fromannotation);
                        if (this.typeList.containsKey(((XSDElementDeclaration) totm).getType().getName())) {
                            this.copyTypeSet.add(this.typeList.get(((XSDElementDeclaration) totm).getType().getName()));
                        }
                        addAnnotationForXSDElementDeclaration((XSDElementDeclaration) fromtm, (XSDElementDeclaration) totm);
                    }
                }
            }
        }
    }
}
Also used : XSDComplexTypeContent(org.eclipse.xsd.XSDComplexTypeContent) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDAnnotationsStructure(com.amalto.workbench.utils.XSDAnnotationsStructure) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDTerm(org.eclipse.xsd.XSDTerm) XSDAnnotation(org.eclipse.xsd.XSDAnnotation) XSDParticle(org.eclipse.xsd.XSDParticle)

Example 29 with XSDAnnotationsStructure

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

the class XSDPasteConceptAction method copyElements.

// edit by ymli; fix the bug:0011523: pasty partcles to the element
public void copyElements() {
    ArrayList<XSDParticle> particles = WorkbenchClipboard.getWorkbenchClipboard().getParticles();
    IStructuredSelection selection = (IStructuredSelection) page.getTreeViewer().getSelection();
    XSDComplexTypeContent content = null;
    XSDElementDeclaration element = null;
    if (selection.getFirstElement() instanceof XSDElementDeclaration) {
        element = (XSDElementDeclaration) selection.getFirstElement();
        content = ((XSDComplexTypeDefinition) element.getTypeDefinition()).getContent();
    } else if (selection.getFirstElement() instanceof XSDComplexTypeDefinition) {
        content = ((XSDComplexTypeDefinition) selection.getFirstElement()).getContent();
    } else if (selection.getFirstElement() instanceof XSDModelGroup) {
        XSDComplexTypeDefinition complexType = (XSDComplexTypeDefinition) ((XSDModelGroup) selection.getFirstElement()).getContainer().getContainer();
        content = complexType.getContent();
    } else {
        if (selection.getFirstElement() instanceof XSDParticle) {
            XSDParticle particle = (XSDParticle) selection.getFirstElement();
            XSDElementDeclaration declar = (XSDElementDeclaration) particle.getTerm();
            if (declar.getTypeDefinition() instanceof XSDComplexTypeDefinition) {
                XSDComplexTypeDefinition typeDefinition = (XSDComplexTypeDefinition) declar.getTypeDefinition();
                content = typeDefinition.getContent();
            }
        }
    }
    if (content instanceof XSDParticle) {
        XSDParticle partile = (XSDParticle) content;
        if (partile.getTerm() instanceof XSDModelGroup) {
            XSDModelGroup toGroup = ((XSDModelGroup) partile.getTerm());
            for (XSDParticle particle : particles) {
                // if the is particle with the same name, donot copy it.
                if (isExist(toGroup, particle)) {
                    boolean ifOverwrite = MessageDialog.openConfirm(this.page.getSite().getShell(), Messages.XSDPasteConceptAction_Confirm, Messages.bind(Messages.XSDPasteConceptAction_ErrorMsg3, ((XSDElementDeclaration) particle.getTerm()).getName()));
                    if (ifOverwrite) {
                        reomveElement(toGroup, particle);
                    } else {
                        continue;
                    }
                }
                XSDParticle newParticle = (XSDParticle) particle.cloneConcreteComponent(true, false);
                if (newParticle.getContent() instanceof XSDElementDeclaration && Util.changeElementTypeToSequence(element, newParticle.getMaxOccurs()) == Status.CANCEL_STATUS) {
                    break;
                }
                toGroup.getContents().add(newParticle);
                toGroup.updateElement();
                if (newParticle.getContent() instanceof XSDElementDeclaration) {
                    if (((XSDElementDeclaration) newParticle.getContent()).getTypeDefinition() instanceof XSDComplexTypeDefinition) {
                        addAnnotationForComplexType((XSDComplexTypeDefinition) ((XSDElementDeclaration) particle.getContent()).getTypeDefinition(), (XSDComplexTypeDefinition) ((XSDElementDeclaration) newParticle.getContent()).getTypeDefinition());
                    }
                    XSDAnnotationsStructure struc1 = new XSDAnnotationsStructure(newParticle.getTerm());
                    addAnnotion(struc1, ((XSDElementDeclaration) particle.getTerm()).getAnnotation());
                    Util.changeElementTypeToSequence((XSDElementDeclaration) newParticle.getContent(), newParticle.getMaxOccurs());
                }
            }
        }
    }
}
Also used : XSDComplexTypeContent(org.eclipse.xsd.XSDComplexTypeContent) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDAnnotationsStructure(com.amalto.workbench.utils.XSDAnnotationsStructure) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDParticle(org.eclipse.xsd.XSDParticle)

Example 30 with XSDAnnotationsStructure

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

the class XSDSetAnnotationDescriptionsAction method doAction.

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 = new XSDAnnotationsStructure(xSDCom);
        if (struc.getAnnotation() == null) {
            throw new RuntimeException(Messages.bind(Messages.XSDSetAnnotationXX_ExceptionInfo2, xSDCom.getClass().getName()));
        }
        AnnotationLanguageLabelsDialog dlg = new AnnotationLanguageLabelsDialog(struc.getDescriptions(), new AnnotationLabelDialogSelectionListener(page), page.getEditorSite().getShell(), Messages.XSDSetAnnotationXX_SetDescOfThisItem);
        dlg.setBlockOnOpen(true);
        dlg.open();
        if (dlg.getReturnCode() == Window.OK) {
            // remove existing annotations with labels
            struc.removeAllDescriptions();
            // add the new ones
            LinkedHashMap<String, String> descriptions = dlg.getDescriptionsMap();
            Set<String> isoCodes = descriptions.keySet();
            for (Iterator iter = isoCodes.iterator(); iter.hasNext(); ) {
                String isoCode = (String) iter.next();
                struc.setDescription(isoCode, descriptions.get(isoCode));
            }
        } else {
            return Status.CANCEL_STATUS;
        }
        if (struc.hasChanged()) {
            page.markDirty();
            page.refresh();
            page.getTreeViewer().expandToLevel(xSDCom, 2);
        }
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages.XSDSetAnnotationXX_ErrorMsg, e.getLocalizedMessage()));
        return Status.CANCEL_STATUS;
    }
    return Status.OK_STATUS;
}
Also used : XSDAnnotationsStructure(com.amalto.workbench.utils.XSDAnnotationsStructure) Element(org.w3c.dom.Element) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) XSDComponent(org.eclipse.xsd.XSDComponent) TreePath(org.eclipse.jface.viewers.TreePath) TreeSelection(org.eclipse.jface.viewers.TreeSelection) Iterator(java.util.Iterator) AnnotationLanguageLabelsDialog(com.amalto.workbench.dialogs.AnnotationLanguageLabelsDialog) XSDAnnotation(org.eclipse.xsd.XSDAnnotation)

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