Search in sources :

Example 76 with TreeNode

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

the class TreeSettingDirectEditCommand method calculateFilterConnections.

private void calculateFilterConnections(AbstractInOutTree abstractTree, String newValue) {
    XmlMapData mapperData = (XmlMapData) abstractTree.eContainer();
    List<TableEntryLocation> matchedLocations = expressionManager.parseTableEntryLocation((String) newValue);
    EList<FilterConnection> connections = abstractTree.getFilterIncomingConnections();
    List usefullConnections = new ArrayList();
    if (!matchedLocations.isEmpty()) {
        for (int i = 0; i < matchedLocations.size(); i++) {
            TableEntryLocation currentLocation = matchedLocations.get(i);
            boolean found = false;
            for (FilterConnection conn : connections) {
                TableEntryLocation sourceLocation = null;
                if (conn.getSource() instanceof TreeNode) {
                    sourceLocation = expressionManager.parseTableEntryLocation(XmlMapUtil.convertToExpression(((TreeNode) conn.getSource()).getXpath())).get(0);
                } else if (conn.getSource() instanceof VarNode) {
                    VarNode varNode = (VarNode) conn.getSource();
                    sourceLocation = new TableEntryLocation(((VarTable) varNode.eContainer()).getName(), varNode.getName());
                }
                if (currentLocation.equals(sourceLocation)) {
                    found = true;
                    usefullConnections.add(conn);
                    break;
                }
            }
            if (!found) {
                if (mapperData != null) {
                    String convertToXpath = XmlMapUtil.convertToXpath(currentLocation.toString());
                    boolean findFromVar = false;
                    if (abstractTree instanceof OutputXmlTree) {
                        findFromVar = true;
                    }
                    AbstractNode sourceNode = findConnectionSource(mapperData, currentLocation, XmlMapUtil.getXPathLength(convertToXpath), findFromVar);
                    if (sourceNode != null) {
                        FilterConnection connection = null;
                        connection = XmlmapFactory.eINSTANCE.createFilterConnection();
                        sourceNode.getFilterOutGoingConnections().add(connection);
                        abstractTree.getFilterIncomingConnections().add(connection);
                        connection.setSource(sourceNode);
                        connection.setTarget(abstractTree);
                        mapperData.getConnections().add(connection);
                        usefullConnections.add(connection);
                    }
                }
            }
        }
        List<FilterConnection> copyOfConnections = new ArrayList<FilterConnection>(connections);
        copyOfConnections.removeAll(usefullConnections);
        for (FilterConnection connection : copyOfConnections) {
            if (connection.getSource() != null) {
                if (connection.getSource().getFilterOutGoingConnections().contains(connection)) {
                    connection.getSource().getFilterOutGoingConnections().remove(connection);
                    mapperData.getConnections().remove(connection);
                }
            }
        }
        abstractTree.getFilterIncomingConnections().removeAll(copyOfConnections);
    } else if (!connections.isEmpty()) {
        for (FilterConnection connection : connections) {
            if (connection.getSource() != null) {
                if (connection.getSource().getFilterOutGoingConnections().contains(connection)) {
                    connection.getSource().getFilterOutGoingConnections().remove(connection);
                    mapperData.getConnections().remove(connection);
                }
            }
        }
        abstractTree.getFilterIncomingConnections().removeAll(connections);
    }
}
Also used : VarNode(org.talend.designer.xmlmap.model.emf.xmlmap.VarNode) FilterConnection(org.talend.designer.xmlmap.model.emf.xmlmap.FilterConnection) AbstractNode(org.talend.designer.xmlmap.model.emf.xmlmap.AbstractNode) ArrayList(java.util.ArrayList) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) TableEntryLocation(org.talend.designer.xmlmap.ui.expressionutil.TableEntryLocation) EList(org.eclipse.emf.common.util.EList) ArrayList(java.util.ArrayList) List(java.util.List) OutputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree) XmlMapData(org.talend.designer.xmlmap.model.emf.xmlmap.XmlMapData)

Example 77 with TreeNode

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

the class DeleteTreeNodeAction method calculateEnabled.

@Override
protected boolean calculateEnabled() {
    // nodesNeedToChangeMainStatus.clear();
    if (getSelectedObjects().isEmpty()) {
        return false;
    } else {
        boolean enable = true;
        Object s = getSelectedObjects().get(0);
        if (s instanceof List && !((List) s).isEmpty()) {
            List selectedarts = (List) s;
            Object lastSelection = selectedarts.get(selectedarts.size() - 1);
            if (!(lastSelection instanceof TreeNodeEditPart)) {
                return false;
            }
            for (Object obj : selectedarts) {
                if (obj instanceof TreeNodeEditPart) {
                    TreeNodeEditPart nodePart = (TreeNodeEditPart) obj;
                    TreeNode treeNode = (TreeNode) nodePart.getModel();
                    int xPathLength = XmlMapUtil.getXPathLength(treeNode.getXpath());
                    if (xPathLength <= 2) {
                        enable = false;
                    }
                    // can't delete root
                    if (treeNode.eContainer() instanceof TreeNode && XmlMapUtil.DOCUMENT.equals(((TreeNode) treeNode.eContainer()).getType())) {
                        enable = false;
                    }
                }
                if (!enable) {
                    return enable;
                }
            }
        }
        return enable;
    }
}
Also used : OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) List(java.util.List) ArrayList(java.util.ArrayList) TreeNodeEditPart(org.talend.designer.xmlmap.parts.TreeNodeEditPart)

