Search in sources :

Example 6 with WSDataModel

use of com.amalto.workbench.webservices.WSDataModel in project tmdm-studio-se by Talend.

the class EditXObjectAction method run.

@Override
public void run() {
    try {
        super.run();
        if (xobject == null || !xobject.isXObject()) {
            return;
        }
        // Access to server and get port
        TMDMService service = Util.getMDMService(new URL(xobject.getEndpointAddress()), xobject.getUsername(), xobject.getPassword());
        switch(xobject.getType()) {
            case TreeObject.DATA_MODEL:
                WSDataModel wsDataModel = service.getDataModel(new WSGetDataModel((WSDataModelPK) xobject.getWsKey()));
                xobject.setWsObject(wsDataModel);
                // XSDEditorUtil.openDataModel(xobject, false);
                return;
            case TreeObject.VIEW:
                WSView wsView = service.getView(new WSGetView((WSViewPK) xobject.getWsKey()));
                xobject.setWsObject(wsView);
                break;
            case TreeObject.DATA_CLUSTER:
                WSDataCluster wsDataCluster = service.getDataCluster(new WSGetDataCluster((WSDataClusterPK) xobject.getWsKey()));
                xobject.setWsObject(wsDataCluster);
                break;
            case TreeObject.STORED_PROCEDURE:
                WSStoredProcedure wsStoredProcedure = service.getStoredProcedure(new WSGetStoredProcedure((WSStoredProcedurePK) xobject.getWsKey()));
                xobject.setWsObject(wsStoredProcedure);
                break;
            case TreeObject.ROUTING_RULE:
                WSRoutingRule wsRoutingRule = service.getRoutingRule(new WSGetRoutingRule((WSRoutingRulePK) xobject.getWsKey()));
                xobject.setWsObject(wsRoutingRule);
                break;
            case TreeObject.TRANSFORMER:
                WSTransformerV2 wsTranformer = service.getTransformerV2(new WSGetTransformerV2((WSTransformerV2PK) xobject.getWsKey()));
                xobject.setWsObject(wsTranformer);
                break;
            case TreeObject.MENU:
                WSMenu wsMenu = service.getMenu(new WSGetMenu((WSMenuPK) xobject.getWsKey()));
                xobject.setWsObject(wsMenu);
                break;
            case TreeObject.SERVICE_CONFIGURATION:
                break;
            case TreeObject.JOB_REGISTRY:
                // System.out.println("JOB_REGISTRY "+ xobject.getDisplayName());
                break;
            case TreeObject.JOB:
                // System.out.println("JOB "+ xobject.getDisplayName()+" "+xobject.getWsKey());
                xobject.setWsObject(xobject.getDisplayName());
                break;
            case TreeObject.ROLE:
                if (exAdapter != null) {
                    exAdapter.run(service, xobject);
                }
                break;
            case TreeObject.RESOURCES:
            case TreeObject.CUSTOM_TYPE:
            case TreeObject.DATA_MODEL_RESOURCE:
            case TreeObject.DATA_MODEL_TYPES_RESOURCE:
            case TreeObject.CUSTOM_TYPES_RESOURCE:
            case TreeObject.PICTURES_RESOURCE:
                break;
            default:
                MessageDialog.openError(getShell(), Messages._Error, Messages.bind(Messages.EditXObjectAction_ErrorMsg1, IConstants.TALEND, xobject.getType()));
                return;
        }
        if (page == null) {
            this.page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
        }
        this.page.openEditor(new XObjectEditorInput(xobject, xobject.getDisplayName()), // $NON-NLS-1$
        "com.amalto.workbench.editors.XObjectEditor");
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        if (!Util.handleConnectionException(getShell(), e, Messages.EditXObjectAction_ErrorMsg2)) {
            MessageDialog.openError(getShell(), Messages._Error, Messages.bind(Messages.EditXObjectAction_ErrorMsg2, e.getLocalizedMessage()));
        }
    }
}
Also used : WSGetStoredProcedure(com.amalto.workbench.webservices.WSGetStoredProcedure) WSMenuPK(com.amalto.workbench.webservices.WSMenuPK) WSGetTransformerV2(com.amalto.workbench.webservices.WSGetTransformerV2) WSStoredProcedurePK(com.amalto.workbench.webservices.WSStoredProcedurePK) XObjectEditorInput(com.amalto.workbench.providers.XObjectEditorInput) URL(java.net.URL) WSView(com.amalto.workbench.webservices.WSView) WSGetDataModel(com.amalto.workbench.webservices.WSGetDataModel) WSDataCluster(com.amalto.workbench.webservices.WSDataCluster) WSDataClusterPK(com.amalto.workbench.webservices.WSDataClusterPK) TMDMService(com.amalto.workbench.webservices.TMDMService) WSRoutingRule(com.amalto.workbench.webservices.WSRoutingRule) WSStoredProcedure(com.amalto.workbench.webservices.WSStoredProcedure) WSGetView(com.amalto.workbench.webservices.WSGetView) WSGetMenu(com.amalto.workbench.webservices.WSGetMenu) WSRoutingRulePK(com.amalto.workbench.webservices.WSRoutingRulePK) WSGetRoutingRule(com.amalto.workbench.webservices.WSGetRoutingRule) WSMenu(com.amalto.workbench.webservices.WSMenu) WSDataModel(com.amalto.workbench.webservices.WSDataModel) WSGetDataCluster(com.amalto.workbench.webservices.WSGetDataCluster) WSTransformerV2(com.amalto.workbench.webservices.WSTransformerV2) WSTransformerV2PK(com.amalto.workbench.webservices.WSTransformerV2PK) WSDataModelPK(com.amalto.workbench.webservices.WSDataModelPK) WSViewPK(com.amalto.workbench.webservices.WSViewPK)

