Search in sources :

Example 1 with DataModelMainPage

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

the class AnnotationOrderedListsDialog method getConceptElements.

private List<String> getConceptElements() {
    DataModelMainPage page = parentPage;
    IStructuredSelection selection = (IStructuredSelection) page.getTreeViewer().getSelection();
    List<String> childNames = new ArrayList<String>();
    XSDElementDeclaration decl = null;
    if (selection.getFirstElement() instanceof XSDElementDeclaration) {
        decl = (XSDElementDeclaration) selection.getFirstElement();
    // childNames = Util.getChildElementNames(decl.getElement());
    } else if (selection.getFirstElement() instanceof Element) {
        TreePath tPath = ((TreeSelection) selection).getPaths()[0];
        XSDComponent xSDCom = null;
        for (int i = 0; i < tPath.getSegmentCount(); i++) {
            if (tPath.getSegment(i) instanceof XSDAnnotation) {
                xSDCom = (XSDAnnotation) (tPath.getSegment(i));
                break;
            }
        }
        decl = (XSDElementDeclaration) xSDCom.getContainer();
    }
    try {
        childNames = Util.getChildElementNames(decl.getName(), decl);
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }
    return childNames;
}
Also used : TreePath(org.eclipse.jface.viewers.TreePath) TreeSelection(org.eclipse.jface.viewers.TreeSelection) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) Element(org.w3c.dom.Element) DataModelMainPage(com.amalto.workbench.editors.DataModelMainPage) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) XSDAnnotation(org.eclipse.xsd.XSDAnnotation) XSDComponent(org.eclipse.xsd.XSDComponent)

Example 2 with DataModelMainPage

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

the class ComplexTypeWrapper method changeTypeName.

public boolean changeTypeName() {
    if (curXSDComplexType.getName().equals(newTypeName))
        return false;
    curXSDComplexType.setName(newTypeName);
    curXSDComplexType.updateElement();
    IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    IEditorPart activeEditor = activePage.getActiveEditor();
    if (activeEditor instanceof XSDEditor) {
        XSDEditor editor = (XSDEditor) activeEditor;
        DataModelMainPage page = editor.getdMainPage();
        IStructuredContentProvider provider = (IStructuredContentProvider) page.getSchemaContentProvider();
        Util.updateReferenceToXSDTypeDefinition(page.getSite(), curXSDComplexType, provider);
    }
    return true;
}
Also used : XSDEditor(com.amalto.workbench.editors.xsdeditor.XSDEditor) DataModelMainPage(com.amalto.workbench.editors.DataModelMainPage) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorPart(org.eclipse.ui.IEditorPart)

Example 3 with DataModelMainPage

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

the class SimpleTypeWrapper method changeTypeName.

public boolean changeTypeName() {
    if (getNewTypeName().trim().equals(getOldTypeName()))
        return false;
    xsdSimpleType.setName(getNewTypeName().trim());
    xsdSimpleType.updateElement();
    IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    IEditorPart activeEditor = activePage.getActiveEditor();
    if (activeEditor instanceof XSDEditor) {
        XSDEditor editor = (XSDEditor) activeEditor;
        DataModelMainPage page = editor.getdMainPage();
        IStructuredContentProvider provider = (IStructuredContentProvider) page.getSchemaContentProvider();
        Util.updateReferenceToXSDTypeDefinition(page.getSite(), xsdSimpleType, provider);
    }
    return true;
}
Also used : XSDEditor(com.amalto.workbench.editors.xsdeditor.XSDEditor) DataModelMainPage(com.amalto.workbench.editors.DataModelMainPage) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorPart(org.eclipse.ui.IEditorPart)

Example 4 with DataModelMainPage

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

the class XSDEditor method doSave.

