Search in sources :

Example 1 with RepositoryXmlSelectionDialog

use of org.talend.designer.xmlmap.ui.dialog.RepositoryXmlSelectionDialog in project tdi-studio-se by Talend.

the class ImportTreeFromRepository method run.

@Override
public void run() {
    targetAbsolutePath = null;
    loopNode = null;
    xpathAndOrder.clear();
    RepositoryXmlSelectionDialog reviewDialog = new RepositoryXmlSelectionDialog(shell, new String[] { "XML", "MDM" });
    if (reviewDialog.open() == Window.OK) {
        TreeNode treeNodeRoot = XmlMapUtil.getTreeNodeRoot(schemaNode);
        XmlMapUtil.detachNodeConnections(treeNodeRoot, mapperManager.getExternalData(), true);
        RepositoryNode repositoryNode = reviewDialog.getResult();
        Item item = repositoryNode.getObject().getProperty().getItem();
        String detailedMessage = "";
        try {
            if (item instanceof XmlFileConnectionItem) {
                XmlFileConnectionItem xmlitem = (XmlFileConnectionItem) item;
                XmlFileConnection connection = (XmlFileConnection) xmlitem.getConnection();
                prepareEmfTreeFromXml(connection);
            } else if (item instanceof MDMConnectionItem) {
                String selectedSchema = (String) repositoryNode.getProperties(EProperties.LABEL);
                MDMConnection connection = (MDMConnection) ((MDMConnectionItem) item).getConnection();
                prepareEmfTreeFromMdm(connection, selectedSchema);
            }
        } catch (Exception e) {
            ExceptionHandler.process(e);
            StringBuffer sb = new StringBuffer();
            sb.append(e.toString());
            sb.append("\n");
            if (e.getStackTrace() != null) {
                for (StackTraceElement trace : e.getStackTrace()) {
                    sb.append(trace.toString());
                    sb.append("\n");
                }
            }
            detailedMessage = sb.toString();
        }
        boolean childrenEmpty = false;
        if (schemaNode.getChildren().isEmpty()) {
            childrenEmpty = true;
            TreeNode rootNode = createModel();
            rootNode.setName("root");
            rootNode.setNodeType(NodeType.ELEMENT);
            rootNode.setType(XmlMapUtil.DEFAULT_DATA_TYPE);
            rootNode.setXpath(XmlMapUtil.getXPath(schemaNode.getXpath(), "root", NodeType.ELEMENT));
            schemaNode.getChildren().add(rootNode);
            if (loopNode == null) {
                schemaNode.getChildren().get(0).setLoop(true);
                schemaNode.getChildren().get(0).setMain(true);
            }
        }
        if (childrenEmpty || (detailedMessage != null && !"".equals(detailedMessage))) {
            showError(detailedMessage);
        }
        AbstractInOutTree tree = null;
        if (schemaNode.eContainer() instanceof InputXmlTree) {
            XmlMapConnectionBuilder connectionBuilder = new XmlMapConnectionBuilder();
            connectionBuilder.setCheckRootNodePrefix(true);
            connectionBuilder.rebuildLinks(schemaNode, mapperManager.getExternalData());
            mapperManager.refreshTreeSchemaEditor((InputXmlTree) schemaNode.eContainer());
            // mapperManager.inputTreeSchemaBeanListModified();
            tree = (InputXmlTree) schemaNode.eContainer();
        } else if (schemaNode.eContainer() instanceof OutputXmlTree) {
            // mapperManager.outputTreeSchemaBeanListModified();
            mapperManager.refreshTreeSchemaEditor((OutputXmlTree) schemaNode.eContainer());
            tree = (OutputXmlTree) schemaNode.eContainer();
        }
        if (tree != null) {
            mapperManager.getProblemsAnalyser().checkProblems(tree);
            mapperManager.getMapperUI().updateStatusBar();
        }
    }
}
Also used : RepositoryXmlSelectionDialog(org.talend.designer.xmlmap.ui.dialog.RepositoryXmlSelectionDialog) XmlFileConnection(org.talend.core.model.metadata.builder.connection.XmlFileConnection) AbstractInOutTree(org.talend.designer.xmlmap.model.emf.xmlmap.AbstractInOutTree) MDMConnectionItem(org.talend.core.model.properties.MDMConnectionItem) ProjectRepositoryNode(org.talend.core.repository.model.ProjectRepositoryNode) RepositoryNode(org.talend.repository.model.RepositoryNode) MDMConnection(org.talend.core.model.metadata.builder.connection.MDMConnection) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) PersistenceException(org.talend.commons.exception.PersistenceException) InputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.InputXmlTree) Item(org.talend.core.model.properties.Item) XmlFileConnectionItem(org.talend.core.model.properties.XmlFileConnectionItem) MDMConnectionItem(org.talend.core.model.properties.MDMConnectionItem) XmlMapConnectionBuilder(org.talend.designer.xmlmap.util.XmlMapConnectionBuilder) FOXTreeNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) XmlFileConnectionItem(org.talend.core.model.properties.XmlFileConnectionItem) OutputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree)

Aggregations

FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 PersistenceException (org.talend.commons.exception.PersistenceException)1 MDMConnection (org.talend.core.model.metadata.builder.connection.MDMConnection)1 XmlFileConnection (org.talend.core.model.metadata.builder.connection.XmlFileConnection)1 Item (org.talend.core.model.properties.Item)1 MDMConnectionItem (org.talend.core.model.properties.MDMConnectionItem)1 XmlFileConnectionItem (org.talend.core.model.properties.XmlFileConnectionItem)1 ProjectRepositoryNode (org.talend.core.repository.model.ProjectRepositoryNode)1 AbstractInOutTree (org.talend.designer.xmlmap.model.emf.xmlmap.AbstractInOutTree)1 InputXmlTree (org.talend.designer.xmlmap.model.emf.xmlmap.InputXmlTree)1 OutputXmlTree (org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree)1 TreeNode (org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode)1 RepositoryXmlSelectionDialog (org.talend.designer.xmlmap.ui.dialog.RepositoryXmlSelectionDialog)1 XmlMapConnectionBuilder (org.talend.designer.xmlmap.util.XmlMapConnectionBuilder)1 FOXTreeNode (org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode)1 RepositoryNode (org.talend.repository.model.RepositoryNode)1