use of org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode in project tdi-studio-se by Talend.
the class DropContextAnalyzer method checkDropOutputDocChildValid.
private boolean checkDropOutputDocChildValid(Object targetModel) {
OutputTreeNode outputNode = (OutputTreeNode) targetModel;
NodeType nodeType = outputNode.getNodeType();
if (outputNode.eContainer() instanceof OutputTreeNode && nodeType != NodeType.ATTRIBUT && nodeType != NodeType.NAME_SPACE) {
dropType = DropType.DROP_OUTPUT_DOC_CHILD;
return true;
} else if (outputNode.eContainer() instanceof OutputXmlTree && !XmlMapUtil.DOCUMENT.equals(outputNode.getType())) {
dropType = DropType.DROP_INSERT_OUTPUT;
return true;
}
return false;
}
use of org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode in project tdi-studio-se by Talend.
the class NewNodeCreationFactory method getNewObject.
public AbstractNode getNewObject() {
if (dropType != null) {
switch(dropType) {
case DROP_OUTPUT_DOC_CHILD:
OutputTreeNode outputNode = XmlmapFactory.eINSTANCE.createOutputTreeNode();
outputNode.setNodeType(nodeType);
return outputNode;
case DROP_INSERT_INPUT:
return XmlmapFactory.eINSTANCE.createTreeNode();
case DROP_INSERT_OUTPUT:
return XmlmapFactory.eINSTANCE.createOutputTreeNode();
case DROP_INSERT_VAR:
return XmlmapFactory.eINSTANCE.createVarNode();
default:
break;
}
}
return null;
}
use of org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode 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.OutputTreeNode 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.OutputTreeNode in project tdi-studio-se by Talend.
the class MapDataHelper method rebuildModelOutputs.
public void rebuildModelOutputs(List<IMetadataTable> outputMetadataTables, XmlMapData mapData) {
for (IMetadataTable meatadataTable : outputMetadataTables) {
String name = meatadataTable.getTableName();
OutputXmlTree outputTree = null;
for (OutputXmlTree out : mapData.getOutputTrees()) {
if (out.getName() != null && out.getName().equals(name)) {
outputTree = out;
break;
}
}
if (outputTree == null) {
outputTree = XmlmapFactory.eINSTANCE.createOutputXmlTree();
outputTree.setName(name);
mapData.getOutputTrees().add(outputTree);
}
List<IMetadataColumn> listColumns = meatadataTable.getListColumns();
if (listColumns != null) {
EList<OutputTreeNode> nodes = outputTree.getNodes();
for (int i = 0; i < listColumns.size(); i++) {
IMetadataColumn column = listColumns.get(i);
OutputTreeNode found = null;
int j = 0;
for (; j < nodes.size(); j++) {
OutputTreeNode 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
OutputTreeNode temp = nodes.get(j);
nodes.remove(j);
nodes.add(i, temp);
}
} else {
found = XmlmapFactory.eINSTANCE.createOutputTreeNode();
found.setName(column.getLabel());
found.setType(column.getTalendType());
found.setNullable(column.isNullable());
found.setXpath(XmlMapUtil.getXPath(outputTree.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 (children.isEmpty()) {
XmlMapUtil.detachConnectionsSouce(found, mapData);
TreeNode treeRoot = XmlmapFactory.eINSTANCE.createOutputTreeNode();
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);
found.getChildren().clear();
}
}
}
if (nodes.size() > listColumns.size()) {
List unUsed = new ArrayList();
for (int i = listColumns.size(); i < nodes.size(); i++) {
OutputTreeNode node = nodes.get(i);
XmlMapUtil.detachConnectionsSouce(node, mapData);
unUsed.add(node);
}
nodes.removeAll(unUsed);
}
}
mapData.getOutputTrees().add(outputTree);
// re-build the connections in case any unnecessary connections are created because of previous bugs and
// can't be deleted
rebuildOutputNodesConnections(outputTree.getNodes(), mapData);
}
}
Aggregations