Search in sources :

Example 6 with AbstractInOutTree

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

use of org.talend.designer.xmlmap.model.emf.xmlmap.AbstractInOutTree 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)

Example 8 with AbstractInOutTree

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

the class ImportTreeFromXml 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 parentPart = (TreeNodeEditPart) object;
                parentNode = (TreeNode) parentPart.getModel();
                if (parentNode.eContainer() instanceof AbstractInOutTree && XmlMapUtil.DOCUMENT.equals(parentNode.getType())) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : AbstractInOutTree(org.talend.designer.xmlmap.model.emf.xmlmap.AbstractInOutTree) ArrayList(java.util.ArrayList) List(java.util.List) TreeNodeEditPart(org.talend.designer.xmlmap.parts.TreeNodeEditPart)

Example 9 with AbstractInOutTree

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

the class XmlMapConnectionBuilder method hasMaptchedLocation.

private boolean hasMaptchedLocation(XmlMapExpressionManager expressionManager, TableEntryLocation sourceLocation, EObject targetNodeOrTree, ExpressionType type) {
    String targetExpression = null;
    AbstractNode targetNode = null;
    AbstractInOutTree targetTree = null;
    switch(type) {
        case EXPRESSION:
            targetNode = (AbstractNode) targetNodeOrTree;
            targetExpression = targetNode.getExpression();
            break;
        case EXPRESSION_FILTER:
            targetTree = (AbstractInOutTree) targetNodeOrTree;
            targetExpression = targetTree.getExpressionFilter();
        default:
            break;
    }
    if (!"".equals(targetExpression) && targetExpression != null) {
        List<TableEntryLocation> targetLocations = expressionManager.parseTableEntryLocation(targetExpression);
        for (TableEntryLocation target : targetLocations) {
            if (sourceLocation.equals(target)) {
                return true;
            } else if (checkRootNodePrefix && !cancelForAll) {
                StringBuffer bf = new StringBuffer();
                String prefix = null;
                String nodeName = null;
                final String[] split = sourceLocation.toString().split("/");
                if (split.length > 2) {
                    for (int i = 0; i < split.length; i++) {
                        String value = split[i];
                        if (i == 1) {
                            int indexOf = split[1].indexOf(":");
                            if (indexOf != -1) {
                                prefix = split[1].substring(0, indexOf);
                                nodeName = split[1].substring(indexOf + 1, split[1].length());
                                value = nodeName;
                            } else {
                                break;
                            }
                        }
                        bf.append(value);
                        if (i < split.length - 1) {
                            bf.append("/");
                        }
                    }
                }
                if (bf.toString().equals(targetExpression)) {
                    if (applyForAll) {
                        // reset the target expression with prefix
                        if (targetNode != null) {
                            targetNode.setExpression(expressionManager.replaceExpression(targetExpression, target, sourceLocation));
                        }
                        if (targetTree != null) {
                            targetTree.setExpressionFilter(expressionManager.replaceExpression(targetExpression, target, sourceLocation));
                        }
                        return true;
                    } else {
                        PrefixChangeDialog dialog = new PrefixChangeDialog(new Shell());
                        dialog.setPrefix(prefix);
                        dialog.setRootNodeName(nodeName);
                        dialog.setSourceExpression(sourceLocation.toString());
                        dialog.setTargetExpression(target.toString());
                        if (dialog.open() == Window.OK) {
                            applyForAll = dialog.isApplyAll();
                            cancelForAll = dialog.isCancelAll();
                            if (cancelForAll) {
                                return false;
                            }
                            // reset the target expression with prefix
                            if (targetNode != null) {
                                targetNode.setExpression(expressionManager.replaceExpression(targetExpression, target, sourceLocation));
                            }
                            if (targetTree != null) {
                                targetTree.setExpressionFilter(expressionManager.replaceExpression(targetExpression, target, sourceLocation));
                            }
                            return true;
                        }
                    }
                }
            }
        }
    }
    return false;
}
Also used : Shell(org.eclipse.swt.widgets.Shell) AbstractNode(org.talend.designer.xmlmap.model.emf.xmlmap.AbstractNode) TableEntryLocation(org.talend.designer.xmlmap.ui.expressionutil.TableEntryLocation) AbstractInOutTree(org.talend.designer.xmlmap.model.emf.xmlmap.AbstractInOutTree) PrefixChangeDialog(org.talend.designer.xmlmap.ui.dialog.PrefixChangeDialog)

Example 10 with AbstractInOutTree

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

the class XmlMapConnectionBuilder method rebuildLinks.

public void rebuildLinks(TreeNode docNode, XmlMapData mapData) {
    if (docNode == null || mapData == null) {
        return;
    }
    AbstractInOutTree inputTree = XmlMapUtil.getAbstractInOutTree(docNode);
    int index = mapData.getInputTrees().indexOf(inputTree);
    if (index == -1) {
        index = mapData.getInputTrees().size();
    }
    List<TreeNode> nodes = new ArrayList<TreeNode>();
    nodes.add(docNode);
    rebuildLink(index, nodes, mapData);
}
Also used : OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) ArrayList(java.util.ArrayList) AbstractInOutTree(org.talend.designer.xmlmap.model.emf.xmlmap.AbstractInOutTree)

Aggregations

AbstractInOutTree (org.talend.designer.xmlmap.model.emf.xmlmap.AbstractInOutTree)32 TreeNode (org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode)25 OutputTreeNode (org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode)23 ArrayList (java.util.ArrayList)15 OutputXmlTree (org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree)13 InputXmlTree (org.talend.designer.xmlmap.model.emf.xmlmap.InputXmlTree)12 TreeNodeEditPart (org.talend.designer.xmlmap.parts.TreeNodeEditPart)8 List (java.util.List)6 FilterConnection (org.talend.designer.xmlmap.model.emf.xmlmap.FilterConnection)6 VarNode (org.talend.designer.xmlmap.model.emf.xmlmap.VarNode)6 AbstractNode (org.talend.designer.xmlmap.model.emf.xmlmap.AbstractNode)5 InputLoopNodesTable (org.talend.designer.xmlmap.model.emf.xmlmap.InputLoopNodesTable)4 LookupConnection (org.talend.designer.xmlmap.model.emf.xmlmap.LookupConnection)4 XmlMapData (org.talend.designer.xmlmap.model.emf.xmlmap.XmlMapData)4 TransferedObject (org.talend.designer.gefabstractmap.dnd.TransferedObject)3 XmlmapTreeNodeFigure (org.talend.designer.xmlmap.figures.treeNode.XmlmapTreeNodeFigure)3 Connection (org.talend.designer.xmlmap.model.emf.xmlmap.Connection)3 VarTable (org.talend.designer.xmlmap.model.emf.xmlmap.VarTable)3 OutputTreeNodeEditPart (org.talend.designer.xmlmap.parts.OutputTreeNodeEditPart)3 Iterator (java.util.Iterator)2