Example 78 with TreeNode

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

the class DropContextAnalyzer method checkDropInputValid.

private boolean checkDropInputValid(Object target) {
    if (objects.getType() == TransferdType.INPUT) {
        for (Object obj : objects.getToTransfer()) {
            TreeNodeEditPart part = (TreeNodeEditPart) obj;
            AbstractInOutTree srouceTree = XmlMapUtil.getAbstractInOutTree((TreeNode) part.getModel());
            AbstractInOutTree targetTree = null;
            if (target instanceof InputXmlTree) {
                targetTree = (InputXmlTree) target;
            } else {
                targetTree = XmlMapUtil.getAbstractInOutTree((TreeNode) target);
            }
            if (srouceTree == targetTree) {
                return false;
            }
            if (srouceTree.eContainer() instanceof XmlMapData) {
                XmlMapData mapdata = ((XmlMapData) srouceTree.eContainer());
                int indexSource = mapdata.getInputTrees().indexOf(srouceTree);
                int indexTarget = mapdata.getInputTrees().indexOf(targetTree);
                if (indexTarget < indexSource) {
                    return false;
                }
            }
        }
    }
    return true;
}
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) AbstractInOutTree(org.talend.designer.xmlmap.model.emf.xmlmap.AbstractInOutTree) TransferedObject(org.talend.designer.gefabstractmap.dnd.TransferedObject) TreeNodeEditPart(org.talend.designer.xmlmap.parts.TreeNodeEditPart) XmlMapData(org.talend.designer.xmlmap.model.emf.xmlmap.XmlMapData) Point(org.eclipse.draw2d.geometry.Point)

Example 79 with TreeNode

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

the class AddChoiceAction 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;
                }
                // can't create two or more choice under a node
                EList<TreeNode> children = parent.getChildren();
                for (int i = 0; i < children.size(); i++) {
                    if (children.get(i).isChoice()) {
                        return false;
                    }
                }
                boolean isElement = NodeType.ELEMENT.equals(parent.getNodeType());
                if (isElement && XmlMapUtil.getXPathLength(parent.getXpath()) > 2) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) 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 80 with TreeNode

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

the class CreateElementAction method run.

@Override
public void run() {
    TreeNode treeNode = null;
    boolean needWarning = false;
    if (input) {
        treeNode = XmlmapFactory.eINSTANCE.createTreeNode();
        if (!parent.getOutgoingConnections().isEmpty()) {
            needWarning = true;
        }
    } else {
        treeNode = XmlmapFactory.eINSTANCE.createOutputTreeNode();
        OutputTreeNode outputTreeNode = (OutputTreeNode) treeNode;
        EList<Connection> incomingConnections = parent.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 an sub element for the selected element ?");
    }
    if (canContinue) {
        // IInputValidator validataor = new IInputValidator() {
        //
        // public String isValid(String newText) {
        // String xpath = XmlMapUtil.getXPath(parent.getXpath(), newText, NodeType.ELEMENT);
        // EList<TreeNode> children = parent.getChildren();
        // boolean exist = false;
        // for (TreeNode child : children) {
        // if (child.getXpath() != null && child.getXpath().equals(xpath)) {
        // exist = true;
        // break;
        // }
        // }
        //
        // if (exist) {
        // return "Element '" + newText + "' already exist !";
        // } else {
        // return null;
        // }
        // }
        //
        // };
        InputDialog dialog = new InputDialog(null, "Create New Element", "Input the new element's valid label", "", null);
        int open = -1;
        String label = "";
        while (!StringUtil.validateLabelForXML(label)) {
            open = dialog.open();
            if (open == InputDialog.OK) {
                label = dialog.getValue().trim();
            }
            if (open == InputDialog.CANCEL) {
                return;
            }
        }
        if (open == Window.OK) {
            XmlMapUtil.detachNodeConnections(parent, mapperManager.getExternalData(), false);
            treeNode.setName(label);
            treeNode.setNodeType(NodeType.ELEMENT);
            String parentXpath = parent.getXpath();
            if (parent.isChoice() || parent.isSubstitution()) {
                TreeNode realPrant = XmlMapUtil.getRealParentNode(parent);
                if (realPrant != null) {
                    parentXpath = realPrant.getXpath();
                }
            }
            treeNode.setXpath(XmlMapUtil.getXPath(parentXpath, treeNode.getName(), treeNode.getNodeType()));
            treeNode.setType(XmlMapUtil.DEFAULT_DATA_TYPE);
            parent.getChildren().add(treeNode);
            parent.setExpression("");
            if (!input) {
                OutputTreeNode output = (OutputTreeNode) parent;
                if (!XmlMapUtil.isExpressionEditable(output) && output.isAggregate()) {
                    output.setAggregate(false);
                }
            }
        }
        if (open == Window.OK && mapperManager != null) {
            // if (input) {
            // mapperManager.inputTreeSchemaBeanListModified();
            // } else {
            // mapperManager.outputTreeSchemaBeanListModified();
            // }
            Object object = graphicViewer.getEditPartRegistry().get(treeNode);
            if (object instanceof TreeNodeEditPart) {
                graphicViewer.select((TreeNodeEditPart) object);
            }
        }
    }
}
Also used : InputDialog(org.eclipse.jface.dialogs.InputDialog) 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)

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