Example 7 with WSDataModel

use of com.amalto.workbench.webservices.WSDataModel in project tmdm-studio-se by Talend.

the class DataModelMainPage method createCharacteristicsContent.

protected void createCharacteristicsContent(FormToolkit toolkit, Composite mainComposite) {
    try {
        GridLayout layout = new GridLayout();
        layout.verticalSpacing = 0;
        mainComposite.getParent().setLayout(layout);
        GridData gdMainComposite = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
        gdMainComposite.widthHint = 1;
        gdMainComposite.heightHint = 1;
        mainComposite.setLayoutData(gdMainComposite);
        WSDataModel wsObject = (WSDataModel) (xobject.getWsObject());
        // description
        Composite descriptionComposite = toolkit.createComposite(mainComposite, SWT.NONE);
        descriptionComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));
        descriptionComposite.setLayout(new GridLayout());
        desAntionComposite = new // $NON-NLS-1$
        DescAnnotationComposite(// $NON-NLS-1$
        Messages.DescriptionText, // $NON-NLS-1$
        " ...", // $NON-NLS-1$
        toolkit, // $NON-NLS-1$
        descriptionComposite, null, false);
        // $NON-NLS-1$
        desAntionComposite.setText(wsObject.getDescription() == null ? "" : wsObject.getDescription());
        desAntionComposite.getTextWidget().addModifyListener(new ModifyListener() {

            public void modifyText(ModifyEvent e) {
                markDirty();
            }
        });
        desAntionComposite.setEnable(!isReadOnly());
        Composite btnCmp = toolkit.createComposite(mainComposite);
        btnCmp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));
        GridLayout gLayout = new GridLayout();
        gLayout.numColumns = 4;
        gLayout.horizontalSpacing = 20;
        gLayout.verticalSpacing = 0;
        btnCmp.setLayout(gLayout);
        xsdSchema = getXSDSchema(wsObject.getXsdSchema());
        createSash(mainComposite);
        hookSelectionProvider();
        if (!isReadOnly()) {
            createCompDropTarget();
            hookContextMenu();
            hookDoubleClickAction();
            hookTypesContextMenu();
        }
        // init undo history
        initializeOperationHistory();
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) WSDataModel(com.amalto.workbench.webservices.WSDataModel) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Composite(org.eclipse.swt.widgets.Composite) DescAnnotationComposite(com.amalto.workbench.widgets.DescAnnotationComposite) ModifyListener(org.eclipse.swt.events.ModifyListener) GridData(org.eclipse.swt.layout.GridData) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) SAXParseException(org.xml.sax.SAXParseException)

