Search in sources :

Example 41 with OutputTreeNode

use of org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode in project tdi-studio-se by Talend.

the class XMLMapperHelper method hasAggregateColumn.

private static boolean hasAggregateColumn(final INode xmlMapperNode) {
    boolean hasAggregateColumn = false;
    List<? extends IConnection> outConnections = (List<? extends IConnection>) xmlMapperNode.getOutgoingConnections();
    XmlMapData xmlMapData = (XmlMapData) ElementParameterParser.getObjectValueXMLTree(xmlMapperNode);
    if (xmlMapData != null && outConnections != null && outConnections.size() > 0) {
        List<OutputXmlTree> outputTables = xmlMapData.getOutputTrees();
        HashMap<String, IConnection> hNameToConnection = new HashMap<String, IConnection>();
        for (IConnection connection : outConnections) {
            hNameToConnection.put(connection.getName(), connection);
        }
        for (OutputXmlTree outputTable : outputTables) {
            String tableName = outputTable.getName();
            IConnection connection = hNameToConnection.get(tableName);
            if (connection == null) {
                continue;
            }
            List<TreeNode> editableNodes = new ArrayList<TreeNode>();
            for (TreeNode node : outputTable.getNodes()) {
                getEditableNodes(node, editableNodes);
            }
            for (TreeNode node : editableNodes) {
                if (((OutputTreeNode) node).isAggregate()) {
                    hasAggregateColumn = true;
                    break;
                }
            }
        }
    }
    return hasAggregateColumn;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IConnection(org.talend.core.model.process.IConnection) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) EList(org.eclipse.emf.common.util.EList) ArrayList(java.util.ArrayList) List(java.util.List) OutputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree) XmlMapData(org.talend.designer.xmlmap.model.emf.xmlmap.XmlMapData)

Example 42 with OutputTreeNode

use of org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode in project tdi-studio-se by Talend.

the class XmlMapUtil method removeloopInOutputTree.

/**
     * 
     * DOC WCHEN Remove source loops refrenced from input main
     * 
     * @param mapData
     * @param mainInput
     * @param oldLoopsFromInput
     * @param checkProblem
     */
public static void removeloopInOutputTree(XmlMapData mapData, InputXmlTree mainInput, List<TreeNode> oldLoopsFromInput, boolean checkProblem) {
    boolean isMainInputMultiLoop = mainInput == null ? false : mainInput.isMultiLoops();
    EList<OutputXmlTree> outputTrees = mapData.getOutputTrees();
    for (OutputXmlTree outputTree : outputTrees) {
        if (isMainInputMultiLoop) {
            for (TreeNode oldLoop : oldLoopsFromInput) {
                EList<InputLoopNodesTable> inputLoopNodesTables = outputTree.getInputLoopNodesTables();
                for (InputLoopNodesTable inputLoopTable : inputLoopNodesTables) {
                    inputLoopTable.getInputloopnodes().remove(oldLoop);
                }
            }
        } else {
            List<TreeNode> multiLoopsForXmlTree = getMultiLoopsForXmlTree(outputTree);
            for (TreeNode loop : multiLoopsForXmlTree) {
                ((OutputTreeNode) loop).setInputLoopNodesTable(null);
            }
            outputTree.getInputLoopNodesTables().clear();
        }
    }
}
Also used : InputLoopNodesTable(org.talend.designer.xmlmap.model.emf.xmlmap.InputLoopNodesTable) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) OutputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode)

Example 43 with OutputTreeNode

use of org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode in project tdi-studio-se by Talend.

the class ProblemsAnalyser method checkNodeInputLookTableProblem.

