Search in sources :

Example 11 with XSDAnnotation

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

the class XSDSetAnnotaionDisplayFormatAction 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);
        // XSDAnnotationsStructure struc = new XSDAnnotationsStructure((XSDComponent)selection.getFirstElement());
        if (struc.getAnnotation() == null) {
            throw new RuntimeException(Messages.XSDSetAnnoXX_ExceptionInfo + selection.getFirstElement().getClass().getName());
        }
        dlg = new AnnotationLanguageLabelsDialog(struc.getDisplayFormat(), new SelectionListener() {

            public void widgetDefaultSelected(SelectionEvent e) {
            }

            public void widgetSelected(SelectionEvent e) {
                dlg.close();
            }
        }, page.getSite().getShell(), Messages.XSDSetAnnoXX_DialogTitle2);
        dlg.setBlockOnOpen(true);
        int ret = dlg.open();
        if (ret == Window.CANCEL) {
            return Status.CANCEL_STATUS;
        }
        LinkedHashMap<String, String> fomats = dlg.getDescriptionsMap();
        struc.setDisplayFormat(fomats);
        if (struc.hasChanged()) {
            page.refresh();
            page.getTreeViewer().expandToLevel(selection.getFirstElement(), 2);
            page.markDirty();
        }
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages.XSDSetAnnoXX_ErrorMsg2, 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) SelectionEvent(org.eclipse.swt.events.SelectionEvent) AnnotationLanguageLabelsDialog(com.amalto.workbench.dialogs.AnnotationLanguageLabelsDialog) XSDAnnotation(org.eclipse.xsd.XSDAnnotation) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 12 with XSDAnnotation

use of org.eclipse.xsd.XSDAnnotation 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 13 with XSDAnnotation

use of org.eclipse.xsd.XSDAnnotation 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 14 with XSDAnnotation

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

the class XSDSetAnnotationPrimaryKeyInfoAction 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);
        struc.setXSDSchema(schema);
        if (struc.getAnnotation() == null) {
            throw new RuntimeException(Messages.bind(Messages.XSDSetAnnotationXX_ExceptionInfo1, xSDCom.getClass().getName()));
        }
        dlg = new AnnotationOrderedListsDialog(new ArrayList(struc.getPrimaryKeyInfos().values()), new SelectionListener() {

            public void widgetDefaultSelected(SelectionEvent e) {
            }

            public void widgetSelected(SelectionEvent e) {
                dlg.close();
            }
        }, // $NON-NLS-1$
        page.getSite().getShell(), // $NON-NLS-1$
        Messages.XSDSetAnnotationXX_DialogTitle, // $NON-NLS-1$
        "xPaths", // $NON-NLS-1$
        page, AnnotationOrderedListsDialog.AnnotationPrimaKeyInfo_ActionType, null);
        dlg.setBlockOnOpen(true);
        int ret = dlg.open();
        if (ret == Window.CANCEL) {
            return Status.CANCEL_STATUS;
        }
        struc.setAccessRole(dlg.getXPaths(), false, (IStructuredContentProvider) page.getTreeViewer().getContentProvider(), // $NON-NLS-1$
        "X_PrimaryKeyInfo");
        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.XSDSetAnnotationXX_Msg, e.getLocalizedMessage()));
        return Status.CANCEL_STATUS;
    }
    return Status.OK_STATUS;
}
Also used : XSDAnnotationsStructure(com.amalto.workbench.utils.XSDAnnotationsStructure) Element(org.w3c.dom.Element) AnnotationOrderedListsDialog(com.amalto.workbench.dialogs.AnnotationOrderedListsDialog) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) XSDComponent(org.eclipse.xsd.XSDComponent) TreePath(org.eclipse.jface.viewers.TreePath) TreeSelection(org.eclipse.jface.viewers.TreeSelection) SelectionEvent(org.eclipse.swt.events.SelectionEvent) XSDAnnotation(org.eclipse.xsd.XSDAnnotation) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 15 with XSDAnnotation

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

the class XSDSetAnnotationSourceSystemAction 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);
        // XSDAnnotationsStructure struc = new XSDAnnotationsStructure((XSDComponent)selection.getFirstElement());
        if (struc.getAnnotation() == null) {
            throw new RuntimeException(Messages.bind(Messages.ExceptionInfo, xSDCom.getClass().getName()));
        }
        InputDialog id = new InputDialog(page.getSite().getShell(), Messages.XSDSetAnnoXX_DialogTitle1, Messages.XSDSetAnnoXX_DialogTip, struc.getSourceSystem(), new IInputValidator() {

            public String isValid(String newText) {
                return null;
            }
        });
        id.setBlockOnOpen(true);
        int ret = id.open();
        if (ret == Window.CANCEL) {
            return Status.CANCEL_STATUS;
        }
        // $NON-NLS-1$
        struc.setSourceSystem("".equals(id.getValue()) ? null : id.getValue());
        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.XSDSetAnnoXX_ErrorMsg1, e.getLocalizedMessage()));
        return Status.CANCEL_STATUS;
    }
    return Status.OK_STATUS;
}
Also used : InputDialog(org.eclipse.jface.dialogs.InputDialog) 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) XSDAnnotation(org.eclipse.xsd.XSDAnnotation) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Aggregations

XSDAnnotation (org.eclipse.xsd.XSDAnnotation)55 Element (org.w3c.dom.Element)33 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)28 XSDParticle (org.eclipse.xsd.XSDParticle)21 XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)20 XSDModelGroup (org.eclipse.xsd.XSDModelGroup)20 XSDAnnotationsStructure (com.amalto.workbench.utils.XSDAnnotationsStructure)17 ArrayList (java.util.ArrayList)16 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)16 XSDTerm (org.eclipse.xsd.XSDTerm)16 TreePath (org.eclipse.jface.viewers.TreePath)13 TreeSelection (org.eclipse.jface.viewers.TreeSelection)13 XSDComponent (org.eclipse.xsd.XSDComponent)13 XSDIdentityConstraintDefinition (org.eclipse.xsd.XSDIdentityConstraintDefinition)13 XSDSimpleTypeDefinition (org.eclipse.xsd.XSDSimpleTypeDefinition)12 XSDTypeDefinition (org.eclipse.xsd.XSDTypeDefinition)10 XSDXPathDefinition (org.eclipse.xsd.XSDXPathDefinition)10 EList (org.eclipse.emf.common.util.EList)9 XSDSchema (org.eclipse.xsd.XSDSchema)8 Iterator (java.util.Iterator)7