Search in sources :

Example 21 with TreeNode

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

the class CreateNodeAndConnectionCommand method execute.

@Override
public void execute() {
    if (targetEditPart == null) {
        return;
    }
    xmlMapData = getXmlMapData(targetEditPart.getModel());
    if (xmlMapData == null) {
        return;
    }
    if (newObjects instanceof TransferedObject) {
        TransferedObject tranceferedObj = (TransferedObject) newObjects;
        // this node type is only used when drag leaf element or attribute or varnode to create output node
        NodeType selectedNodeType = NodeType.ELEMENT;
        if (!update && targetEditPart instanceof OutputTreeNodeEditPart) {
            OutputTreeNode targetOutputNode = (OutputTreeNode) ((OutputTreeNodeEditPart) targetEditPart).getModel();
            Shell shell = targetEditPart.getViewer().getControl().getShell();
            // if allNamespace , create output as namespace , if allsubTree , create output subtree , no need prompt
            boolean needPrompt = false;
            boolean hasSubTree = false;
            for (Object o : tranceferedObj.getToTransfer()) {
                if (o instanceof VarNodeEditPart) {
                    needPrompt = true;
                } else if (o instanceof TreeNodeEditPart) {
                    TreeNode treeNode = (TreeNode) ((TreeNodeEditPart) o).getModel();
                    if (NodeType.ATTRIBUT.equals(treeNode.getNodeType())) {
                        needPrompt = true;
                    }
                    if (NodeType.ELEMENT.equals(treeNode.getNodeType())) {
                        if (treeNode.getChildren().isEmpty()) {
                            needPrompt = true;
                        } else {
                            hasSubTree = true;
                        }
                    }
                }
            }
            if (needPrompt) {
                DragAndDrogDialog selectDialog = new DragAndDrogDialog(shell, !targetOutputNode.getChildren().isEmpty());
                int open = selectDialog.open();
                if (open == Window.OK) {
                    if (DragAndDrogDialog.CREATE_AS_SUBELEMENT.equals(selectDialog.getSelectValue())) {
                        selectedNodeType = NodeType.ELEMENT;
                    } else if (DragAndDrogDialog.CREATE_AS_ATTRIBUTE.equals(selectDialog.getSelectValue())) {
                        selectedNodeType = NodeType.ATTRIBUT;
                    } else if (DragAndDrogDialog.CREATE_AS_SUBELEMENT.equals(selectDialog.getSelectValue())) {
                        selectedNodeType = NodeType.NAME_SPACE;
                    } else if (DragAndDrogDialog.CREATE_AS_TEXT.equals(selectDialog.getSelectValue())) {
                        update = true;
                    }
                } else {
                    return;
                }
            }
            if (!update) {
                if (!targetOutputNode.getIncomingConnections().isEmpty() && ((selectedNodeType != NodeType.ATTRIBUT && selectedNodeType != NodeType.NAME_SPACE) || hasSubTree)) {
                    boolean canContinue = MessageDialog.openConfirm(null, "Warning", "Do you want to disconnect the existing linker and then add an sub element for the selected element ?");
                    if (canContinue) {
                        XmlMapUtil.detachNodeConnections(targetOutputNode, xmlMapData, false);
                    } else {
                        return;
                    }
                }
            }
        }
        for (Object o : (tranceferedObj.getToTransfer())) {
            if (!(o instanceof TableEntityPart)) {
                continue;
            }
            AbstractNode sourceNode = (AbstractNode) ((TableEntityPart) o).getModel();
            if (update) {
                doUpdate(sourceNode);
            } else {
                // only drop output can create a new node now
                if (targetEditPart instanceof OutputTreeNodeEditPart) {
                    OutputTreeNode targetOutputNode = (OutputTreeNode) ((OutputTreeNodeEditPart) targetEditPart).getModel();
                    OutputTreeNode targetNode = XmlmapFactory.eINSTANCE.createOutputTreeNode();
                    targetNode.setName(sourceNode.getName());
                    targetNode.setType(XmlMapUtil.DEFAULT_DATA_TYPE);
                    if (sourceNode instanceof TreeNode) {
                        NodeType nodeType = selectedNodeType;
                        if (NodeType.NAME_SPACE.equals(((TreeNode) sourceNode).getNodeType())) {
                            // namespace and only be droped as namespace
                            nodeType = NodeType.NAME_SPACE;
                            targetNode.setDefaultValue(((TreeNode) sourceNode).getDefaultValue());
                        } else if (!((TreeNode) sourceNode).getChildren().isEmpty()) {
                            nodeType = ((TreeNode) sourceNode).getNodeType();
                        }
                        targetNode.setXpath(XmlMapUtil.getXPath(targetOutputNode.getXpath(), targetNode.getName(), nodeType));
                        targetNode.setNodeType(nodeType);
                        targetNode.setExpression(XmlMapUtil.convertToExpression(((TreeNode) sourceNode).getXpath()));
                        EList<TreeNode> sourceChildren = ((TreeNode) sourceNode).getChildren();
                        if (!sourceChildren.isEmpty()) {
                            // children must be attribute or namespace
                            for (TreeNode child : sourceChildren) {
                                OutputTreeNode childTarget = XmlmapFactory.eINSTANCE.createOutputTreeNode();
                                childTarget.setName(child.getName());
                                childTarget.setType(child.getType());
                                childTarget.setNodeType(child.getNodeType());
                                childTarget.setXpath(XmlMapUtil.getXPath(targetNode.getXpath(), childTarget.getName(), childTarget.getNodeType()));
                                targetNode.getChildren().add(childTarget);
                                if (NodeType.NAME_SPACE.equals(child.getNodeType())) {
                                    childTarget.setDefaultValue(child.getDefaultValue());
                                    // default value is already set as from source , no need the expression to get
                                    // default value
                                    childTarget.setExpression("");
                                } else {
                                    childTarget.setExpression(XmlMapUtil.convertToExpression(child.getXpath()));
                                    Connection conn = XmlmapFactory.eINSTANCE.createConnection();
                                    conn.setSource(child);
                                    conn.setTarget(childTarget);
                                    // attach source and target
                                    childTarget.getIncomingConnections().add(conn);
                                    child.getOutgoingConnections().add(conn);
                                    if (xmlMapData != null) {
                                        xmlMapData.getConnections().add(conn);
                                    }
                                }
                            }
                        }
                    } else if (sourceNode instanceof VarNode) {
                        String variable = sourceNode.getName();
                        targetNode.setXpath(XmlMapUtil.getXPath(targetOutputNode.getXpath(), targetNode.getName(), selectedNodeType));
                        targetNode.setNodeType(selectedNodeType);
                        if (sourceNode.eContainer() instanceof VarTable) {
                            VarTable container = (VarTable) sourceNode.eContainer();
                            variable = container.getName() + TalendTextUtils.JAVA_END_STRING + variable;
                        }
                        targetNode.setExpression(variable);
                    }
                    targetOutputNode.getChildren().add(targetNode);
                    // add connection
                    Connection conn = XmlmapFactory.eINSTANCE.createConnection();
                    conn.setSource(sourceNode);
                    conn.setTarget(targetNode);
                    // attach source and target
                    targetNode.getIncomingConnections().add(conn);
                    sourceNode.getOutgoingConnections().add(conn);
                    if (xmlMapData != null) {
                        xmlMapData.getConnections().add(conn);
                    }
                // if (sourceNode instanceof TreeNode) {
                // createInputLoopTable((TreeNode) sourceNode, targetNode);
                // }
                }
            }
        }
    }
    if (targetEditPart instanceof OutputTreeNodeEditPart) {
        OutputTreeNode model = (OutputTreeNode) targetEditPart.getModel();
        if (NodeType.NAME_SPACE.equals(model.getNodeType()) && model.getExpression() != null && !"".equals(model.getExpression())) {
            model.setDefaultValue("");
        }
        if (!XmlMapUtil.isExpressionEditable(model)) {
            model.setExpression("");
            if (model.isAggregate()) {
                model.setAggregate(false);
            }
        }
    }
}
Also used : VarNode(org.talend.designer.xmlmap.model.emf.xmlmap.VarNode) VarNodeEditPart(org.talend.designer.xmlmap.parts.VarNodeEditPart) TableEntityPart(org.talend.designer.gefabstractmap.part.TableEntityPart) AbstractNode(org.talend.designer.xmlmap.model.emf.xmlmap.AbstractNode) FilterConnection(org.talend.designer.xmlmap.model.emf.xmlmap.FilterConnection) Connection(org.talend.designer.xmlmap.model.emf.xmlmap.Connection) LookupConnection(org.talend.designer.xmlmap.model.emf.xmlmap.LookupConnection) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) TreeNodeEditPart(org.talend.designer.xmlmap.parts.TreeNodeEditPart) OutputTreeNodeEditPart(org.talend.designer.xmlmap.parts.OutputTreeNodeEditPart) DragAndDrogDialog(org.talend.designer.xmlmap.dnd.DragAndDrogDialog) VarTable(org.talend.designer.xmlmap.model.emf.xmlmap.VarTable) Shell(org.eclipse.swt.widgets.Shell) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) NodeType(org.talend.designer.xmlmap.model.emf.xmlmap.NodeType) TransferedObject(org.talend.designer.gefabstractmap.dnd.TransferedObject) TransferedObject(org.talend.designer.gefabstractmap.dnd.TransferedObject) OutputTreeNodeEditPart(org.talend.designer.xmlmap.parts.OutputTreeNodeEditPart)

