Search in sources :

Example 1 with PrefixChangeDialog

use of org.talend.designer.xmlmap.ui.dialog.PrefixChangeDialog 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)

Aggregations

Shell (org.eclipse.swt.widgets.Shell)1 AbstractInOutTree (org.talend.designer.xmlmap.model.emf.xmlmap.AbstractInOutTree)1 AbstractNode (org.talend.designer.xmlmap.model.emf.xmlmap.AbstractNode)1 PrefixChangeDialog (org.talend.designer.xmlmap.ui.dialog.PrefixChangeDialog)1 TableEntryLocation (org.talend.designer.xmlmap.ui.expressionutil.TableEntryLocation)1