private boolean checkNodeInputLookTableProblem(OutputTreeNode outputNode, InputXmlTree mainInputTree, boolean checkChildren) {
    for (Connection connection : outputNode.getIncomingConnections()) {
        if (connection.getSource() instanceof TreeNode) {
            TreeNode source = (TreeNode) connection.getSource();
            InputXmlTree abstractInOutTree = (InputXmlTree) XmlMapUtil.getAbstractInOutTree(source);
            if (abstractInOutTree == mainInputTree) {
                return true;
            } else {
                EList<LookupConnection> lookupIncomingConnections = source.getLookupIncomingConnections();
                for (LookupConnection lookupConn : lookupIncomingConnections) {
                    TreeNode sourceNode = (TreeNode) lookupConn.getSource();
                    AbstractInOutTree abstractInOutTree2 = XmlMapUtil.getAbstractInOutTree(sourceNode);
                    if (abstractInOutTree2 == mainInputTree) {
                        return true;
                    }
                }
            }
            if (checkChildren && !outputNode.getChildren().isEmpty()) {
                for (TreeNode child : outputNode.getChildren()) {
                    if (checkNodeInputLookTableProblem((OutputTreeNode) child, mainInputTree, checkChildren)) {
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
Also used : InputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.InputXmlTree) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) Connection(org.talend.designer.xmlmap.model.emf.xmlmap.Connection) LookupConnection(org.talend.designer.xmlmap.model.emf.xmlmap.LookupConnection) AbstractInOutTree(org.talend.designer.xmlmap.model.emf.xmlmap.AbstractInOutTree) LookupConnection(org.talend.designer.xmlmap.model.emf.xmlmap.LookupConnection)

Example 44 with OutputTreeNode

use of org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode in project tdi-studio-se by Talend.

the class XmlMapUtil method cleanAggregate.

public static boolean cleanAggregate(List<? extends TreeNode> nodes) {
    boolean changed = false;
    for (TreeNode obj : nodes) {
        OutputTreeNode outputNode = (OutputTreeNode) obj;
        if (outputNode.isAggregate()) {
            outputNode.setAggregate(false);
            changed = true;
        }
        if (!outputNode.getChildren().isEmpty()) {
            changed = cleanAggregate(outputNode.getChildren()) || changed;
        }
    }
    return changed;
}
Also used : OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode)

Example 45 with OutputTreeNode

use of org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode in project tdi-studio-se by Talend.

the class MapperManager method selectOutputXmlTree.

public void selectOutputXmlTree(OutputXmlTree outputTree) {
    if (outputTree != selectedOutputTree) {
        selectedOutputTree = outputTree;
        MetadataTableEditorView outputMetaEditorView = mapperUI.getTabFolderEditors().getOutputMetaEditorView();
        List<IMetadataTable> metadataList = getMapperComponent().getMetadataList();
        IMetadataTable table = null;
        for (int i = 0; i < metadataList.size(); i++) {
            if (outputTree.getName() != null && outputTree.getName().equals(metadataList.get(i).getTableName())) {
                table = metadataList.get(i);
                break;
            }
        }
        if (outputTree.isErrorReject()) {
            for (IMetadataColumn column : table.getListColumns()) {
                if (ERROR_REJECT_MESSAGE.equals(column.getLabel()) || ERROR_REJECT_STACK_TRACE.equals(column.getLabel())) {
                    column.setCustom(true);
                }
            }
            CustomTableManager.addCustomManagementToTable(mapperUI.getTabFolderEditors().getOutputMetaEditorView(), true);
        }
        if (table != null) {
            MetadataTableEditor editor = new MetadataTableEditor(table, table.getTableName());
            outputMetaEditorView.setMetadataTableEditor(editor);
            editor.setModifiedBeanListenable(outputMetaEditorView.getTableViewerCreator());
            IModifiedBeanListener<IMetadataColumn> columnListener = new IModifiedBeanListener<IMetadataColumn>() {

                @Override
                public void handleEvent(ModifiedBeanEvent<IMetadataColumn> event) {
                    fireCurrentDirectEditApply();
                    if (AbstractMetadataTableEditorView.ID_COLUMN_NAME.equals(event.column.getId())) {
                        if (event.index < selectedOutputTree.getNodes().size()) {
                            TreeNode treeNode = selectedOutputTree.getNodes().get(event.index);
                            if (treeNode != null) {
                                treeNode.setName((String) event.newValue);
                                processColumnNameChanged(treeNode);
                            }
                        }
                    } else if (AbstractMetadataTableEditorView.ID_COLUMN_TYPE.equals(event.column.getId())) {
                        if (event.index < selectedOutputTree.getNodes().size()) {
                            OutputTreeNode treeNode = selectedOutputTree.getNodes().get(event.index);
                            if (treeNode != null) {
                                String oldValue = treeNode.getType();
                                treeNode.setType((String) event.newValue);
                                if (oldValue != null && oldValue.equals(XmlMapUtil.DOCUMENT)) {
                                    XmlMapUtil.detachNodeConnections(treeNode, getExternalData(), true);
                                    List<TreeNode> removedLoops = new ArrayList<TreeNode>();
                                    if (mainInputTree != null && mainInputTree.isMultiLoops()) {
                                        XmlMapUtil.getChildLoops(removedLoops, treeNode.getChildren());
                                    }
                                    treeNode.getChildren().clear();
                                    selectedOutputTree.setMultiLoops(XmlMapUtil.checkMultiLoopsStatus(selectedOutputTree));
                                    if (mainInputTree != null && mainInputTree.isMultiLoops()) {
                                        if (XmlMapUtil.hasDocument(selectedOutputTree)) {
                                            XmlMapUtil.removeLoopTableForOutput(selectedOutputTree, removedLoops, mainInputTree == null ? false : mainInputTree.isMultiLoops());
                                        } else {
                                            selectedOutputTree.getInputLoopNodesTables().clear();
                                            selectedOutputTree.getInputLoopNodesTables().add(XmlmapFactory.eINSTANCE.createInputLoopNodesTable());
                                        }
                                    }
                                }
                                if (XmlMapUtil.DOCUMENT.equals(event.newValue)) {
                                    XmlMapUtil.detachNodeConnections(treeNode, getExternalData(), true);
                                    OutputTreeNode createTreeNode = XmlmapFactory.eINSTANCE.createOutputTreeNode();
                                    createTreeNode.setName("root");
                                    createTreeNode.setType(XmlMapUtil.DEFAULT_DATA_TYPE);
                                    createTreeNode.setNodeType(NodeType.ELEMENT);
                                    createTreeNode.setXpath(XmlMapUtil.getXPath(treeNode.getXpath(), createTreeNode.getName(), createTreeNode.getNodeType()));
                                    createTreeNode.setLoop(true);
                                    createTreeNode.setMain(true);
                                    treeNode.getChildren().add(createTreeNode);
                                }
                                problemsAnalyser.checkProblems(selectedOutputTree);
                                mapperUI.updateStatusBar();
                                outputTreeSchemaBeanListModified();
                            }
                        }
                    } else if (AbstractMetadataTableEditorView.ID_COLUMN_KEY.equals(event.column.getId())) {
                        if (event.index < selectedOutputTree.getNodes().size()) {
                            TreeNode treeNode = selectedOutputTree.getNodes().get(event.index);
                            treeNode.setKey((Boolean) event.newValue);
                        }
                    } else if (AbstractMetadataTableEditorView.ID_COLUMN_PATTERN.equals(event.column.getId())) {
                        if (event.index < selectedOutputTree.getNodes().size()) {
                            TreeNode treeNode = selectedOutputTree.getNodes().get(event.index);
                            treeNode.setPattern((String) event.newValue);
                        }
                    } else if (AbstractMetadataTableEditorView.ID_COLUMN_NULLABLE.equals(event.column.getId())) {
                        if (event.index < selectedOutputTree.getNodes().size()) {
                            TreeNode treeNode = selectedOutputTree.getNodes().get(event.index);
                            treeNode.setNullable((Boolean) event.newValue);
                        }
                    }
                }
            };
            editor.addModifiedBeanListener(columnListener);
            editor.addAfterOperationListListener(new IListenableListListener() {

                @Override
                public void handleEvent(ListenableListEvent event) {
                    if (event.type == TYPE.ADDED) {
                        EList<OutputTreeNode> nodes = selectedOutputTree.getNodes();
                        List<IMetadataColumn> metadataColumns = (List<IMetadataColumn>) event.addedObjects;
                        if (event.index != null) {
                            int index = event.index;
                            for (IMetadataColumn column : metadataColumns) {
                                OutputTreeNode createTreeNode = XmlmapFactory.eINSTANCE.createOutputTreeNode();
                                createTreeNode.setName(column.getLabel());
                                createTreeNode.setType(column.getTalendType());
                                createTreeNode.setNullable(column.isNullable());
                                createTreeNode.setPattern(column.getPattern());
                                createTreeNode.setXpath(XmlMapUtil.getXPath(selectedOutputTree.getName(), createTreeNode.getName(), createTreeNode.getNodeType()));
                                selectedOutputTree.getNodes().add(index, createTreeNode);
                                index = index + 1;
                            }
                        }
                    } else if (event.type == TYPE.REMOVED) {
                        List<IMetadataColumn> metadataColumns = (List<IMetadataColumn>) event.removedObjects;
                        List treeNodeToRemove = new ArrayList();
                        for (IMetadataColumn column : metadataColumns) {
                            for (TreeNode node : selectedOutputTree.getNodes()) {
                                if (node.getName() != null && node.getName().equals(column.getLabel())) {
                                    XmlMapUtil.detachNodeConnections(node, getExternalData(), true);
                                    treeNodeToRemove.add(node);
                                }
                            }
                        }
                        selectedOutputTree.getNodes().removeAll(treeNodeToRemove);
                        problemsAnalyser.checkProblems(selectedOutputTree);
                        mapperUI.updateStatusBar();
                        outputTreeSchemaBeanListModified();
                    } else if (event.type == TYPE.SWAPED) {
                        List<Integer> listIndexTarget = event.indicesTarget;
                        List<Integer> listIndexOrignal = event.indicesOrigin;
                        for (int i = 0; i < listIndexOrignal.size(); i++) {
                            int orignal = listIndexOrignal.get(i);
                            int target = listIndexTarget.get(i);
                            if (orignal < selectedOutputTree.getNodes().size()) {
                                OutputTreeNode tempTreeNode = selectedOutputTree.getNodes().get(orignal);
                                selectedOutputTree.getNodes().remove(orignal);
                                selectedOutputTree.getNodes().add(target, tempTreeNode);
                            }
                        }
                    } else if (event.type == TYPE.REPLACED) {
                        // fix for TDI-24071
                        List added = (List) event.addedObjects;
                        List removed = (List) event.removedObjects;
                        List<IMetadataColumn> removedColumn = new ArrayList<IMetadataColumn>();
                        List<IMetadataColumn> addedColumn = new ArrayList<IMetadataColumn>();
                        if (!added.isEmpty()) {
                            addedColumn.addAll((List<IMetadataColumn>) added.get(0));
                        }
                        if (!removed.isEmpty()) {
                            removedColumn.addAll((List<IMetadataColumn>) removed.get(0));
                        }
                        Map<IMetadataColumn, OutputTreeNode> nodeMap = new HashMap<IMetadataColumn, OutputTreeNode>();
                        for (int i = 0; i < removedColumn.size(); i++) {
                            IMetadataColumn column = removedColumn.get(i);
                            OutputTreeNode node = selectedOutputTree.getNodes().get(i);
                            boolean found = false;
                            for (IMetadataColumn columnAdded : addedColumn) {
                                if (column.sameMetacolumnAs(columnAdded)) {
                                    nodeMap.put(columnAdded, node);
                                    found = true;
                                    break;
                                }
                            }
                            if (!found) {
                                XmlMapUtil.detachNodeConnections(node, getExternalData(), true);
                            }
                        }
                        // remove all
                        boolean needCheck = false;
                        if (selectedOutputTree.isMultiLoops()) {
                            needCheck = true;
                        }
                        selectedOutputTree.getNodes().clear();
                        // add all
                        for (IMetadataColumn column : addedColumn) {
                            OutputTreeNode treeNode = nodeMap.get(column);
                            if (treeNode == null) {
                                treeNode = XmlmapFactory.eINSTANCE.createOutputTreeNode();
                                treeNode.setName(column.getLabel());
                                treeNode.setType(column.getTalendType());
                                treeNode.setNullable(column.isNullable());
                                treeNode.setPattern(column.getPattern());
                                treeNode.setXpath(XmlMapUtil.getXPath(selectedInputTree.getName(), treeNode.getName(), treeNode.getNodeType()));
                                if (XmlMapUtil.DOCUMENT.equals(column.getTalendType())) {
                                    TreeNode createTreeNode = XmlmapFactory.eINSTANCE.createOutputTreeNode();
                                    createTreeNode.setName("root");
                                    createTreeNode.setType(XmlMapUtil.DEFAULT_DATA_TYPE);
                                    createTreeNode.setNodeType(NodeType.ELEMENT);
                                    createTreeNode.setXpath(XmlMapUtil.getXPath(treeNode.getXpath(), createTreeNode.getName(), createTreeNode.getNodeType()));
                                    createTreeNode.setLoop(true);
                                    createTreeNode.setMain(true);
                                    treeNode.getChildren().add(createTreeNode);
                                }
                            }
                            selectedOutputTree.getNodes().add(treeNode);
                        }
                        if (needCheck) {
                            selectedOutputTree.setMultiLoops(XmlMapUtil.checkMultiLoopsStatus(selectedOutputTree));
                        }
                        mapperUI.updateStatusBar();
                        mapperUI.updateStatusBar();
                    }
                }
            });
        }
        refreshTreeSchemaEditor(outputTree);
    }
}
Also used : ListenableListEvent(org.talend.commons.utils.data.list.ListenableListEvent) MetadataTableEditor(org.talend.core.ui.metadata.editor.MetadataTableEditor) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) IModifiedBeanListener(org.talend.commons.ui.swt.tableviewer.IModifiedBeanListener) IListenableListListener(org.talend.commons.utils.data.list.IListenableListListener) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) ModifiedBeanEvent(org.talend.commons.ui.swt.tableviewer.ModifiedBeanEvent) EList(org.eclipse.emf.common.util.EList) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) List(java.util.List) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList) MetadataTableEditorView(org.talend.core.ui.metadata.editor.MetadataTableEditorView) AbstractMetadataTableEditorView(org.talend.core.ui.metadata.editor.AbstractMetadataTableEditorView)

