Search in sources :

Example 1 with XmlMapData

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

the class TXMLMapChangeAllInOneValueMigrationTask method execute.

/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.talend.core.model.migration.TXMLMapChangeAllInOneValueMigrationTask
	 * (org .talend.core.model.properties.Item)
	 */
@Override
public ExecutionResult execute(Item item) {
    IProxyRepositoryFactory factory = CorePlugin.getDefault().getRepositoryService().getProxyRepositoryFactory();
    ProcessType processType = getProcessType(item);
    boolean modified = false;
    if (processType != null) {
        for (Object obj : processType.getNode()) {
            NodeType nodeType = (NodeType) obj;
            if (nodeType.getComponentName().startsWith("tXMLMap")) {
                XmlMapData xmlMapdata = (XmlMapData) nodeType.getNodeData();
                EList<OutputXmlTree> outputTables = xmlMapdata.getOutputTrees();
                EList<InputXmlTree> inputTables = xmlMapdata.getInputTrees();
                boolean hasDocumentInTheMainInputTable = false;
                for (InputXmlTree inputTable : inputTables) {
                    if (!(inputTable.isLookup())) {
                        for (TreeNode inputEntry : inputTable.getNodes()) {
                            if ("id_Document".equals(inputEntry.getType())) {
                                hasDocumentInTheMainInputTable = true;
                            }
                        }
                    }
                }
                if (hasDocumentInTheMainInputTable) {
                    for (OutputXmlTree outputTable : outputTables) {
                        for (TreeNode outputEntry : outputTable.getNodes()) {
                            if ("id_Document".equals(outputEntry.getType())) {
                                if (!outputTable.isAllInOne()) {
                                    outputTable.setAllInOne(true);
                                    modified = true;
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    try {
        if (modified) {
            factory.save(item, true);
            return ExecutionResult.SUCCESS_WITH_ALERT;
        } else {
            return ExecutionResult.SUCCESS_NO_ALERT;
        }
    } catch (Exception e) {
        ExceptionHandler.process(e);
        return ExecutionResult.FAILURE;
    }
}
Also used : InputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.InputXmlTree) ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) OutputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) XmlMapData(org.talend.designer.xmlmap.model.emf.xmlmap.XmlMapData)

Example 2 with XmlMapData

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

the class FixValueAction method run.

@Override
public void run() {
    if (selectedNode != null) {
        NameSpaceDialog nsDialog = new NameSpaceDialog(null);
        nsDialog.setCurrentNode(selectedNode);
        nsDialog.setParentNode((TreeNode) selectedNode.eContainer());
        int status = nsDialog.open();
        if (status == nsDialog.OK) {
            String defaultValue = nsDialog.getNSValue();
            if (defaultValue != null) {
                defaultValue = defaultValue.trim();
            }
            String prefix = nsDialog.getPrefix().trim();
            selectedNode.setDefaultValue(defaultValue);
            if (prefix == null || "".equals(prefix)) {
                prefix = XmlMapUtil.DEFAULT_NAME_SPACE_PREFIX;
            }
            selectedNode.setName(prefix);
            XmlMapData externalEmfData = (XmlMapData) mapperManager.getExternalData();
            XmlMapUtil.updateXPathAndExpression(externalEmfData, mapperManager.getMapperComponent().getExpressionManager(), selectedNode, prefix, XmlMapUtil.getXPathLength(selectedNode.getXpath()), true);
        }
    }
}
Also used : NameSpaceDialog(org.talend.designer.xmlmap.ui.dialog.NameSpaceDialog) XmlMapData(org.talend.designer.xmlmap.model.emf.xmlmap.XmlMapData)

Example 3 with XmlMapData

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

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

the class XMLMapperHelper method hasDocumentInMainInput.

private static boolean hasDocumentInMainInput(final INode xmlMapperNode) {
    boolean hasDocumentInMainInput = false;
    List<? extends IConnection> inConnections = (List<? extends IConnection>) xmlMapperNode.getIncomingConnections();
    XmlMapData xmlMapData = (XmlMapData) ElementParameterParser.getObjectValueXMLTree(xmlMapperNode);
    if (xmlMapData != null && inConnections != null && inConnections.size() > 0) {
        List<InputXmlTree> inputTables = xmlMapData.getInputTrees();
        HashMap<String, IConnection> hNameToConnection = new HashMap<String, IConnection>();
        for (IConnection connection : inConnections) {
            hNameToConnection.put(connection.getName(), connection);
        }
        for (InputXmlTree inputTable : inputTables) {
            String tableName = inputTable.getName();
            IConnection connection = hNameToConnection.get(tableName);
            if (connection == null) {
                continue;
            }
            if (!(inputTable.isLookup())) {
                for (TreeNode node : inputTable.getNodes()) {
                    if ("id_Document".equals(node.getType())) {
                        hasDocumentInMainInput = true;
                        break;
                    }
                }
            }
        }
    }
    return hasDocumentInMainInput;
}
Also used : InputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.InputXmlTree) HashMap(java.util.HashMap) 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) ArrayList(java.util.ArrayList) List(java.util.List) IConnection(org.talend.core.model.process.IConnection) XmlMapData(org.talend.designer.xmlmap.model.emf.xmlmap.XmlMapData)

Example 5 with XmlMapData

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

the class ProblemsAnalyser method checkProblems.

public List<Problem> checkProblems() {
    treeAndProblems.clear();
    final XmlMapData copyOfMapData = mapperManager.getExternalData();
    if (copyOfMapData != null) {
        // check problems for InputLoopTable in output
        InputXmlTree mainInputTree = mapperManager.getMainInputTree();
        for (OutputXmlTree outputTree : copyOfMapData.getOutputTrees()) {
            checkInputLoopTablesProblem(outputTree, mainInputTree);
        }
        for (InputXmlTree inputTree : copyOfMapData.getInputTrees()) {
            isMultipleDocType = false;
            checkTreeNodesProblem(inputTree, inputTree.getNodes());
        }
        for (OutputXmlTree outputTree : copyOfMapData.getOutputTrees()) {
            isMultipleDocType = false;
            checkTreeNodesProblem(outputTree, outputTree.getNodes());
        }
    }
    return getProblems();
}
Also used : InputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.InputXmlTree) OutputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree) XmlMapData(org.talend.designer.xmlmap.model.emf.xmlmap.XmlMapData)

Aggregations

XmlMapData (org.talend.designer.xmlmap.model.emf.xmlmap.XmlMapData)36 InputXmlTree (org.talend.designer.xmlmap.model.emf.xmlmap.InputXmlTree)18 TreeNode (org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode)17 OutputXmlTree (org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree)15 ArrayList (java.util.ArrayList)14 OutputTreeNode (org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode)14 VarNode (org.talend.designer.xmlmap.model.emf.xmlmap.VarNode)8 List (java.util.List)7 EList (org.eclipse.emf.common.util.EList)6 HashMap (java.util.HashMap)5 VarTable (org.talend.designer.xmlmap.model.emf.xmlmap.VarTable)5 IConnection (org.talend.core.model.process.IConnection)4 AbstractInOutTree (org.talend.designer.xmlmap.model.emf.xmlmap.AbstractInOutTree)4 AbstractNode (org.talend.designer.xmlmap.model.emf.xmlmap.AbstractNode)3 FilterConnection (org.talend.designer.xmlmap.model.emf.xmlmap.FilterConnection)3 ComboBoxCellEditor (org.eclipse.jface.viewers.ComboBoxCellEditor)2 CCombo (org.eclipse.swt.custom.CCombo)2 Test (org.junit.Test)2 NodeType (org.talend.designer.core.model.utils.emf.talendfile.NodeType)2 MapperTable (org.talend.designer.gefabstractmap.model.abstractmap.MapperTable)2