Search in sources :

Example 6 with DataModelMainPage

use of com.amalto.workbench.editors.DataModelMainPage 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 7 with DataModelMainPage

use of com.amalto.workbench.editors.DataModelMainPage in project tmdm-studio-se by Talend.

the class ElementWrapperCommitHandler method updateReference.

private void updateReference(String originalName) {
    DataModelMainPage page = getPage();
    String modifiedXpath = getModifiedXpath(page);
    if (modifiedXpath != null && !modifiedXpath.isEmpty()) {
        // $NON-NLS-1$
        int lastIndex = modifiedXpath.lastIndexOf("/");
        String originalXpath = originalName;
        originalXpath = modifiedXpath.substring(0, lastIndex + 1) + originalXpath;
        IStructuredContentProvider provider = (IStructuredContentProvider) page.getTreeViewer().getContentProvider();
        Object[] allForeignKeyRelatedInfos = Util.getAllForeignKeyRelatedInfos(page.getSite(), new ArrayList<Object>(), provider, new HashSet<Object>());
        Util.updateForeignKeyRelatedInfo(originalXpath, modifiedXpath, allForeignKeyRelatedInfos);
    }
}
Also used : DataModelMainPage(com.amalto.workbench.editors.DataModelMainPage) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider)

Example 8 with DataModelMainPage

use of com.amalto.workbench.editors.DataModelMainPage in project tmdm-studio-se by Talend.

the class ElementWrapperCommitHandler method getPage.

private DataModelMainPage getPage() {
    IEditorPart activeEditor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
    if (activeEditor instanceof XSDEditor) {
        XSDEditor xsdEditor = (XSDEditor) activeEditor;
        DataModelMainPage page = xsdEditor.getdMainPage();
        return page;
    }
    return null;
}
Also used : XSDEditor(com.amalto.workbench.editors.xsdeditor.XSDEditor) DataModelMainPage(com.amalto.workbench.editors.DataModelMainPage) IEditorPart(org.eclipse.ui.IEditorPart)

Example 9 with DataModelMainPage

use of com.amalto.workbench.editors.DataModelMainPage in project tmdm-studio-se by Talend.

the class XSDEditor method resetTreeSelection.

private void resetTreeSelection(int newPageIndex) {
    DataModelMainPage dataModelEditorPage = getDataModelEditorPage();
    if (dataModelEditorPage != null) {
        TreeViewer treeViewer = dataModelEditorPage.getTreeViewer();
        if (newPageIndex == MODEL_PAGE_INDEX) {
            treeViewer.setSelection(null);
        } else if (newPageIndex == SOURCE_PAGE_INDEX) {
            IStructuredSelection selection = (IStructuredSelection) treeViewer.getSelection();
            if (!selection.isEmpty()) {
                Object firstElement = selection.getFirstElement();
                if ((firstElement instanceof XSDIdentityConstraintDefinition)) {
                    XSDIdentityConstraintDefinition cdf = (XSDIdentityConstraintDefinition) firstElement;
                    XSDConcreteComponent container = cdf.getContainer();
                    treeViewer.setSelection(new StructuredSelection(container));
                } else if ((firstElement instanceof XSDXPathDefinition)) {
                    XSDXPathDefinition pathdef = (XSDXPathDefinition) firstElement;
                    XSDConcreteComponent container = pathdef.getContainer().getContainer();
                    treeViewer.setSelection(new StructuredSelection(container));
                } else if (firstElement instanceof XSDAnnotation) {
                    XSDAnnotation annotation = (XSDAnnotation) firstElement;
                    XSDConcreteComponent container = annotation.getContainer();
                    treeViewer.setSelection(new StructuredSelection(container));
                }
            }
        }
    }
}
Also used : XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) TreeViewer(org.eclipse.jface.viewers.TreeViewer) DataModelMainPage(com.amalto.workbench.editors.DataModelMainPage) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) XSDIdentityConstraintDefinition(org.eclipse.xsd.XSDIdentityConstraintDefinition) EObject(org.eclipse.emf.ecore.EObject) TreeObject(com.amalto.workbench.models.TreeObject) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) XSDXPathDefinition(org.eclipse.xsd.XSDXPathDefinition) XSDAnnotation(org.eclipse.xsd.XSDAnnotation)

Example 10 with DataModelMainPage

use of com.amalto.workbench.editors.DataModelMainPage in project tmdm-studio-se by Talend.

the class XMLEditor method doSave.

@Override
public void doSave(IProgressMonitor progressMonitor) {
    // WSDataModel wsObject = (WSDataModel) (xobject.getWSObject());
    IDocument doc = ((XMLEditorInput) this.getEditorInput()).getDocument();
    String schema = doc.get();
    DataModelMainPage page = (DataModelMainPage) editor.formPages.get(0);
    page.setXsdSchema(null);
    int ret = page.save(schema);
    if (ret != 0) {
        return;
    }
    setModified(true);
    super.doSave(progressMonitor);
}
Also used : DataModelMainPage(com.amalto.workbench.editors.DataModelMainPage) IDocument(org.eclipse.jface.text.IDocument)

Aggregations

DataModelMainPage (com.amalto.workbench.editors.DataModelMainPage)11 IEditorPart (org.eclipse.ui.IEditorPart)5 XSDEditor (com.amalto.workbench.editors.xsdeditor.XSDEditor)4 IStructuredContentProvider (org.eclipse.jface.viewers.IStructuredContentProvider)3 WSDataModel (com.amalto.workbench.webservices.WSDataModel)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)2 PartInitException (org.eclipse.ui.PartInitException)2 XSDAnnotation (org.eclipse.xsd.XSDAnnotation)2 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)2 XSDIdentityConstraintDefinition (org.eclipse.xsd.XSDIdentityConstraintDefinition)2 XSDSchema (org.eclipse.xsd.XSDSchema)2 XSDXPathDefinition (org.eclipse.xsd.XSDXPathDefinition)2 Element (org.w3c.dom.Element)2 SAXParseException (org.xml.sax.SAXParseException)2 CommitException (com.amalto.workbench.detailtabs.exception.CommitException)1 CommitValidationException (com.amalto.workbench.detailtabs.exception.CommitValidationException)1 TreeObject (com.amalto.workbench.models.TreeObject)1 XSDAnnotationsStructure (com.amalto.workbench.utils.XSDAnnotationsStructure)1