use of org.talend.designer.xmlmap.model.emf.xmlmap.Connection in project tdi-studio-se by Talend.
the class AutoMapper method map.
/**
* DOC amaumont Comment method "map".
*/
public void map() {
EList<InputXmlTree> inputTrees = xmlMapData.getInputTrees();
EList<OutputXmlTree> outputTrees = xmlMapData.getOutputTrees();
/*
* non-document node , if name is the same ,automap document node , check xpath first , if can't find ,check the
* name
*/
for (OutputXmlTree outputTree : outputTrees) {
List<TreeNode> outputEntries = getAllEntities(outputTree);
for (TreeNode outputEntry : outputEntries) {
if ((outputEntry.getExpression() == null || "".equals(outputEntry.getExpression())) && XmlMapUtil.isExpressionEditable(outputEntry)) {
String xpath = outputEntry.getXpath();
String outputNodePath = xpath.substring(outputTree.getName().length() + 1, xpath.length());
TreeNode inputSameXpath = null;
TreeNode inputSameName = null;
out: for (InputXmlTree inputTable : inputTrees) {
List<TreeNode> inputColumnEntries = getAllEntities(inputTable);
in: for (TreeNode inputEntry : inputColumnEntries) {
// check if input tree node can be mapped
if (XmlMapUtil.isExpressionEditable(inputEntry)) {
String inputXpath = inputEntry.getXpath();
String inputNodePath = inputXpath.substring(inputTable.getName().length() + 1, inputXpath.length());
if (outputNodePath.equals(inputNodePath)) {
inputSameXpath = inputEntry;
break out;
}
// if the same name , find the first matched node , don't overwrite
if (inputSameName == null && outputEntry.getName() != null && outputEntry.getName().equals(inputEntry.getName())) {
inputSameName = inputEntry;
}
}
}
}
TreeNode inputEntryToMap = null;
if (inputSameXpath != null) {
inputEntryToMap = inputSameXpath;
} else if (inputSameName != null) {
inputEntryToMap = inputSameName;
}
if (inputEntryToMap != null) {
String expression = outputEntry.getExpression();
String convertToExpression = XmlMapUtil.convertToExpression(inputEntryToMap.getXpath());
if (expression != null && expression.indexOf(convertToExpression) != -1) {
continue;
} else {
if (expression == null) {
expression = "";
}
expression = expression + convertToExpression;
}
outputEntry.setExpression(expression);
Connection conn = XmlmapFactory.eINSTANCE.createConnection();
conn.setSource(inputEntryToMap);
conn.setTarget(outputEntry);
outputEntry.getIncomingConnections().add(conn);
inputEntryToMap.getOutgoingConnections().add(conn);
xmlMapData.getConnections().add(conn);
}
}
}
}
}
use of org.talend.designer.xmlmap.model.emf.xmlmap.Connection in project tdi-studio-se by Talend.
the class XmlMapService method externalEmfDataClone.
/*
* (non-Javadoc)
*
* @see
* org.talend.core.service.IXmlMapService#externalEmfDataClone(org.talend.designer.core.model.utils.emf.talendfile
* .AbstractExternalData)
*/
@Override
public AbstractExternalData externalEmfDataClone(AbstractExternalData externalEmfData) {
if (!(externalEmfData instanceof XmlMapData)) {
return externalEmfData;
}
Map<EObject, EObject> nodeMaps = new HashMap<EObject, EObject>();
XmlMapData newXmlMapData = XmlmapFactory.eINSTANCE.createXmlMapData();
XmlMapData xmlMapData = (XmlMapData) externalEmfData;
EList<InputXmlTree> oriInputs = xmlMapData.getInputTrees();
EList<OutputXmlTree> oriOutputs = xmlMapData.getOutputTrees();
EList<VarTable> oriVars = xmlMapData.getVarTables();
EList<IConnection> oriConns = xmlMapData.getConnections();
for (IConnection oriConn : oriConns) {
if (oriConn instanceof INodeConnection) {
AbstractNode sourceNode = ((INodeConnection) oriConn).getSource();
AbstractNode targetNode = ((INodeConnection) oriConn).getTarget();
EObject source = null;
if (nodeMaps.get(sourceNode) != null) {
source = nodeMaps.get(sourceNode);
} else {
source = cloneTreeNode(sourceNode);
nodeMaps.put(sourceNode, source);
}
EObject target = null;
if (nodeMaps.get(targetNode) != null) {
target = nodeMaps.get(targetNode);
} else {
target = cloneTreeNode(targetNode);
nodeMaps.put(targetNode, target);
}
if (oriConn instanceof Connection) {
new XmlMapConnectionBuilder().createConnection((AbstractNode) source, (AbstractNode) target, newXmlMapData);
} else if (oriConn instanceof LookupConnection) {
new XmlMapConnectionBuilder().createLookupConnection((TreeNode) source, (TreeNode) target, newXmlMapData);
}
} else if (oriConn instanceof FilterConnection) {
AbstractNode sourceNode = ((FilterConnection) oriConn).getSource();
AbstractInOutTree targetNode = ((FilterConnection) oriConn).getTarget();
EObject source = null;
if (nodeMaps.get(sourceNode) != null) {
source = nodeMaps.get(sourceNode);
} else {
source = cloneTreeNode(sourceNode);
nodeMaps.put(sourceNode, source);
}
EObject target = null;
if (nodeMaps.get(targetNode) != null) {
target = nodeMaps.get(targetNode);
} else {
target = cloneTreeNode(targetNode);
nodeMaps.put(targetNode, target);
}
new XmlMapConnectionBuilder().createFilterConnection((AbstractNode) source, (AbstractInOutTree) target, newXmlMapData);
}
}
for (InputXmlTree inputXml : oriInputs) {
InputXmlTree newInputXml = null;
if (nodeMaps.get(inputXml) == null) {
newInputXml = (InputXmlTree) cloneTreeNode(inputXml);
} else {
newInputXml = (InputXmlTree) nodeMaps.get(inputXml);
}
if (inputXml.getNodes() != null) {
for (TreeNode treeNode : inputXml.getNodes()) {
EObject obj = nodeMaps.get(treeNode);
if ((obj != null) && !newInputXml.getNodes().contains(obj)) {
newInputXml.getNodes().add((TreeNode) obj);
}
}
}
if (!newXmlMapData.getInputTrees().contains(newInputXml)) {
newXmlMapData.getInputTrees().add(newInputXml);
}
nodeMaps.put(inputXml, newInputXml);
}
for (OutputXmlTree outputXml : oriOutputs) {
OutputXmlTree newOutputXml = null;
if (nodeMaps.get(outputXml) == null) {
newOutputXml = (OutputXmlTree) cloneTreeNode(outputXml);
} else {
newOutputXml = (OutputXmlTree) nodeMaps.get(outputXml);
}
if (outputXml.getNodes() != null) {
for (OutputTreeNode treeNode : outputXml.getNodes()) {
EObject obj = nodeMaps.get(treeNode);
if ((obj != null) && !newOutputXml.getNodes().contains(obj)) {
newOutputXml.getNodes().add((OutputTreeNode) obj);
}
}
}
// }
if (!newXmlMapData.getOutputTrees().contains(newOutputXml)) {
newXmlMapData.getOutputTrees().add(newOutputXml);
}
nodeMaps.put(outputXml, newOutputXml);
}
for (VarTable varXml : oriVars) {
VarTable newVarXml = null;
if (nodeMaps.get(varXml) == null) {
newVarXml = XmlmapFactory.eINSTANCE.createVarTable();
newVarXml.setMinimized(varXml.isMinimized());
newVarXml.setName(varXml.getName());
if (varXml.getNodes() != null) {
for (VarNode treeNode : varXml.getNodes()) {
EObject obj = nodeMaps.get(treeNode);
if (obj != null) {
newVarXml.getNodes().add((VarNode) obj);
}
}
}
if (!newXmlMapData.getVarTables().contains(newVarXml)) {
newXmlMapData.getVarTables().add(newVarXml);
}
nodeMaps.put(varXml, newVarXml);
}
}
return newXmlMapData;
}
use of org.talend.designer.xmlmap.model.emf.xmlmap.Connection 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);
}
}
}
}
use of org.talend.designer.xmlmap.model.emf.xmlmap.Connection 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);
}
}
use of org.talend.designer.xmlmap.model.emf.xmlmap.Connection in project tdi-studio-se by Talend.
the class XmlMapUtil method detachConnectionsTarget.
public static void detachConnectionsTarget(AbstractNode treeNode, XmlMapData mapData, boolean detachChildren) {
for (Connection connection : treeNode.getOutgoingConnections()) {
AbstractNode target = connection.getTarget();
if (target.getIncomingConnections().contains(connection)) {
target.getIncomingConnections().remove(connection);
mapData.getConnections().remove(connection);
}
}
treeNode.getOutgoingConnections().clear();
// TreeNode detach children's connections
if (treeNode instanceof TreeNode) {
TreeNode inputTreeNode = (TreeNode) treeNode;
if (detachChildren && !inputTreeNode.getChildren().isEmpty()) {
for (int i = 0; i < inputTreeNode.getChildren().size(); i++) {
TreeNode child = inputTreeNode.getChildren().get(i);
detachConnectionsTarget(child, mapData);
}
}
}
}
Aggregations