Search in sources :

Example 1 with Connection

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

the class SetSubstitutionAction method run.

@Override
public void run() {
    TreeNode treeNode = null;
    boolean needWarning = false;
    if (input) {
        treeNode = XmlmapFactory.eINSTANCE.createTreeNode();
        if (!selectedNode.getOutgoingConnections().isEmpty()) {
            needWarning = true;
        }
    } else {
        treeNode = XmlmapFactory.eINSTANCE.createOutputTreeNode();
        EList<Connection> incomingConnections = selectedNode.getIncomingConnections();
        if (!incomingConnections.isEmpty()) {
            needWarning = true;
        }
    }
    boolean canContinue = true;
    // Shell shell = this.part.getSite().getShell();
    if (needWarning) {
        canContinue = MessageDialog.openConfirm(null, "Warning", "Do you want to disconnect the existing linker and then add a choice for the selected element ?");
    }
    if (canContinue) {
        AbstractUIPlugin plugin = (AbstractUIPlugin) Platform.getPlugin(PlatformUI.PLUGIN_ID);
        IDialogSettings workbenchSettings = plugin.getDialogSettings();
        //$NON-NLS-1$
        IDialogSettings section = workbenchSettings.getSection("SetSubstitutionAction.SubsMessageDialog");
        if (section == null) {
            //$NON-NLS-1$
            section = workbenchSettings.addNewSection("SetSubstitutionAction.SubsMessageDialog");
        }
        boolean popupMessageDialog = !section.getBoolean(HIDE_MESSAGE);
        if (popupMessageDialog) {
            String message = "This element will be copied as part of the substitution group automatically." + "\n" + "If this element must be abstract and must be extended only, you can delete it.";
            SubsMessageDialog dialog = new SubsMessageDialog(null, message);
            int open = dialog.open();
            if (open == Window.OK) {
                boolean hideDialogNextTime = dialog.getResult();
                if (hideDialogNextTime) {
                    section.put(HIDE_MESSAGE, true);
                }
            }
            if (open == Window.CANCEL) {
                return;
            }
        }
        XmlMapUtil.detachNodeConnections(selectedNode, mapperManager.getExternalData(), false);
        treeNode.setName(selectedNode.getName() + XSDPopulationUtil2.SUBS);
        treeNode.setNodeType(NodeType.ELEMENT);
        treeNode.setXpath(selectedNode.getXpath() + XmlMapUtil.XPATH_SEPARATOR + treeNode.getName());
        treeNode.setSubstitution(true);
        TreeNode parentNode = (TreeNode) selectedNode.eContainer();
        int index = parentNode.getChildren().indexOf(selectedNode);
        parentNode.getChildren().remove(selectedNode);
        treeNode.getChildren().add(selectedNode);
        parentNode.getChildren().add(index, treeNode);
        if (!input) {
            OutputTreeNode output = (OutputTreeNode) selectedNode;
            if (!XmlMapUtil.isExpressionEditable(output) && output.isAggregate()) {
                output.setAggregate(false);
            }
        }
        Object object = graphicViewer.getEditPartRegistry().get(treeNode);
        if (object instanceof TreeNodeEditPart) {
            graphicViewer.select((TreeNodeEditPart) object);
        }
    }
}
Also used : AbstractUIPlugin(org.eclipse.ui.plugin.AbstractUIPlugin) IDialogSettings(org.eclipse.jface.dialogs.IDialogSettings) 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) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) TreeNodeEditPart(org.talend.designer.xmlmap.parts.TreeNodeEditPart)

Example 2 with Connection

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

the class AutoMapper method map.

/**
     * DOC amaumont Comment method "map".
     */