Example 22 with TreeNode

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

the class UpdateExpressionCommand method execute.

@Override
public void execute() {
    AbstractNode targetNode = (AbstractNode) targetEditPart.getModel();
    boolean targetVar = targetNode instanceof VarNode;
    boolean targetOutput = targetNode instanceof OutputTreeNode;
    boolean targetInput = targetNode instanceof TreeNode && !(targetNode instanceof OutputTreeNode);
    String expression = targetNode.getExpression();
    if (objects.getToTransfer() != null) {
        for (Object obj : objects.getToTransfer()) {
            AbstractNode sourceNode = null;
            if (objects.getType() == TransferdType.INPUT) {
                TreeNodeEditPart part = (TreeNodeEditPart) obj;
                sourceNode = (TreeNode) part.getModel();
                if (expression == null) {
                    expression = XmlMapUtil.convertToExpression(((TreeNode) sourceNode).getXpath());
                } else {
                    expression = expression + " " + XmlMapUtil.convertToExpression(((TreeNode) sourceNode).getXpath());
                }
                targetNode.setExpression(expression);
                // INPUT => OUTPUT/VAR
                if (targetVar || targetOutput) {
                    createConnection(sourceNode, targetNode);
                    if (targetOutput) {
                        OutputTreeNode model = (OutputTreeNode) targetNode;
                        if (NodeType.NAME_SPACE.equals(model.getNodeType()) && model.getExpression() != null && !"".equals(model.getExpression())) {
                            model.setDefaultValue("");
                        }
                    // disable function of add source loop to target InputLoopNodesTable
                    // InputLoopTableUtil.addSourceLoopToInputLoopTable((TreeNode) sourceNode, model,
                    // manager.getMainInputTree());
                    }
                } else // INPUT => INPUT
                if (targetInput) {
                    createLookupConnection((TreeNode) sourceNode, (TreeNode) targetNode);
                }
            } else if (objects.getType() == TransferdType.VAR) {
                // VARE ==>OUTPUT
                String tableName = "Var";
                VarNodeEditPart part = (VarNodeEditPart) obj;
                sourceNode = (VarNode) part.getModel();
                if (sourceNode.eContainer() instanceof VarTable) {
                    tableName = ((VarTable) sourceNode.eContainer()).getName();
                }
                if (expression == null) {
                    expression = tableName + "." + sourceNode.getName();
                } else {
                    expression = expression + " " + tableName + "." + sourceNode.getName();
                }
                targetNode.setExpression(expression);
                createConnection(sourceNode, targetNode);
            }
        }
    }
}
Also used : VarNode(org.talend.designer.xmlmap.model.emf.xmlmap.VarNode) VarTable(org.talend.designer.xmlmap.model.emf.xmlmap.VarTable) VarNodeEditPart(org.talend.designer.xmlmap.parts.VarNodeEditPart) AbstractNode(org.talend.designer.xmlmap.model.emf.xmlmap.AbstractNode) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) TransferedObject(org.talend.designer.gefabstractmap.dnd.TransferedObject) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) TreeNodeEditPart(org.talend.designer.xmlmap.parts.TreeNodeEditPart)

