Search in sources :

Example 26 with TreeNode

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

the class ImportTreeFromRepository method createDefaultTreeNode.

private TreeNode createDefaultTreeNode(TreeNode parentNode, String name) {
    TreeNode createTreeNode = createModel();
    createTreeNode.setName(name);
    createTreeNode.setNodeType(NodeType.ELEMENT);
    createTreeNode.setType(XmlMapUtil.DEFAULT_DATA_TYPE);
    createTreeNode.setXpath(XmlMapUtil.getXPath(parentNode.getXpath(), createTreeNode.getName(), createTreeNode.getNodeType()));
    parentNode.getChildren().add(createTreeNode);
    return createTreeNode;
}
Also used : FOXTreeNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode)

Example 27 with TreeNode

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

the class RenameTreeNodeAction method run.

@Override
public void run() {
    if (selectedNode != null) {
        // validataor
        IInputValidator validataor = new IInputValidator() {

            public String isValid(String newText) {
                String xpath = XmlMapUtil.getXPath(((TreeNode) selectedNode.eContainer()).getXpath(), newText, selectedNode.getNodeType());
                EList<TreeNode> children = ((TreeNode) selectedNode.eContainer()).getChildren();
                boolean exist = false;
                for (TreeNode child : children) {
                    if (child.getNodeType().equals(selectedNode.getNodeType())) {
                        if (child.getXpath() != null && child.getXpath().equals(xpath) && !child.equals(selectedNode)) {
                            exist = true;
                            break;
                        }
                    }
                }
                if (exist) {
                    if (selectedNode.getNodeType().equals(NodeType.ATTRIBUT)) {
                        return "Atribute '" + newText + "' already exist !";
                    } else if (selectedNode.getNodeType().equals(NodeType.ELEMENT)) {
                        return "Element '" + newText + "' already exist !";
                    }
                }
                return null;
            }
        };
        String name = selectedNode.getName();
        if (selectedNode.isSubstitution()) {
            name = name.substring(0, name.lastIndexOf(XSDPopulationUtil2.SUBS));
        }
        InputDialog dialog = new InputDialog(null, "Rename Tree Node", "", name, validataor);
        if (dialog.open() == Window.OK) {
            if (selectedNode.isSubstitution()) {
                selectedNode.setName(dialog.getValue() + XSDPopulationUtil2.SUBS);
            } else {
                selectedNode.setName(dialog.getValue());
            }
            // refresh
            if (selectedNode.isSubstitution()) {
                TreeNode realParent = XmlMapUtil.getRealParentNode(selectedNode);
                if (realParent != null) {
                    selectedNode.setXpath(XmlMapUtil.getXPath(realParent.getXpath(), selectedNode.getName(), selectedNode.getNodeType()));
                }
            } else {
                XmlMapData externalEmfData = (XmlMapData) mapperManager.getExternalData();
                XmlMapUtil.updateXPathAndExpression(externalEmfData, mapperManager.getMapperComponent().getExpressionManager(), selectedNode, dialog.getValue(), XmlMapUtil.getXPathLength(selectedNode.getXpath()), true);
            }
            TabFolderEditors tabFolderEditors = mapperManager.getMapperUI().getTabFolderEditors();
            if (tabFolderEditors != null) {
                if (selectedNode instanceof OutputTreeNode) {
                    tabFolderEditors.getOutputTreeSchemaEditor().refresh();
                } else if (selectedNode instanceof TreeNode) {
                    tabFolderEditors.getInputTreeSchemaEditor().refresh();
                }
            }
        }
    }
}
Also used : TabFolderEditors(org.talend.designer.xmlmap.ui.tabs.TabFolderEditors) InputDialog(org.eclipse.jface.dialogs.InputDialog) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) XmlMapData(org.talend.designer.xmlmap.model.emf.xmlmap.XmlMapData) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Example 28 with TreeNode

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

the class InsertNewColumnCommand method validSourceNodeName.

