Search in sources :

Example 11 with XSDAnnotationsStructure

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

the class ElementWrapperCommitHandler method doSubmit.

@Override
protected boolean doSubmit() throws CommitException {
    try {
        String originalName = getCommitedObj().getSourceName();
        XSDElementDeclaration decl = getCommitedObj().getSourceXSDContent();
        XSDElementDeclaration ref = null;
        if (decl.isElementDeclarationReference()) {
            ref = decl.getResolvedElementDeclaration();
        }
        XSDAnnotationsStructure struct = new XSDAnnotationsStructure(getCommitedObj().getSourceElement());
        // remove first
        // struct.setAutoExpand(null);
        struct.setAutoExpand(String.valueOf(getCommitedObj().isAutoExpand()));
        // update validation rule
        Set<String> paths = new HashSet<String>();
        DataModelMainPage page = getPage();
        Util.collectElementPaths((IStructuredContentProvider) page.getElementsViewer().getContentProvider(), page.getSite(), getCommitedObj().getSourceElement(), paths, null);
        XSDElementDeclaration newRef = Util.findReference(getCommitedObj().getNewReference(), getCommitedObj().getSchema());
        XSDIdentityConstraintDefinition identify = null;
        XSDXPathDefinition keyPath = null;
        List<Object> keyInfo = Util.getKeyInfo(getCommitedObj().getSourceXSDContent());
        if (keyInfo != null && keyInfo.size() > 0) {
            identify = (XSDIdentityConstraintDefinition) keyInfo.get(0);
            keyPath = (XSDXPathDefinition) keyInfo.get(1);
            identify.getFields().remove(keyPath);
        }
        getCommitedObj().getSourceXSDContent().setName(// $NON-NLS-1$
        "".equals(getCommitedObj().getNewName()) ? null : getCommitedObj().getNewName());
        if (keyPath != null) {
            XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory();
            XSDXPathDefinition field = factory.createXSDXPathDefinition();
            field.setVariety(keyPath.getVariety());
            field.setValue(getCommitedObj().getNewName());
            identify.getFields().add(field);
        }
        if (newRef != null) {
            decl.setResolvedElementDeclaration(newRef);
            decl.setTypeDefinition(null);
            Element elem = decl.getElement();
            if (elem.getAttributes().getNamedItem("type") != null) {
                // $NON-NLS-1$
                elem.getAttributes().removeNamedItem("type");
            }
            decl.updateElement();
        } else if (ref != null) {
            XSDElementDeclaration sourceXSDContent = getCommitedObj().getSourceXSDContent();
            sourceXSDContent.setTypeDefinition(getCommitedObj().getSchema().getSchemaForSchema().resolveSimpleTypeDefinition(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001, // $NON-NLS-1$
            "string"));
            sourceXSDContent.setResolvedElementDeclaration(sourceXSDContent);
        // XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory();
        // XSDElementDeclaration newD = (XSDElementDeclaration) factory.createXSDElementDeclaration();
        // newD.setName(getCommitedObj().getNewName());
        // newD.updateElement();
        // XSDSimpleTypeDefinition stringType = getCommitedObj().getSchema().getSchemaForSchema()
        // .resolveSimpleTypeDefinition(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001, "string");
        // 
        // newD.setTypeDefinition(stringType);
        // if (getCommitedObj().getSourceElement().getContainer() instanceof XSDModelGroup) {
        // XSDModelGroup group = ((XSDModelGroup) getCommitedObj().getSourceElement().getContainer());
        // ((XSDModelGroup) getCommitedObj().getSourceElement().getContainer()).getContents().remove(
        // getCommitedObj().getSourceElement());
        // getCommitedObj().setSourceElement(factory.createXSDParticle());
        // getCommitedObj().getSourceElement().setContent(newD);
        // group.getContents().add(getCommitedObj().getSourceElement());
        // }
        }
        int newMaxOcur = getCommitedObj().getNewMaxOcur();
        if (Util.changeElementTypeToSequence(decl, newMaxOcur) == Status.CANCEL_STATUS) {
            return false;
        }
        int newMinOcur = getCommitedObj().getNewMinOcur();
        getCommitedObj().getSourceElement().setMinOccurs(newMinOcur);
        if (newMaxOcur == -1 || (newMaxOcur == 0 & newMinOcur == 0)) {
            if (!"unbounded".equals(getCommitedObj().getSourceElement().getElement().getAttribute("maxOccurs"))) {
                // $NON-NLS-1$//$NON-NLS-2$
                getCommitedObj().getSourceElement().getElement().setAttribute("maxOccurs", "unbounded");
            }
        } else {
            getCommitedObj().getSourceElement().setMaxOccurs(newMaxOcur);
        }
        getCommitedObj().getSourceElement().updateElement();
        updateReference(originalName);
        if (elementExAdapter != null) {
            elementExAdapter.renameElement(getCommitedObj().getSchema(), paths, getCommitedObj().getNewName());
        }
        if (mapinfoExAdapter != null) {
            mapinfoExAdapter.renameElementMapinfo(paths, decl.getName());
        }
    } catch (Exception e) {
        throw new CommitException(e.getMessage(), e);
    }
    return true;
}
Also used : CommitException(com.amalto.workbench.detailtabs.exception.CommitException) XSDFactory(org.eclipse.xsd.XSDFactory) XSDAnnotationsStructure(com.amalto.workbench.utils.XSDAnnotationsStructure) Element(org.w3c.dom.Element) DataModelMainPage(com.amalto.workbench.editors.DataModelMainPage) CommitValidationException(com.amalto.workbench.detailtabs.exception.CommitValidationException) CommitException(com.amalto.workbench.detailtabs.exception.CommitException) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDIdentityConstraintDefinition(org.eclipse.xsd.XSDIdentityConstraintDefinition) XSDXPathDefinition(org.eclipse.xsd.XSDXPathDefinition) HashSet(java.util.HashSet)

Example 12 with XSDAnnotationsStructure

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

the class ElementFKInfosSection method initUIContents.

@Override
protected void initUIContents(XSDComponent editedObj) {
    super.initUIContents(editedObj);
    fkInfos.clear();
    XSDAnnotationsStructure annoStruct = new XSDAnnotationsStructure(curXSDComponent);
    for (String eachFKInfo : annoStruct.getForeignKeyInfos().values()) {
        fkInfos.add(eachFKInfo);
    }
    // 
    formatFKinfo = annoStruct.getFormatForeignKeyInfo();
    holder.setDefaultDataModel(getDataModelName());
    holder.setDefaultEntity(getEntityName());
}
Also used : XSDAnnotationsStructure(com.amalto.workbench.utils.XSDAnnotationsStructure)

Example 13 with XSDAnnotationsStructure

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

the class EntityPKInfosSection method initUIContents.

@Override
protected void initUIContents(XSDComponent editedObj) {
    super.initUIContents(editedObj);
    list.clear();
    holder.setDefaultDataModel(getDataModelName());
    holder.setDefaultEntity(getEntityName());
    XSDAnnotationsStructure annoStruct = new XSDAnnotationsStructure(curXSDComponent);
    for (String eachLookUpFields : annoStruct.getPrimaryKeyInfos().values()) list.add(eachLookUpFields);
}
Also used : XSDAnnotationsStructure(com.amalto.workbench.utils.XSDAnnotationsStructure)

Example 14 with XSDAnnotationsStructure

use of com.amalto.workbench.utils.XSDAnnotationsStructure 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 XSDAnnotationsStructure

use of com.amalto.workbench.utils.XSDAnnotationsStructure 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

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