Example 8 with WSDataModel

use of com.amalto.workbench.webservices.WSDataModel in project tmdm-studio-se by Talend.

the class DataModelMainPage method createToolBar.

private void createToolBar(Composite parent) {
    Composite toolBarComp = new Composite(parent, SWT.BORDER);
    GridData gd = new GridData(SWT.FILL, SWT.TOP, true, false, 2, 1);
    gd.heightHint = 25;
    toolBarComp.setLayoutData(gd);
    final GridLayout glToolBarBackground = new GridLayout();
    glToolBarBackground.verticalSpacing = 0;
    glToolBarBackground.marginWidth = 0;
    glToolBarBackground.marginHeight = 0;
    glToolBarBackground.horizontalSpacing = 0;
    toolBarComp.setLayout(glToolBarBackground);
    ToolBar resultToolBar = new ToolBar(toolBarComp, SWT.FLAT | SWT.HORIZONTAL);
    gd = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
    resultToolBar.setLayoutData(gd);
    ToolItem importToolItem = new ToolItem(resultToolBar, SWT.PUSH);
    importToolItem.setImage(ImageCache.getCreatedImage(EImage.IMPORT.getPath()));
    importToolItem.setToolTipText(Messages.ImportText);
    importToolItem.setEnabled(!isReadOnly());
    ToolItem exportToolItem = new ToolItem(resultToolBar, SWT.PUSH);
    exportToolItem.setImage(ImageCache.getCreatedImage(EImage.EXPORT.getPath()));
    exportToolItem.setToolTipText(Messages.ExportText);
    exportToolItem.setEnabled(!isReadOnly());
    ToolItem importSchemalItem = new ToolItem(resultToolBar, SWT.PUSH);
    importSchemalItem.setImage(ImageCache.getCreatedImage(EImage.CHECKIN_ACTION.getPath()));
    importSchemalItem.setToolTipText(Messages.ImportIncludeSchema);
    importSchemalItem.setEnabled(!isReadOnly());
    importToolItem.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            FileDialog fd = new FileDialog(getSite().getShell(), SWT.OPEN);
            // $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
            fd.setFilterExtensions(new String[] { "*.xsd", "*.dtd", "*.xml" });
            // set the default path to the workspace.
            fd.setFilterPath(Platform.getInstanceLocation().getURL().getPath().substring(1));
            fd.setText(Messages.SelectXMLDefinition);
            String filename = fd.open();
            if (filename == null) {
                return;
            }
            xsdSchema = null;
            inferXsdFromXml(filename);
        }

        private void inferXsdFromXml(String xmlFile) {
            int infer = 0;
            // $NON-NLS-1$
            String xsd = "";
            try {
                // $NON-NLS-1$
                String inputType = xmlFile.substring(xmlFile.lastIndexOf("."));
                if (inputType.equals(".xsd")) {
                    // $NON-NLS-1$
                    xsd = Util.getXML(xmlFile);
                    xsdSchema = Util.createXsdSchema(xsd, xobject);
                    xsd = Util.nodeToString(xsdSchema.getDocument());
                } else {
                    XSDDriver d = new XSDDriver();
                    // $NON-NLS-1$
                    infer = d.doMain(new String[] { xmlFile, "out.xsd" });
                    if (infer == 0) {
                        xsd = d.outputXSD();
                    }
                }
            } catch (Exception e) {
                log.error(e.getMessage(), e);
                infer = 2;
            } finally {
                if (infer == 0 && !xsd.equals("")) {
                    // $NON-NLS-1$
                    WSDataModel wsObj = (WSDataModel) (xobject.getWsObject());
                    wsObj.setXsdSchema(xsd);
                    validateSchema(xsd);
                    refreshData();
                    markDirtyWithoutCommit();
                } else if (infer != 0) {
                    MessageDialog.openError(getSite().getShell(), Messages._Error, Messages.XsdSchemaInferred);
                }
            }
        }

        void validateSchema(String xsd) {
            try {
                boolean elem = false;
                XSDSchema schema = getXSDSchema(xsd);
                NodeList nodeList = schema.getDocument().getDocumentElement().getChildNodes();
                for (int idx = 0; idx < nodeList.getLength(); idx++) {
                    Node node = nodeList.item(idx);
                    if (node instanceof Element && node.getLocalName().indexOf("element") >= 0) {
                        // $NON-NLS-1$
                        elem = true;
                        break;
                    }
                }
                if (!elem) {
                    MessageDialog.openWarning(getSite().getShell(), Messages.Warning, Messages.NoElementNode);
                }
            } catch (Exception e) {
                log.error(e.getMessage(), e);
            }
        }
    });
    exportToolItem.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            FileDialog fd = new FileDialog(getSite().getShell(), SWT.SAVE);
            // $NON-NLS-1$
            fd.setFilterExtensions(new String[] { "*.xsd" });
            fd.setFilterPath(Platform.getInstanceLocation().getURL().getPath().substring(1));
            fd.setText(Messages.SaveDataModuleXSDSchema);
            String filename = fd.open();
            if (filename == null) {
                return;
            }
            inferXsdFromDataModule(filename);
        }

        private void inferXsdFromDataModule(String xmlFile) {
            WSDataModel wsObject = (WSDataModel) (xobject.getWsObject());
            XSDDriver d = new XSDDriver();
            if (d.outputXSD_UTF_8(wsObject.getXsdSchema(), xmlFile) != null) {
                MessageDialog.openInformation(getSite().getShell(), Messages.ExportXSD, Messages.OperationExportingXsd);
            } else {
                MessageDialog.openError(getSite().getShell(), Messages._Error, Messages.FailedExportXSD);
            }
        }
    });
    importSchemalItem.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            popupImportDialog();
        }
    });
}
Also used : Composite(org.eclipse.swt.widgets.Composite) DescAnnotationComposite(com.amalto.workbench.widgets.DescAnnotationComposite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) SAXParseException(org.xml.sax.SAXParseException) GridLayout(org.eclipse.swt.layout.GridLayout) WSDataModel(com.amalto.workbench.webservices.WSDataModel) GridData(org.eclipse.swt.layout.GridData) ToolBar(org.eclipse.swt.widgets.ToolBar) SelectionEvent(org.eclipse.swt.events.SelectionEvent) FileDialog(org.eclipse.swt.widgets.FileDialog) ToolItem(org.eclipse.swt.widgets.ToolItem) XSDSchema(org.eclipse.xsd.XSDSchema)

