use of org.talend.designer.xmlmap.util.XmlMapConnectionBuilder in project tdi-studio-se by Talend.
the class ImportTreeFromRepository method run.
@Override
public void run() {
targetAbsolutePath = null;
loopNode = null;
xpathAndOrder.clear();
RepositoryXmlSelectionDialog reviewDialog = new RepositoryXmlSelectionDialog(shell, new String[] { "XML", "MDM" });
if (reviewDialog.open() == Window.OK) {
TreeNode treeNodeRoot = XmlMapUtil.getTreeNodeRoot(schemaNode);
XmlMapUtil.detachNodeConnections(treeNodeRoot, mapperManager.getExternalData(), true);
RepositoryNode repositoryNode = reviewDialog.getResult();
Item item = repositoryNode.getObject().getProperty().getItem();
String detailedMessage = "";
try {
if (item instanceof XmlFileConnectionItem) {
XmlFileConnectionItem xmlitem = (XmlFileConnectionItem) item;
XmlFileConnection connection = (XmlFileConnection) xmlitem.getConnection();
prepareEmfTreeFromXml(connection);
} else if (item instanceof MDMConnectionItem) {
String selectedSchema = (String) repositoryNode.getProperties(EProperties.LABEL);
MDMConnection connection = (MDMConnection) ((MDMConnectionItem) item).getConnection();
prepareEmfTreeFromMdm(connection, selectedSchema);
}
} catch (Exception e) {
ExceptionHandler.process(e);
StringBuffer sb = new StringBuffer();
sb.append(e.toString());
sb.append("\n");
if (e.getStackTrace() != null) {
for (StackTraceElement trace : e.getStackTrace()) {
sb.append(trace.toString());
sb.append("\n");
}
}
detailedMessage = sb.toString();
}
boolean childrenEmpty = false;
if (schemaNode.getChildren().isEmpty()) {
childrenEmpty = true;
TreeNode rootNode = createModel();
rootNode.setName("root");
rootNode.setNodeType(NodeType.ELEMENT);
rootNode.setType(XmlMapUtil.DEFAULT_DATA_TYPE);
rootNode.setXpath(XmlMapUtil.getXPath(schemaNode.getXpath(), "root", NodeType.ELEMENT));
schemaNode.getChildren().add(rootNode);
if (loopNode == null) {
schemaNode.getChildren().get(0).setLoop(true);
schemaNode.getChildren().get(0).setMain(true);
}
}
if (childrenEmpty || (detailedMessage != null && !"".equals(detailedMessage))) {
showError(detailedMessage);
}
AbstractInOutTree tree = null;
if (schemaNode.eContainer() instanceof InputXmlTree) {
XmlMapConnectionBuilder connectionBuilder = new XmlMapConnectionBuilder();
connectionBuilder.setCheckRootNodePrefix(true);
connectionBuilder.rebuildLinks(schemaNode, mapperManager.getExternalData());
mapperManager.refreshTreeSchemaEditor((InputXmlTree) schemaNode.eContainer());
// mapperManager.inputTreeSchemaBeanListModified();
tree = (InputXmlTree) schemaNode.eContainer();
} else if (schemaNode.eContainer() instanceof OutputXmlTree) {
// mapperManager.outputTreeSchemaBeanListModified();
mapperManager.refreshTreeSchemaEditor((OutputXmlTree) schemaNode.eContainer());
tree = (OutputXmlTree) schemaNode.eContainer();
}
if (tree != null) {
mapperManager.getProblemsAnalyser().checkProblems(tree);
mapperManager.getMapperUI().updateStatusBar();
}
}
}
use of org.talend.designer.xmlmap.util.XmlMapConnectionBuilder 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.util.XmlMapConnectionBuilder in project tdi-studio-se by Talend.
the class ImportTreeFromXml method run.
@Override
public void run() {
List<FOXTreeNode> list = new ArrayList<FOXTreeNode>();
FileDialog f = new FileDialog(shell);
String file = f.open();
if (file != null) {
boolean clickOk = false;
TreeNode treeNodeRoot = null;
String detailedMessage = "";
try {
clickOk = TreeUtil.getFoxTreeNodesForXmlMap(file, shell, list);
if (!clickOk) {
return;
}
treeNodeRoot = XmlMapUtil.getTreeNodeRoot(parentNode);
XmlMapUtil.detachNodeConnections(treeNodeRoot, mapperManager.getExternalData(), true);
parentNode.getChildren().clear();
prepareEmfTreeNode(list, parentNode);
} catch (Exception e) {
ExceptionHandler.process(e);
StringBuffer sb = new StringBuffer();
sb.append(e.toString());
sb.append("\n");
if (e.getStackTrace() != null) {
for (StackTraceElement trace : e.getStackTrace()) {
sb.append(trace.toString());
sb.append("\n");
}
}
detailedMessage = sb.toString();
}
boolean childrenEmpty = false;
if (parentNode.getChildren().isEmpty()) {
childrenEmpty = true;
TreeNode rootNode = null;
if (input) {
rootNode = XmlmapFactory.eINSTANCE.createTreeNode();
} else {
rootNode = XmlmapFactory.eINSTANCE.createOutputTreeNode();
}
rootNode.setName("root");
rootNode.setNodeType(NodeType.ELEMENT);
rootNode.setType(XmlMapUtil.DEFAULT_DATA_TYPE);
rootNode.setXpath(XmlMapUtil.getXPath(parentNode.getXpath(), "root", NodeType.ELEMENT));
parentNode.getChildren().add(rootNode);
}
// set a default loop
parentNode.getChildren().get(0).setLoop(true);
parentNode.getChildren().get(0).setMain(true);
if (childrenEmpty || (detailedMessage != null && !"".equals(detailedMessage))) {
showError(detailedMessage);
}
if (parentNode.eContainer() instanceof InputXmlTree) {
XmlMapConnectionBuilder connectionBuilder = new XmlMapConnectionBuilder();
connectionBuilder.setCheckRootNodePrefix(true);
connectionBuilder.rebuildLinks(parentNode, mapperManager.getExternalData());
mapperManager.refreshTreeSchemaEditor((InputXmlTree) parentNode.eContainer());
// mapperManager.inputTreeSchemaBeanListModified();
} else if (parentNode.eContainer() instanceof OutputXmlTree) {
mapperManager.refreshTreeSchemaEditor((OutputXmlTree) parentNode.eContainer());
// mapperManager.outputTreeSchemaBeanListModified();
}
if (treeNodeRoot != null && treeNodeRoot.eContainer() instanceof AbstractInOutTree) {
mapperManager.getProblemsAnalyser().checkProblems((AbstractInOutTree) treeNodeRoot.eContainer());
mapperManager.getMapperUI().updateStatusBar();
}
}
}
Aggregations