use of org.talend.designer.xmlmap.model.emf.xmlmap.AbstractInOutTree in project tdi-studio-se by Talend.
the class UpdateFilterExpressionCommand method execute.
@Override
public void execute() {
AbstractInOutTree targetTree = (AbstractInOutTree) targetEditPart.getModel();
String expression = targetTree.getExpressionFilter();
if (objects.getToTransfer() != null) {
for (Object obj : objects.getToTransfer()) {
AbstractNode sourceNode = null;
// INPUT == FILTER
if (objects.getType() == TransferdType.INPUT) {
TreeNodeEditPart part = (TreeNodeEditPart) obj;
sourceNode = (TreeNode) part.getModel();
if (expression == null) {
expression = XmlMapUtil.convertToExpression(((TreeNode) sourceNode).getXpath());
} else {
expression = expression + " " + XmlMapUtil.convertToExpression(((TreeNode) sourceNode).getXpath());
}
} else // VARE == FILTER
if (objects.getType() == TransferdType.VAR) {
String tableName = "Var";
VarNodeEditPart part = (VarNodeEditPart) obj;
sourceNode = (VarNode) part.getModel();
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 != null) {
targetTree.setExpressionFilter(expression);
FilterConnection connection = XmlmapFactory.eINSTANCE.createFilterConnection();
connection.setSource(sourceNode);
connection.setTarget(targetTree);
targetTree.getFilterIncomingConnections().add(connection);
sourceNode.getFilterOutGoingConnections().add(connection);
xmlMapData.getConnections().add(connection);
}
// check if need update outputTree InputLoopNodesTable
}
}
}
use of org.talend.designer.xmlmap.model.emf.xmlmap.AbstractInOutTree in project tdi-studio-se by Talend.
the class DeleteTreeNodeAction method run.
@Override
public void run() {
try {
TreeNode docRoot = null;
Object s = getSelectedObjects().get(0);
if (s instanceof List && !((List) s).isEmpty()) {
List selectedarts = new ArrayList((List) s);
Iterator iter = selectedarts.iterator();
while (iter.hasNext()) {
Object obj = iter.next();
if (obj instanceof TreeNodeEditPart) {
TreeNodeEditPart nodePart = (TreeNodeEditPart) obj;
TreeNode treeNode = (TreeNode) nodePart.getModel();
if (treeNode.eContainer() instanceof TreeNode) {
TreeNode parent = (TreeNode) treeNode.eContainer();
if (docRoot == null) {
docRoot = XmlMapUtil.getTreeNodeRoot(parent);
}
XmlMapUtil.detachNodeConnections(treeNode, mapperManager.getExternalData(), true);
// if delete loop , clean group and main
if (treeNode.isLoop()) {
if (treeNode instanceof OutputTreeNode && XmlMapUtil.findUpGroupNode((OutputTreeNode) treeNode) != null) {
XmlMapUtil.cleanSubGroup(docRoot);
}
XmlMapUtil.clearMainNode(docRoot);
}
parent.getChildren().remove(treeNode);
// check if tree is multiloop
if (docRoot != null && docRoot.eContainer() instanceof AbstractInOutTree) {
AbstractInOutTree tree = (AbstractInOutTree) docRoot.eContainer();
tree.setMultiLoops(XmlMapUtil.checkMultiLoopsStatus(tree));
}
if (input) {
// remove delete loops in InputLoopTable for outputs
List<TreeNode> subNodes = new ArrayList<TreeNode>();
checkSubElementIsLoop(treeNode, subNodes);
XmlMapUtil.removeloopInOutputTree(mapperManager, subNodes);
}
}
}
}
}
if (mapperManager != null) {
mapperManager.beanListModified(input);
// }
if (docRoot != null && docRoot.eContainer() instanceof AbstractInOutTree) {
mapperManager.getProblemsAnalyser().checkProblems((AbstractInOutTree) docRoot.eContainer());
mapperManager.getMapperUI().updateStatusBar();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
use of org.talend.designer.xmlmap.model.emf.xmlmap.AbstractInOutTree in project tdi-studio-se by Talend.
the class ImportTreeFromXml method calculateEnabled.
@Override
protected boolean calculateEnabled() {
if (getSelectedObjects().isEmpty()) {
return false;
} else {
// get the last selection to run the action
Object s = getSelectedObjects().get(0);
if (s instanceof List && !((List) s).isEmpty()) {
List selectedarts = (List) s;
Object object = selectedarts.get(selectedarts.size() - 1);
if (object instanceof TreeNodeEditPart) {
TreeNodeEditPart parentPart = (TreeNodeEditPart) object;
parentNode = (TreeNode) parentPart.getModel();
if (parentNode.eContainer() instanceof AbstractInOutTree && XmlMapUtil.DOCUMENT.equals(parentNode.getType())) {
return true;
}
}
}
}
return false;
}
use of org.talend.designer.xmlmap.model.emf.xmlmap.AbstractInOutTree in project tdi-studio-se by Talend.
the class XmlMapConnectionBuilder method hasMaptchedLocation.
private boolean hasMaptchedLocation(XmlMapExpressionManager expressionManager, TableEntryLocation sourceLocation, EObject targetNodeOrTree, ExpressionType type) {
String targetExpression = null;
AbstractNode targetNode = null;
AbstractInOutTree targetTree = null;
switch(type) {
case EXPRESSION:
targetNode = (AbstractNode) targetNodeOrTree;
targetExpression = targetNode.getExpression();
break;
case EXPRESSION_FILTER:
targetTree = (AbstractInOutTree) targetNodeOrTree;
targetExpression = targetTree.getExpressionFilter();
default:
break;
}
if (!"".equals(targetExpression) && targetExpression != null) {
List<TableEntryLocation> targetLocations = expressionManager.parseTableEntryLocation(targetExpression);
for (TableEntryLocation target : targetLocations) {
if (sourceLocation.equals(target)) {
return true;
} else if (checkRootNodePrefix && !cancelForAll) {
StringBuffer bf = new StringBuffer();
String prefix = null;
String nodeName = null;
final String[] split = sourceLocation.toString().split("/");
if (split.length > 2) {
for (int i = 0; i < split.length; i++) {
String value = split[i];
if (i == 1) {
int indexOf = split[1].indexOf(":");
if (indexOf != -1) {
prefix = split[1].substring(0, indexOf);
nodeName = split[1].substring(indexOf + 1, split[1].length());
value = nodeName;
} else {
break;
}
}
bf.append(value);
if (i < split.length - 1) {
bf.append("/");
}
}
}
if (bf.toString().equals(targetExpression)) {
if (applyForAll) {
// reset the target expression with prefix
if (targetNode != null) {
targetNode.setExpression(expressionManager.replaceExpression(targetExpression, target, sourceLocation));
}
if (targetTree != null) {
targetTree.setExpressionFilter(expressionManager.replaceExpression(targetExpression, target, sourceLocation));
}
return true;
} else {
PrefixChangeDialog dialog = new PrefixChangeDialog(new Shell());
dialog.setPrefix(prefix);
dialog.setRootNodeName(nodeName);
dialog.setSourceExpression(sourceLocation.toString());
dialog.setTargetExpression(target.toString());
if (dialog.open() == Window.OK) {
applyForAll = dialog.isApplyAll();
cancelForAll = dialog.isCancelAll();
if (cancelForAll) {
return false;
}
// reset the target expression with prefix
if (targetNode != null) {
targetNode.setExpression(expressionManager.replaceExpression(targetExpression, target, sourceLocation));
}
if (targetTree != null) {
targetTree.setExpressionFilter(expressionManager.replaceExpression(targetExpression, target, sourceLocation));
}
return true;
}
}
}
}
}
}
return false;
}
use of org.talend.designer.xmlmap.model.emf.xmlmap.AbstractInOutTree in project tdi-studio-se by Talend.
the class XmlMapConnectionBuilder method rebuildLinks.
public void rebuildLinks(TreeNode docNode, XmlMapData mapData) {
if (docNode == null || mapData == null) {
return;
}
AbstractInOutTree inputTree = XmlMapUtil.getAbstractInOutTree(docNode);
int index = mapData.getInputTrees().indexOf(inputTree);
if (index == -1) {
index = mapData.getInputTrees().size();
}
List<TreeNode> nodes = new ArrayList<TreeNode>();
nodes.add(docNode);
rebuildLink(index, nodes, mapData);
}
Aggregations