use of org.talend.designer.xmlmap.model.emf.xmlmap.INodeConnection in project tdi-studio-se by Talend.
the class DirectEditCommand method execute.
@Override
public void execute() {
try {
if (model != null) {
if (DirectEditType.EXPRESSION.equals(type)) {
List<TableEntryLocation> matchedLocations = expressionManager.parseTableEntryLocation((String) newValue);
EList<? extends INodeConnection> connections = null;
if (model instanceof OutputTreeNode || model instanceof VarNode) {
connections = model.getIncomingConnections();
} else if (model instanceof TreeNode) {
connections = ((TreeNode) model).getLookupIncomingConnections();
}
List usefullConnections = new ArrayList();
mapperData = XmlMapUtil.getXmlMapData(model);
if (!matchedLocations.isEmpty()) {
for (int i = 0; i < matchedLocations.size(); i++) {
TableEntryLocation currentLocation = matchedLocations.get(i);
boolean found = false;
for (INodeConnection conn : connections) {
TableEntryLocation sourceLocation = null;
if (conn.getSource() instanceof TreeNode) {
sourceLocation = expressionManager.parseTableEntryLocation(XmlMapUtil.convertToExpression(((TreeNode) conn.getSource()).getXpath())).get(0);
} else if (conn.getSource() instanceof VarNode) {
VarNode varNode = (VarNode) conn.getSource();
sourceLocation = new TableEntryLocation(((VarTable) varNode.eContainer()).getName(), varNode.getName());
}
if (currentLocation.equals(sourceLocation)) {
found = true;
usefullConnections.add(conn);
break;
}
}
if (!found) {
if (mapperData != null) {
String convertToXpath = XmlMapUtil.convertToXpath(currentLocation.toString());
boolean findFromVar = false;
if (model instanceof OutputTreeNode) {
findFromVar = true;
}
AbstractNode sourceNode = findConnectionSource(mapperData, currentLocation, XmlMapUtil.getXPathLength(convertToXpath), findFromVar);
if (sourceNode != null) {
INodeConnection connection = null;
if (model instanceof OutputTreeNode || model instanceof VarNode) {
connection = XmlmapFactory.eINSTANCE.createConnection();
sourceNode.getOutgoingConnections().add((Connection) connection);
model.getIncomingConnections().add((Connection) connection);
} else if (model instanceof TreeNode && sourceNode instanceof TreeNode) {
TreeNode source = (TreeNode) sourceNode;
connection = XmlmapFactory.eINSTANCE.createLookupConnection();
source.getLookupOutgoingConnections().add((LookupConnection) connection);
((TreeNode) model).getLookupIncomingConnections().add((LookupConnection) connection);
}
//
// if (model instanceof OutputTreeNode && sourceNode instanceof TreeNode) {
// createInputLoopTable((TreeNode) sourceNode, (OutputTreeNode) model);
// }
connection.setSource(sourceNode);
connection.setTarget(model);
mapperData.getConnections().add(connection);
usefullConnections.add(connection);
}
}
}
}
} else {
if (!connections.isEmpty()) {
if (model instanceof OutputTreeNode || model instanceof VarNode) {
XmlMapUtil.detachConnectionsSouce(model, mapperData, false);
model.getIncomingConnections().clear();
} else if (model instanceof TreeNode) {
XmlMapUtil.detachLookupSource((TreeNode) model, mapperData);
((TreeNode) model).getLookupIncomingConnections().clear();
}
}
}
List<INodeConnection> copyOfConnections = new ArrayList<INodeConnection>(connections);
copyOfConnections.removeAll(usefullConnections);
if (model instanceof OutputTreeNode || model instanceof VarNode) {
for (INodeConnection connection : copyOfConnections) {
if (connection.getSource() != null) {
if (connection.getSource().getOutgoingConnections().contains(connection)) {
connection.getSource().getOutgoingConnections().remove(connection);
mapperData.getConnections().remove(connection);
}
}
}
model.getIncomingConnections().removeAll(copyOfConnections);
} else if (model instanceof TreeNode) {
for (INodeConnection connection : copyOfConnections) {
if (connection.getSource() != null) {
if (((TreeNode) connection.getSource()).getLookupOutgoingConnections().contains(connection)) {
((TreeNode) connection.getSource()).getLookupOutgoingConnections().remove(connection);
mapperData.getConnections().remove(connection);
}
}
}
((TreeNode) model).getLookupIncomingConnections().removeAll(copyOfConnections);
}
if (model instanceof OutputTreeNode) {
OutputTreeNode outModel = (OutputTreeNode) model;
if (NodeType.NAME_SPACE.equals(outModel.getNodeType()) && outModel.getExpression() != null && !"".equals(model.getExpression())) {
outModel.setDefaultValue("");
}
}
model.setExpression((String) newValue);
} else if (DirectEditType.VAR_NODE_TYPE.equals(type)) {
VarNode varModel = (VarNode) model;
JavaType javaTypeFromLabel = JavaTypesManager.getJavaTypeFromLabel((String) newValue);
if (javaTypeFromLabel == null) {
javaTypeFromLabel = JavaTypesManager.getDefaultJavaType();
}
varModel.setType(javaTypeFromLabel.getId());
} else if (DirectEditType.NODE_NAME.equals(type)) {
if (model instanceof VarNode) {
List<VarNode> children = new ArrayList<VarNode>();
children.addAll(((VarTable) model.eContainer()).getNodes());
children.remove(model);
String message = XmlMapUtil.isValidColumnName(children, (String) newValue);
if (message != null) {
MessageDialog.openError(null, "Error", message);
return;
}
String oldName = model.getName();
String oldExpression = XmlMapUtil.VAR_TABLE_NAME + XmlMapUtil.EXPRESSION_SEPARATOR + oldName;
model.setName((String) newValue);
String newExpression = XmlMapUtil.VAR_TABLE_NAME + XmlMapUtil.EXPRESSION_SEPARATOR + model.getName();
XmlMapUtil.updateTargetExpression(model, oldExpression, newExpression, expressionManager);
} else if (model instanceof GlobalMapNode) {
model.setName((String) newValue);
}
}
}
} catch (PatternSyntaxException ex) {
// Syntax error in the regular expression
}
}
use of org.talend.designer.xmlmap.model.emf.xmlmap.INodeConnection 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.INodeConnection in project tdi-studio-se by Talend.
the class XmlMapUtil method updateTargetExpression.
public static void updateTargetExpression(AbstractNode renamedNode, String oldExpression, String newExpression, XmlMapExpressionManager expressionManager) {
TableEntryLocation previousLocation = expressionManager.parseTableEntryLocation(oldExpression).get(0);
TableEntryLocation newLocation = expressionManager.parseTableEntryLocation(newExpression).get(0);
List<INodeConnection> connections = new ArrayList<INodeConnection>();
connections.addAll(renamedNode.getOutgoingConnections());
if (renamedNode instanceof TreeNode) {
connections.addAll(((TreeNode) renamedNode).getLookupOutgoingConnections());
}
for (INodeConnection connection : connections) {
AbstractNode target = connection.getTarget();
List<TableEntryLocation> targetLocaitons = expressionManager.parseTableEntryLocation(target.getExpression());
for (TableEntryLocation current : targetLocaitons) {
if (current.equals(previousLocation)) {
String replaced = expressionManager.replaceExpression(target.getExpression(), current, newLocation);
target.setExpression(replaced);
}
}
}
for (FilterConnection connection : renamedNode.getFilterOutGoingConnections()) {
AbstractInOutTree target = connection.getTarget();
List<TableEntryLocation> targetLocaitons = expressionManager.parseTableEntryLocation(target.getExpressionFilter());
for (TableEntryLocation current : targetLocaitons) {
if (current.equals(previousLocation)) {
String replaced = expressionManager.replaceExpression(target.getExpressionFilter(), current, newLocation);
target.setExpressionFilter(replaced);
}
}
}
}
Aggregations