private String validSourceNodeName(final List<? extends AbstractNode> validationList, TreeNode sourceNode) {
    String sourceName = sourceNode.getName();
    boolean isValidate = MetadataToolHelper.isValidColumnName(sourceName);
    boolean fixing = false;
    if (!isValidate) {
        if (sourceName.contains(":")) {
            //$NON-NLS-1$
            if (sourceNode.eContainer() instanceof TreeNode) {
                TreeNode parent = (TreeNode) sourceNode.eContainer();
                for (TreeNode child : parent.getChildren()) {
                    if (child.getNodeType() == NodeType.NAME_SPACE) {
                        if (sourceName.startsWith(child.getName() + ":")) {
                            //$NON-NLS-1$
                            sourceName = sourceName.substring(child.getName().length() + 1, sourceName.length());
                            fixing = true;
                        }
                    }
                }
                if (!fixing) {
                    //$NON-NLS-1$
                    sourceName = sourceName.substring(sourceName.indexOf(":"), sourceName.length());
                    fixing = true;
                }
            }
        }
        if (!fixing || !MetadataToolHelper.isValidColumnName(sourceName)) {
            IInputValidator validataor = new IInputValidator() {

                @Override
                public String isValid(String newText) {
                    return XmlMapUtil.isValidColumnName(validationList, newText);
                }
            };
            InputDialog dialog = new InputDialog(null, Messages.getString("InsertNewColumnCommand_createNew"), Messages.getString("InsertNewColumnCommand_message"), sourceName, //$NON-NLS-1$ //$NON-NLS-2$
            validataor);
            int open = dialog.open();
            if (open == Window.CANCEL) {
                return null;
            } else {
                sourceName = dialog.getValue();
            }
        }
    }
    return sourceName;
}
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) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Example 29 with TreeNode

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

the class AddChoiceAction 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();
        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 a choice for the selected element ?");
    }
    if (canContinue) {
        XmlMapUtil.detachNodeConnections(parent, mapperManager.getExternalData(), false);
        treeNode.setName(parent.getName() + XSDPopulationUtil2.CHOICE);
        treeNode.setNodeType(NodeType.ELEMENT);
        treeNode.setXpath(XmlMapUtil.getXPath(this.parent.getXpath(), treeNode.getName(), treeNode.getNodeType()));
        treeNode.setChoice(true);
        parent.getChildren().add(treeNode);
        if (!input) {
            OutputTreeNode output = (OutputTreeNode) parent;
            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 : 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 30 with TreeNode

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

the class CreateAttributeAction method run.

@Override
public void run() {
    TreeNode treeNode = null;
    if (input) {
        treeNode = XmlmapFactory.eINSTANCE.createTreeNode();
    } else {
        treeNode = XmlmapFactory.eINSTANCE.createOutputTreeNode();
    }
    // IInputValidator validataor = new IInputValidator() {
    //
    // public String isValid(String newText) {
    // String xpath = XmlMapUtil.getXPath(parent.getXpath(), newText, NodeType.ATTRIBUT);
    // 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 "Atribute '" + newText + "' already exist !";
    // } else {
    // return null;
    // }
    // }
    //
    // };
    String label = "";
    InputDialog dialog = new InputDialog(null, "Create New Attribute", "Input the new attribute's valid label", "", null);
    int open = -1;
    while (!StringUtil.validateLabelForXML(label)) {
        open = dialog.open();
        if (open == InputDialog.OK) {
            label = dialog.getValue().trim();
        }
        if (open == InputDialog.CANCEL) {
            return;
        }
    }
    if (open == Window.OK) {
        treeNode.setName(label);
        treeNode.setNodeType(NodeType.ATTRIBUT);
        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);
        final EList<TreeNode> children = parent.getChildren();
        int index = 0;
        for (int i = 0; i < children.size(); i++) {
            final TreeNode child = children.get(i);
            if (child.getNodeType() == NodeType.NAME_SPACE || child.getNodeType() == NodeType.ATTRIBUT) {
                if (i == children.size() - 1) {
                    index = children.size();
                }
                continue;
            } else {
                index = i;
                break;
            }
        }
        children.add(index, treeNode);
    }
    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) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) 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