Example 9 with WSDataModel

use of com.amalto.workbench.webservices.WSDataModel 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 10 with WSDataModel

use of com.amalto.workbench.webservices.WSDataModel 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

WSDataModel (com.amalto.workbench.webservices.WSDataModel)23 WSDataModelPK (com.amalto.workbench.webservices.WSDataModelPK)10 WSGetDataModel (com.amalto.workbench.webservices.WSGetDataModel)10 SAXParseException (org.xml.sax.SAXParseException)8 TMDMService (com.amalto.workbench.webservices.TMDMService)6 PartInitException (org.eclipse.ui.PartInitException)6 TreeObject (com.amalto.workbench.models.TreeObject)5 XSDSchema (org.eclipse.xsd.XSDSchema)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 IFile (org.eclipse.core.resources.IFile)4 CoreException (org.eclipse.core.runtime.CoreException)4 TreeParent (com.amalto.workbench.models.TreeParent)3 WSDataCluster (com.amalto.workbench.webservices.WSDataCluster)3 WSDataClusterPK (com.amalto.workbench.webservices.WSDataClusterPK)3 WSGetDataCluster (com.amalto.workbench.webservices.WSGetDataCluster)3 WSGetMenu (com.amalto.workbench.webservices.WSGetMenu)3 WSGetRoutingRule (com.amalto.workbench.webservices.WSGetRoutingRule)3 WSGetStoredProcedure (com.amalto.workbench.webservices.WSGetStoredProcedure)3 WSGetTransformerV2 (com.amalto.workbench.webservices.WSGetTransformerV2)3 WSGetView (com.amalto.workbench.webservices.WSGetView)3