Search in sources :

Example 1 with TreeNodeEditPart

use of org.talend.designer.xmlmap.parts.TreeNodeEditPart in project tdi-studio-se by Talend.

the class CreateDocChildrenCommand method execute.

@Override
public void execute() {
    // only drop output can create a new node now
    OutputTreeNode targetOutputNode = (OutputTreeNode) targetEditPart.getModel();
    String expression = "";
    if (objects.getToTransfer() != null) {
        for (Object obj : objects.getToTransfer()) {
            OutputTreeNode createdNode = (OutputTreeNode) rq.getNewObject();
            AbstractNode source = null;
            if (objects.getType() == TransferdType.INPUT) {
                TreeNodeEditPart part = (TreeNodeEditPart) obj;
                TreeNode sourceNode = (TreeNode) part.getModel();
                source = sourceNode;
                createdNode.setName(sourceNode.getName());
                createdNode.setType(sourceNode.getType());
                createdNode.setPattern(sourceNode.getPattern());
                expression = XmlMapUtil.convertToExpression(sourceNode.getXpath());
                createdNode.setExpression(expression);
                // INPUT => OUTPUT
                if (createdNode instanceof OutputTreeNode) {
                    if (NodeType.NAME_SPACE.equals(sourceNode.getNodeType())) {
                        // namespace and only be droped as namespace
                        createdNode.setDefaultValue(sourceNode.getDefaultValue());
                    }
                    createdNode.setXpath(XmlMapUtil.getXPath(targetOutputNode.getXpath(), createdNode.getName(), createdNode.getNodeType()));
                    createdNode.setExpression(XmlMapUtil.convertToExpression(sourceNode.getXpath()));
                    EList<TreeNode> sourceChildren = 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.setPattern(child.getPattern());
                            childTarget.setNodeType(child.getNodeType());
                            childTarget.setXpath(XmlMapUtil.getXPath(createdNode.getXpath(), childTarget.getName(), childTarget.getNodeType()));
                            createdNode.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()));
                                createConnection(child, childTarget);
                            }
                        }
                    }
                // disable function of add source loop to target InputLoopNodesTable
                // InputLoopTableUtil
                // .addSourceLoopToInputLoopTable(sourceNode, targetOutputNode, manager.getMainInputTree());
                }
            } else if (objects.getType() == TransferdType.VAR) {
                // VARE ==>OUTPUT
                VarNodeEditPart part = (VarNodeEditPart) obj;
                VarNode sourceNode = (VarNode) part.getModel();
                source = sourceNode;
                String variable = sourceNode.getName();
                createdNode.setName(variable);
                createdNode.setXpath(XmlMapUtil.getXPath(targetOutputNode.getXpath(), createdNode.getName(), createdNode.getNodeType()));
                if (sourceNode.eContainer() instanceof VarTable) {
                    VarTable container = (VarTable) sourceNode.eContainer();
                    variable = container.getName() + TalendTextUtils.JAVA_END_STRING + variable;
                }
                createdNode.setExpression(variable);
            }
            targetOutputNode.getChildren().add(createdNode);
            createConnection(source, createdNode);
            if (!XmlMapUtil.isExpressionEditable(targetOutputNode)) {
                targetOutputNode.setExpression("");
                if (targetOutputNode.isAggregate()) {
                    targetOutputNode.setAggregate(false);
                }
            }
        }
    }
}
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) OutputTreeNodeEditPart(org.talend.designer.xmlmap.parts.OutputTreeNodeEditPart)

Example 2 with TreeNodeEditPart

use of org.talend.designer.xmlmap.parts.TreeNodeEditPart 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 3 with TreeNodeEditPart

use of org.talend.designer.xmlmap.parts.TreeNodeEditPart 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 4 with TreeNodeEditPart

use of org.talend.designer.xmlmap.parts.TreeNodeEditPart 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 5 with TreeNodeEditPart

use of org.talend.designer.xmlmap.parts.TreeNodeEditPart 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)

Aggregations

TreeNodeEditPart (org.talend.designer.xmlmap.parts.TreeNodeEditPart)30 TreeNode (org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode)22 OutputTreeNode (org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode)16 List (java.util.List)15 VarNodeEditPart (org.talend.designer.xmlmap.parts.VarNodeEditPart)9 ArrayList (java.util.ArrayList)8 EList (org.eclipse.emf.common.util.EList)8 TransferedObject (org.talend.designer.gefabstractmap.dnd.TransferedObject)8 AbstractInOutTree (org.talend.designer.xmlmap.model.emf.xmlmap.AbstractInOutTree)8 VarNode (org.talend.designer.xmlmap.model.emf.xmlmap.VarNode)7 OutputTreeNodeEditPart (org.talend.designer.xmlmap.parts.OutputTreeNodeEditPart)7 VarTable (org.talend.designer.xmlmap.model.emf.xmlmap.VarTable)6 Connection (org.talend.designer.xmlmap.model.emf.xmlmap.Connection)5 AbstractNode (org.talend.designer.xmlmap.model.emf.xmlmap.AbstractNode)4 Point (org.eclipse.draw2d.geometry.Point)3 InputXmlTree (org.talend.designer.xmlmap.model.emf.xmlmap.InputXmlTree)3 Iterator (java.util.Iterator)2 InputDialog (org.eclipse.jface.dialogs.InputDialog)2 Shell (org.eclipse.swt.widgets.Shell)2 TableEntityPart (org.talend.designer.gefabstractmap.part.TableEntityPart)2