Example 23 with TreeNode

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

the class UpdateFilterExpressionCommand method execute.

@Override
public void execute() {
    AbstractInOutTree targetTree = (AbstractInOutTree) targetEditPart.getModel();
    String expression = targetTree.getExpressionFilter();
    if (objects.getToTransfer() != null) {
        for (Object obj : objects.getToTransfer()) {
            AbstractNode sourceNode = null;
            // INPUT == FILTER
            if (objects.getType() == TransferdType.INPUT) {
                TreeNodeEditPart part = (TreeNodeEditPart) obj;
                sourceNode = (TreeNode) part.getModel();
                if (expression == null) {
                    expression = XmlMapUtil.convertToExpression(((TreeNode) sourceNode).getXpath());
                } else {
                    expression = expression + " " + XmlMapUtil.convertToExpression(((TreeNode) sourceNode).getXpath());
                }
            } else // VARE == FILTER
            if (objects.getType() == TransferdType.VAR) {
                String tableName = "Var";
                VarNodeEditPart part = (VarNodeEditPart) obj;
                sourceNode = (VarNode) part.getModel();
                if (sourceNode.eContainer() instanceof VarTable) {
                    tableName = ((VarTable) sourceNode.eContainer()).getName();
                }
                if (expression == null) {
                    expression = tableName + "." + sourceNode.getName();
                } else {
                    expression = expression + " " + tableName + "." + sourceNode.getName();
                }
            }
            if (sourceNode != null) {
                targetTree.setExpressionFilter(expression);
                FilterConnection connection = XmlmapFactory.eINSTANCE.createFilterConnection();
                connection.setSource(sourceNode);
                connection.setTarget(targetTree);
                targetTree.getFilterIncomingConnections().add(connection);
                sourceNode.getFilterOutGoingConnections().add(connection);
                xmlMapData.getConnections().add(connection);
            }
        // check if need update outputTree InputLoopNodesTable
        }
    }
}
Also used : VarNode(org.talend.designer.xmlmap.model.emf.xmlmap.VarNode) VarTable(org.talend.designer.xmlmap.model.emf.xmlmap.VarTable) VarNodeEditPart(org.talend.designer.xmlmap.parts.VarNodeEditPart) FilterConnection(org.talend.designer.xmlmap.model.emf.xmlmap.FilterConnection) AbstractNode(org.talend.designer.xmlmap.model.emf.xmlmap.AbstractNode) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) AbstractInOutTree(org.talend.designer.xmlmap.model.emf.xmlmap.AbstractInOutTree) TransferedObject(org.talend.designer.gefabstractmap.dnd.TransferedObject) TreeNodeEditPart(org.talend.designer.xmlmap.parts.TreeNodeEditPart)

