use of org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode in project tdi-studio-se by Talend.
the class XmlMapUtil method isExpressionEditable.
public static boolean isExpressionEditable(TreeNode treeNode) {
List children = treeNode.getChildren();
if (treeNode.isChoice() || treeNode.isSubstitution()) {
return false;
}
boolean haschild = false;
boolean isNameSpace = false;
if (children.size() > 0) {
for (int i = 0; i < children.size(); i++) {
TreeNode child = (TreeNode) children.get(i);
// attribute and namespace are not treat as subnode , so the expression of treeNode should be editable.
if (NodeType.ATTRIBUT != child.getNodeType() && NodeType.NAME_SPACE != child.getNodeType()) {
haschild = true;
break;
}
}
} else if (NodeType.NAME_SPACE.equals(treeNode.getNodeType())) {
isNameSpace = true;
}
return !haschild && !isNameSpace;
}
use of org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode in project tdi-studio-se by Talend.
the class XmlMapUtil method getParentLoopNodeEditPart.
public static OutputTreeNodeEditPart getParentLoopNodeEditPart(OutputTreeNodeEditPart nodePart) {
if (nodePart != null && nodePart instanceof OutputTreeNodeEditPart) {
OutputTreeNodeEditPart nodePartTemp = nodePart;
TreeNode model = (TreeNode) nodePartTemp.getModel();
if (model.isLoop()) {
return nodePartTemp;
} else {
if (nodePartTemp.getParent() != null && nodePartTemp.getParent() instanceof OutputTreeNodeEditPart) {
return getParentLoopNodeEditPart((OutputTreeNodeEditPart) nodePartTemp.getParent());
}
}
}
return null;
}
use of org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode in project tdi-studio-se by Talend.
the class MapDataHelper method rebuildInputTree.
public void rebuildInputTree(InputXmlTree inputTree, IMetadataTable metadataTable, XmlMapData mapData) {
if (metadataTable != null && metadataTable.getListColumns() != null) {
List<IMetadataColumn> listColumns = metadataTable.getListColumns();
EList<TreeNode> nodes = inputTree.getNodes();
for (int i = 0; i < listColumns.size(); i++) {
IMetadataColumn column = listColumns.get(i);
TreeNode found = null;
int j = 0;
for (; j < nodes.size(); j++) {
TreeNode node = nodes.get(j);
if (node.getName() != null && node.getName().equals(column.getLabel())) {
found = node;
break;
}
}
if (found != null) {
// set in case talend type changed in metadata
found.setType(column.getTalendType());
if (i != j) {
// do switch to keep the same sequence
TreeNode temp = nodes.get(j);
nodes.remove(j);
nodes.add(i, temp);
}
} else {
found = XmlmapFactory.eINSTANCE.createTreeNode();
found.setName(column.getLabel());
found.setType(column.getTalendType());
found.setNullable(column.isNullable());
found.setXpath(XmlMapUtil.getXPath(inputTree.getName(), found.getName(), found.getNodeType()));
nodes.add(i, found);
}
// add a default root for document
if (XmlMapUtil.DOCUMENT.equals(found.getType())) {
EList<TreeNode> children = found.getChildren();
// if type is changed from a non-document to document
if (children.isEmpty()) {
XmlMapUtil.detachNodeConnections(found, mapData, true);
TreeNode treeRoot = XmlmapFactory.eINSTANCE.createTreeNode();
treeRoot.setName("root");
treeRoot.setType(XmlMapUtil.DEFAULT_DATA_TYPE);
treeRoot.setNodeType(NodeType.ELEMENT);
treeRoot.setXpath(XmlMapUtil.getXPath(found.getXpath(), treeRoot.getName(), treeRoot.getNodeType()));
treeRoot.setLoop(true);
treeRoot.setMain(true);
children.add(treeRoot);
}
} else // remove children and connections for children if not document
{
EList<TreeNode> children = found.getChildren();
if (!children.isEmpty()) {
XmlMapUtil.detachNodeConnections(found, mapData, true);
List<TreeNode> copyOfChildren = new ArrayList<TreeNode>(found.getChildren());
found.getChildren().clear();
if (!inputTree.isLookup() && inputTree.isMultiLoops()) {
List<TreeNode> oldLoops = new ArrayList<TreeNode>();
XmlMapUtil.getChildLoops(oldLoops, copyOfChildren);
inputTree.setMultiLoops(XmlMapUtil.checkMultiLoopsStatus(inputTree));
XmlMapUtil.removeloopInOutputTree(mapData, inputTree, oldLoops);
}
}
}
}
if (nodes.size() > listColumns.size()) {
List unUsed = new ArrayList();
for (int i = listColumns.size(); i < nodes.size(); i++) {
XmlMapUtil.detachNodeConnections(nodes.get(i), mapData, true);
unUsed.add(nodes.get(i));
}
nodes.removeAll(unUsed);
}
}
// be deleted
if (inputTree.isLookup()) {
rebuildInputNodesConnections(inputTree.getNodes(), mapData);
}
}
use of org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode 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;
}
use of org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode in project tdi-studio-se by Talend.
the class XmlMapUtil method detachConnectionsSouce.
public static void detachConnectionsSouce(AbstractNode treeNode, XmlMapData mapData, boolean detachChildren) {
for (Connection connection : treeNode.getIncomingConnections()) {
AbstractNode source = connection.getSource();
if (source.getOutgoingConnections().contains(connection)) {
source.getOutgoingConnections().remove(connection);
mapData.getConnections().remove(connection);
}
}
treeNode.getIncomingConnections().clear();
if (treeNode instanceof OutputTreeNode) {
OutputTreeNode outputTreeNode = (OutputTreeNode) treeNode;
if (!XmlMapUtil.isExpressionEditable(outputTreeNode) && outputTreeNode.isAggregate()) {
outputTreeNode.setAggregate(false);
}
if (detachChildren && !outputTreeNode.getChildren().isEmpty()) {
for (int i = 0; i < outputTreeNode.getChildren().size(); i++) {
TreeNode child = outputTreeNode.getChildren().get(i);
detachConnectionsSouce(child, mapData);
}
}
}
treeNode.setExpression("");
}
Aggregations