Search in sources :

Example 21 with TreeNodeEditPart

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

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

Example 23 with TreeNodeEditPart

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

the class CreateElementAction 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();
                boolean isElement = NodeType.ELEMENT.equals(parent.getNodeType());
                if (isElement && XmlMapUtil.getXPathLength(parent.getXpath()) > 2) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : EList(org.eclipse.emf.common.util.EList) List(java.util.List) TreeNodeEditPart(org.talend.designer.xmlmap.parts.TreeNodeEditPart)

Example 24 with TreeNodeEditPart

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

the class CreateNodeAndConnectionCommand method doUpdate.

// private void createInputLoopTable(TreeNode sourceNode, OutputTreeNode targetOutputNode) {
// EditPartViewer viewer = targetEditPart.getViewer();
// if (viewer instanceof XmlMapGraphicViewer) {
// InputLoopTableUtil.addSourceLoopToInputLoopTable(sourceNode, targetOutputNode, ((XmlMapGraphicViewer) viewer)
// .getMapperManager().getMainInputTree());
// }
// }
private void doUpdate(AbstractNode sourceNode) {
    if (targetEditPart instanceof OutputTreeNodeEditPart) {
        OutputTreeNode targetOutputNode = (OutputTreeNode) ((OutputTreeNodeEditPart) targetEditPart).getModel();
        String expression = targetOutputNode.getExpression();
        if (sourceNode instanceof TreeNode) {
            if (expression == null) {
                expression = XmlMapUtil.convertToExpression(((TreeNode) sourceNode).getXpath());
            } else {
                expression = expression + " " + XmlMapUtil.convertToExpression(((TreeNode) sourceNode).getXpath());
            }
        } else if (sourceNode instanceof VarNode) {
            String tableName = "Var";
            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 instanceof TreeNode) {
        // createInputLoopTable((TreeNode) sourceNode, targetOutputNode);
        // }
        targetOutputNode.setExpression(expression);
        Connection conn = XmlmapFactory.eINSTANCE.createConnection();
        conn.setSource(sourceNode);
        conn.setTarget(targetOutputNode);
        targetOutputNode.getIncomingConnections().add(conn);
        sourceNode.getOutgoingConnections().add(conn);
        if (xmlMapData != null) {
            xmlMapData.getConnections().add(conn);
        }
    } else if (targetEditPart instanceof TreeNodeEditPart) {
        /* for lookup connections */
        if (sourceNode instanceof TreeNode) {
            TreeNode targetTreeNode = (TreeNode) targetEditPart.getModel();
            String expression = targetTreeNode.getExpression();
            if (expression == null) {
                expression = "";
            }
            expression = expression + " " + XmlMapUtil.convertToExpression(((TreeNode) sourceNode).getXpath());
            targetTreeNode.setExpression(expression);
            LookupConnection conn = XmlmapFactory.eINSTANCE.createLookupConnection();
            conn.setSource(sourceNode);
            conn.setTarget(targetTreeNode);
            targetTreeNode.getLookupIncomingConnections().add(conn);
            ((TreeNode) sourceNode).getLookupOutgoingConnections().add(conn);
            if (xmlMapData != null) {
                xmlMapData.getConnections().add(conn);
            }
        }
    } else if (targetEditPart instanceof VarNodeEditPart) {
        /* for varTable drag drop */
        if (sourceNode instanceof TreeNode) {
            VarNodeEditPart targetPart = (VarNodeEditPart) targetEditPart;
            VarNode targetNode = (VarNode) targetPart.getModel();
            String expression = targetNode.getExpression();
            if (expression == null) {
                expression = "";
            }
            expression = expression + " " + XmlMapUtil.convertToExpression(((TreeNode) sourceNode).getXpath());
            if (targetNode.getName() == null || "".equals(targetNode.getName())) {
                String findUniqueVarColumnName = XmlMapUtil.findUniqueVarColumnName(sourceNode.getName(), xmlMapData.getVarTables().get(0));
                targetNode.setName(findUniqueVarColumnName);
            }
            targetNode.setExpression(expression.trim());
            targetNode.setType(sourceNode.getType());
            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);
            }
        }
    } else if (targetEditPart instanceof InputXmlTreeEditPart || targetEditPart instanceof OutputXmlTreeEditPart) {
        AbstractInOutTree treeModel = (AbstractInOutTree) targetEditPart.getModel();
        String expression = treeModel.getExpressionFilter();
        if (sourceNode instanceof TreeNode) {
            if (expression == null) {
                expression = XmlMapUtil.convertToExpression(((TreeNode) sourceNode).getXpath());
            } else {
                expression = expression + " " + XmlMapUtil.convertToExpression(((TreeNode) sourceNode).getXpath());
            }
        } else if (sourceNode instanceof VarNode) {
            String tableName = "Var";
            if (sourceNode.eContainer() instanceof VarTable) {
                tableName = ((VarTable) sourceNode.eContainer()).getName();
            }
            if (expression == null) {
                expression = tableName + "." + sourceNode.getName();
            } else {
                expression = expression + " " + tableName + "." + sourceNode.getName();
            }
        }
        treeModel.setExpressionFilter(expression);
        FilterConnection connection = XmlmapFactory.eINSTANCE.createFilterConnection();
        connection.setSource(sourceNode);
        connection.setTarget(treeModel);
        treeModel.getFilterIncomingConnections().add(connection);
        sourceNode.getFilterOutGoingConnections().add(connection);
        xmlMapData.getConnections().add(connection);
    }
}
Also used : VarNode(org.talend.designer.xmlmap.model.emf.xmlmap.VarNode) VarNodeEditPart(org.talend.designer.xmlmap.parts.VarNodeEditPart) FilterConnection(org.talend.designer.xmlmap.model.emf.xmlmap.FilterConnection) 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) AbstractInOutTree(org.talend.designer.xmlmap.model.emf.xmlmap.AbstractInOutTree) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) LookupConnection(org.talend.designer.xmlmap.model.emf.xmlmap.LookupConnection) TreeNodeEditPart(org.talend.designer.xmlmap.parts.TreeNodeEditPart) OutputTreeNodeEditPart(org.talend.designer.xmlmap.parts.OutputTreeNodeEditPart) OutputXmlTreeEditPart(org.talend.designer.xmlmap.parts.OutputXmlTreeEditPart) VarTable(org.talend.designer.xmlmap.model.emf.xmlmap.VarTable) InputXmlTreeEditPart(org.talend.designer.xmlmap.parts.InputXmlTreeEditPart) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) OutputTreeNodeEditPart(org.talend.designer.xmlmap.parts.OutputTreeNodeEditPart)

Example 25 with TreeNodeEditPart

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

the class SetSubstitutionAction method calculateEnabled.

@Override
protected boolean calculateEnabled() {
    if (getSelectedObjects().isEmpty()) {
        return false;
    } else {
        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.selectedNode = (TreeNode) nodePart.getModel();
                if (selectedNode.isChoice() || selectedNode.isSubstitution()) {
                    return false;
                }
                if (hasSameNameWithParentSubs(selectedNode, selectedNode)) {
                    return false;
                }
                boolean isElement = NodeType.ELEMENT.equals(selectedNode.getNodeType());
                if (isElement && XmlMapUtil.getXPathLength(selectedNode.getXpath()) > 3) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : 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