public void map() {
    EList<InputXmlTree> inputTrees = xmlMapData.getInputTrees();
    EList<OutputXmlTree> outputTrees = xmlMapData.getOutputTrees();
    /*
         * non-document node , if name is the same ,automap document node , check xpath first , if can't find ,check the
         * name
         */
    for (OutputXmlTree outputTree : outputTrees) {
        List<TreeNode> outputEntries = getAllEntities(outputTree);
        for (TreeNode outputEntry : outputEntries) {
            if ((outputEntry.getExpression() == null || "".equals(outputEntry.getExpression())) && XmlMapUtil.isExpressionEditable(outputEntry)) {
                String xpath = outputEntry.getXpath();
                String outputNodePath = xpath.substring(outputTree.getName().length() + 1, xpath.length());
                TreeNode inputSameXpath = null;
                TreeNode inputSameName = null;
                out: for (InputXmlTree inputTable : inputTrees) {
                    List<TreeNode> inputColumnEntries = getAllEntities(inputTable);
                    in: for (TreeNode inputEntry : inputColumnEntries) {
                        // check if input tree node can be mapped
                        if (XmlMapUtil.isExpressionEditable(inputEntry)) {
                            String inputXpath = inputEntry.getXpath();
                            String inputNodePath = inputXpath.substring(inputTable.getName().length() + 1, inputXpath.length());
                            if (outputNodePath.equals(inputNodePath)) {
                                inputSameXpath = inputEntry;
                                break out;
                            }
                            // if the same name , find the first matched node , don't overwrite
                            if (inputSameName == null && outputEntry.getName() != null && outputEntry.getName().equals(inputEntry.getName())) {
                                inputSameName = inputEntry;
                            }
                        }
                    }
                }
                TreeNode inputEntryToMap = null;
                if (inputSameXpath != null) {
                    inputEntryToMap = inputSameXpath;
                } else if (inputSameName != null) {
                    inputEntryToMap = inputSameName;
                }
                if (inputEntryToMap != null) {
                    String expression = outputEntry.getExpression();
                    String convertToExpression = XmlMapUtil.convertToExpression(inputEntryToMap.getXpath());
                    if (expression != null && expression.indexOf(convertToExpression) != -1) {
                        continue;
                    } else {
                        if (expression == null) {
                            expression = "";
                        }
                        expression = expression + convertToExpression;
                    }
                    outputEntry.setExpression(expression);
                    Connection conn = XmlmapFactory.eINSTANCE.createConnection();
                    conn.setSource(inputEntryToMap);
                    conn.setTarget(outputEntry);
                    outputEntry.getIncomingConnections().add(conn);
                    inputEntryToMap.getOutgoingConnections().add(conn);
                    xmlMapData.getConnections().add(conn);
                }
            }
        }
    }
}
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) List(java.util.List) EList(org.eclipse.emf.common.util.EList) ArrayList(java.util.ArrayList) OutputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree)

Example 3 with Connection

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

the class CreateDocChildrenCommand method createConnection.

private void createConnection(AbstractNode sourceNode, AbstractNode targetNode) {
    Connection conn = XmlmapFactory.eINSTANCE.createConnection();
    conn.setSource(sourceNode);
    conn.setTarget(targetNode);
    targetNode.getIncomingConnections().add(conn);
    sourceNode.getOutgoingConnections().add(conn);
    if (xmlMapData != null) {
        xmlMapData.getConnections().add(conn);
    }
}
Also used : Connection(org.talend.designer.xmlmap.model.emf.xmlmap.Connection)

Example 4 with Connection

use of org.talend.designer.xmlmap.model.emf.xmlmap.Connection 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 5 with Connection

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

the class UpdateExpressionCommand method createConnection.

private void createConnection(AbstractNode sourceNode, AbstractNode targetNode) {
    Connection conn = XmlmapFactory.eINSTANCE.createConnection();
    conn.setSource(sourceNode);
    conn.setTarget(targetNode);
    targetNode.getIncomingConnections().add(conn);
    sourceNode.getOutgoingConnections().add(conn);
    if (xmlMapData != null) {
        xmlMapData.getConnections().add(conn);
    }
}
Also used : Connection(org.talend.designer.xmlmap.model.emf.xmlmap.Connection) LookupConnection(org.talend.designer.xmlmap.model.emf.xmlmap.LookupConnection)

Aggregations

Connection (org.talend.designer.xmlmap.model.emf.xmlmap.Connection)18 OutputTreeNode (org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode)13 TreeNode (org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode)12 LookupConnection (org.talend.designer.xmlmap.model.emf.xmlmap.LookupConnection)11 FilterConnection (org.talend.designer.xmlmap.model.emf.xmlmap.FilterConnection)7 OutputXmlTree (org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree)5 TreeNodeEditPart (org.talend.designer.xmlmap.parts.TreeNodeEditPart)5 AbstractInOutTree (org.talend.designer.xmlmap.model.emf.xmlmap.AbstractInOutTree)4 AbstractNode (org.talend.designer.xmlmap.model.emf.xmlmap.AbstractNode)4 InputXmlTree (org.talend.designer.xmlmap.model.emf.xmlmap.InputXmlTree)4 VarNode (org.talend.designer.xmlmap.model.emf.xmlmap.VarNode)4 VarTable (org.talend.designer.xmlmap.model.emf.xmlmap.VarTable)4 IConnection (org.talend.designer.xmlmap.model.emf.xmlmap.IConnection)3 INodeConnection (org.talend.designer.xmlmap.model.emf.xmlmap.INodeConnection)3 ArrayList (java.util.ArrayList)2 InputLoopNodesTable (org.talend.designer.xmlmap.model.emf.xmlmap.InputLoopNodesTable)2 XmlMapData (org.talend.designer.xmlmap.model.emf.xmlmap.XmlMapData)2 OutputTreeNodeEditPart (org.talend.designer.xmlmap.parts.OutputTreeNodeEditPart)2 VarNodeEditPart (org.talend.designer.xmlmap.parts.VarNodeEditPart)2 HashMap (java.util.HashMap)1