Example 24 with TreeNode

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

the class CreateNameSpaceAction method calculateEnabled.

@Override
protected boolean calculateEnabled() {
    if (getSelectedObjects().isEmpty()) {
        return false;
    } else {
        // get the last selection to run the action
        Object s = getSelectedObjects().get(0);
        if (s instanceof List && !((List) s).isEmpty()) {
            List selectedarts = (List) s;
            Object object = selectedarts.get(selectedarts.size() - 1);
            if (object instanceof TreeNodeEditPart) {
                TreeNodeEditPart nodePart = (TreeNodeEditPart) object;
                this.parent = (TreeNode) nodePart.getModel();
                if (parent.isChoice() || parent.isSubstitution()) {
                    return false;
                }
                boolean isElement = NodeType.ELEMENT.equals(parent.getNodeType());
                if (isElement && !XmlMapUtil.DOCUMENT.equals(parent.getType()) && parent.eContainer() instanceof TreeNode) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) EList(org.eclipse.emf.common.util.EList) List(java.util.List) TreeNodeEditPart(org.talend.designer.xmlmap.parts.TreeNodeEditPart)

Example 25 with TreeNode

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

the class DeleteTreeNodeAction method run.

@Override
public void run() {
    try {
        TreeNode docRoot = null;
        Object s = getSelectedObjects().get(0);
        if (s instanceof List && !((List) s).isEmpty()) {
            List selectedarts = new ArrayList((List) s);
            Iterator iter = selectedarts.iterator();
            while (iter.hasNext()) {
                Object obj = iter.next();
                if (obj instanceof TreeNodeEditPart) {
                    TreeNodeEditPart nodePart = (TreeNodeEditPart) obj;
                    TreeNode treeNode = (TreeNode) nodePart.getModel();
                    if (treeNode.eContainer() instanceof TreeNode) {
                        TreeNode parent = (TreeNode) treeNode.eContainer();
                        if (docRoot == null) {
                            docRoot = XmlMapUtil.getTreeNodeRoot(parent);
                        }
                        XmlMapUtil.detachNodeConnections(treeNode, mapperManager.getExternalData(), true);
                        // if delete loop , clean group and main
                        if (treeNode.isLoop()) {
                            if (treeNode instanceof OutputTreeNode && XmlMapUtil.findUpGroupNode((OutputTreeNode) treeNode) != null) {
                                XmlMapUtil.cleanSubGroup(docRoot);
                            }
                            XmlMapUtil.clearMainNode(docRoot);
                        }
                        parent.getChildren().remove(treeNode);
                        // check if tree is multiloop
                        if (docRoot != null && docRoot.eContainer() instanceof AbstractInOutTree) {
                            AbstractInOutTree tree = (AbstractInOutTree) docRoot.eContainer();
                            tree.setMultiLoops(XmlMapUtil.checkMultiLoopsStatus(tree));
                        }
                        if (input) {
                            // remove delete loops in InputLoopTable for outputs
                            List<TreeNode> subNodes = new ArrayList<TreeNode>();
                            checkSubElementIsLoop(treeNode, subNodes);
                            XmlMapUtil.removeloopInOutputTree(mapperManager, subNodes);
                        }
                    }
                }
            }
        }
        if (mapperManager != null) {
            mapperManager.beanListModified(input);
            // }
            if (docRoot != null && docRoot.eContainer() instanceof AbstractInOutTree) {
                mapperManager.getProblemsAnalyser().checkProblems((AbstractInOutTree) docRoot.eContainer());
                mapperManager.getMapperUI().updateStatusBar();
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) AbstractInOutTree(org.talend.designer.xmlmap.model.emf.xmlmap.AbstractInOutTree) List(java.util.List) ArrayList(java.util.ArrayList) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) TreeNodeEditPart(org.talend.designer.xmlmap.parts.TreeNodeEditPart)

Aggregations

TreeNode (org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode)119 OutputTreeNode (org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode)88 ArrayList (java.util.ArrayList)39 InputXmlTree (org.talend.designer.xmlmap.model.emf.xmlmap.InputXmlTree)34 OutputXmlTree (org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree)26 AbstractInOutTree (org.talend.designer.xmlmap.model.emf.xmlmap.AbstractInOutTree)25 TreeNodeEditPart (org.talend.designer.xmlmap.parts.TreeNodeEditPart)22 List (java.util.List)21 VarNode (org.talend.designer.xmlmap.model.emf.xmlmap.VarNode)19 XmlMapData (org.talend.designer.xmlmap.model.emf.xmlmap.XmlMapData)17 EList (org.eclipse.emf.common.util.EList)15 LookupConnection (org.talend.designer.xmlmap.model.emf.xmlmap.LookupConnection)14 AbstractNode (org.talend.designer.xmlmap.model.emf.xmlmap.AbstractNode)13 Connection (org.talend.designer.xmlmap.model.emf.xmlmap.Connection)12 VarTable (org.talend.designer.xmlmap.model.emf.xmlmap.VarTable)12 FilterConnection (org.talend.designer.xmlmap.model.emf.xmlmap.FilterConnection)11 FOXTreeNode (org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode)10 TransferedObject (org.talend.designer.gefabstractmap.dnd.TransferedObject)9 VarNodeEditPart (org.talend.designer.xmlmap.parts.VarNodeEditPart)9 OutputTreeNodeEditPart (org.talend.designer.xmlmap.parts.OutputTreeNodeEditPart)8