Aggregations

OutputTreeNode (org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode)57 TreeNode (org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode)42 OutputXmlTree (org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree)27 ArrayList (java.util.ArrayList)16 InputXmlTree (org.talend.designer.xmlmap.model.emf.xmlmap.InputXmlTree)16 AbstractInOutTree (org.talend.designer.xmlmap.model.emf.xmlmap.AbstractInOutTree)15 VarNode (org.talend.designer.xmlmap.model.emf.xmlmap.VarNode)15 Connection (org.talend.designer.xmlmap.model.emf.xmlmap.Connection)11 VarTable (org.talend.designer.xmlmap.model.emf.xmlmap.VarTable)11 TreeNodeEditPart (org.talend.designer.xmlmap.parts.TreeNodeEditPart)10 AbstractNode (org.talend.designer.xmlmap.model.emf.xmlmap.AbstractNode)9 List (java.util.List)8 TransferedObject (org.talend.designer.gefabstractmap.dnd.TransferedObject)8 LookupConnection (org.talend.designer.xmlmap.model.emf.xmlmap.LookupConnection)8 XmlMapData (org.talend.designer.xmlmap.model.emf.xmlmap.XmlMapData)8 InputLoopNodesTable (org.talend.designer.xmlmap.model.emf.xmlmap.InputLoopNodesTable)7 OutputTreeNodeEditPart (org.talend.designer.xmlmap.parts.OutputTreeNodeEditPart)7 VarNodeEditPart (org.talend.designer.xmlmap.parts.VarNodeEditPart)6 FilterConnection (org.talend.designer.xmlmap.model.emf.xmlmap.FilterConnection)5 InputXmlTreeEditPart (org.talend.designer.xmlmap.parts.InputXmlTreeEditPart)5