@Override
public void doSave(IProgressMonitor monitor) {
    XSDDirectivesManager.removeUnusedXSDImports(getXSDSchema());
    structuredTextEditor.doSave(monitor);
    InputStream stream = null;
    try {
        EditorPart part = (EditorPart) getSelectedPage();
        String xsd = null;
        if (null != part) {
            if (part instanceof StructuredTextEditor) {
                xsd = ((StructuredTextEditor) part).getTextViewer().getDocument().get();
            } else {
                // main page or er editor
                DataModelMainPage dmp = getdMainPage();
                xsd = dmp.getXSDSchemaString();
            }
        }
        if (null != xsd) {
            DataModelMainPage mainPage = getdMainPage();
            WSDataModel wsDataModel = (WSDataModel) xobject.getWsObject();
            wsDataModel.setXsdSchema(xsd);
            if (mainPage != null) {
                mainPage.save(xsd);
            }
            // $NON-NLS-1$
            fileContents = xsd.getBytes("utf-8");
        }
        getDataModelEditorPage().setDirty(false);
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    } finally {
        IOUtils.closeQuietly(stream);
        if (null != monitor) {
            monitor.done();
        }
    }
}
Also used : WSDataModel(com.amalto.workbench.webservices.WSDataModel) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DataModelMainPage(com.amalto.workbench.editors.DataModelMainPage) MultiPageEditorPart(org.eclipse.ui.part.MultiPageEditorPart) IEditorPart(org.eclipse.ui.IEditorPart) EditorPart(org.eclipse.ui.part.EditorPart) StructuredTextEditor(org.eclipse.wst.sse.ui.StructuredTextEditor) PartInitException(org.eclipse.ui.PartInitException) SAXParseException(org.xml.sax.SAXParseException)

Example 5 with DataModelMainPage

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

the class XSDEditor method doPageChanged.

protected void doPageChanged(int newPageIndex, int lastPageIndex) {
    if (xobject == null) {
        return;
    }
    try {
        if (newPageIndex == MODEL_PAGE_INDEX) {
            DataModelMainPage mainPage = getDataModelEditorPage();
            if (mainPage != null) {
                if (lastPageIndex == SOURCE_PAGE_INDEX) {
                    validateXsdSourceEditor();
                    if (!hasXSDErrors) {
                        String xsd = getSourcePageDocument();
                        XSDSchema schema = Util.createXsdSchema(xsd, xobject);
                        mainPage.setXsdSchema(schema);
                    }
                }
                mainPage.refresh();
                // 
                expandHelper.recoverExpandState(mainPage);
            }
        } else if (newPageIndex == SOURCE_PAGE_INDEX) {
            if (hasXSDErrors) {
                return;
            }
            // save DataModelMainPage's contents to file
            DataModelMainPage mainPage = getDataModelEditorPage();
            expandHelper.recordExpandState(mainPage);
            if (mainPage != null && this.isDirty()) {
                String xsd = mainPage.getXSDSchemaString();
                xsd = Util.formatXsdSource(xsd);
                WSDataModel wsDataModel = (WSDataModel) xobject.getWsObject();
                wsDataModel.setXsdSchema(xsd);
                IFile file = getXSDFile(xobject);
                // $NON-NLS-1$
                file.setCharset("utf-8", null);
                // $NON-NLS-1$
                file.setContents(new ByteArrayInputStream(xsd.getBytes("utf-8")), IFile.FORCE, null);
            }
        }
    } catch (SAXParseException ex) {
    // do nothing
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }
}
Also used : WSDataModel(com.amalto.workbench.webservices.WSDataModel) IFile(org.eclipse.core.resources.IFile) ByteArrayInputStream(java.io.ByteArrayInputStream) SAXParseException(org.xml.sax.SAXParseException) DataModelMainPage(com.amalto.workbench.editors.DataModelMainPage) PartInitException(org.eclipse.ui.PartInitException) SAXParseException(org.xml.sax.SAXParseException) XSDSchema(org.eclipse.xsd.XSDSchema)

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