use of org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode in project tdi-studio-se by Talend.
the class SetLoopAction method run.
@Override
public void run() {
TreeNode model = (TreeNode) nodePart.getModel();
TreeNode docRoot = XmlMapUtil.getTreeNodeRoot(model);
AbstractInOutTree abstractTree = (AbstractInOutTree) docRoot.eContainer();
boolean isLookup = abstractTree != mapperManager.getMainInputTree() && !(abstractTree instanceof OutputXmlTree);
// remove old group
if (model instanceof OutputTreeNode) {
OutputTreeNode outputNode = (OutputTreeNode) model;
if (docRoot != null) {
XmlMapUtil.cleanSubGroup(outputNode);
List<TreeNode> newLoopUpGroups = new ArrayList<TreeNode>();
findUpGroupNode(newLoopUpGroups, outputNode);
// clean all groups except the ancestor of new loop
XmlMapUtil.cleanSubGroup(docRoot, newLoopUpGroups);
// reset the group in case some element ancestor of loop element are not group but under the group
if (!newLoopUpGroups.isEmpty()) {
TreeNode rootGroup = newLoopUpGroups.get(newLoopUpGroups.size() - 1);
upsetGroup(outputNode, rootGroup);
}
}
}
if (!isLookup) {
// TDI-20147
List<TreeNode> loopNodes = new ArrayList<TreeNode>();
checkSubElementIsLoop(model, loopNodes);
checkParentElementIsLoop(model, loopNodes);
if (!loopNodes.isEmpty()) {
if (MessageDialog.openConfirm(Display.getDefault().getActiveShell(), Messages.getString("SetLoopAction.cleanSubLoopTitle"), Messages.getString("SetLoopAction.cleanSubLoopMessages"))) {
} else {
return;
}
}
for (TreeNode treeNode : loopNodes) {
treeNode.setLoop(false);
}
model.setLoop(true);
XmlMapUtil.clearMainNode(model);
XmlMapUtil.upsetMainNode(model);
abstractTree.setMultiLoops(XmlMapUtil.checkMultiLoopsStatus(abstractTree));
if (input) {
// check if child is mapped to output remove the old loop in output node
XmlMapUtil.removeloopInOutputTree(mapperManager, loopNodes);
// disable the function to add sourceloop into InputLoopNodesTable automatically
// add input loopNodes to InputLoopNodesTable
// addInputLoopNodesToOutput(model, model);
} else {
// clean the InputLoopNodesTable for the old loops
InputXmlTree mainInput = mapperManager.getMainInputTree();
XmlMapUtil.removeLoopTableForOutput((OutputXmlTree) abstractTree, loopNodes, mainInput == null ? false : mainInput.isMultiLoops());
}
} else {
if (docRoot != null) {
cleanSubLoop(docRoot);
}
model.setLoop(true);
XmlMapUtil.clearMainNode(docRoot);
XmlMapUtil.upsetMainNode(model);
}
if (abstractTree != null) {
mapperManager.getProblemsAnalyser().checkProblems(abstractTree);
mapperManager.getMapperUI().updateStatusBar();
}
}
use of org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode in project tdi-studio-se by Talend.
the class SetAggregateAction method calculateEnabled.
/*
* (non-Javadoc)
*
* @see org.eclipse.gef.ui.actions.WorkbenchPartAction#calculateEnabled()
*/
@Override
protected boolean calculateEnabled() {
if (getSelectedObjects().isEmpty()) {
return false;
}
Object s = getSelectedObjects().get(0);
if (s instanceof List && !((List) s).isEmpty()) {
List selectedarts = (List) s;
Object obj = selectedarts.get(selectedarts.size() - 1);
if (obj instanceof OutputTreeNodeEditPart) {
nodePart = (OutputTreeNodeEditPart) obj;
OutputTreeNode model = (OutputTreeNode) nodePart.getModel();
// root can't be aggregate
if (NodeType.NAME_SPACE.equals(model.getNodeType()) || !(model.eContainer() instanceof OutputTreeNode) || model.isChoice() || model.isSubstitution()) {
return false;
}
if (!XmlMapUtil.isExpressionEditable(model)) {
return false;
}
boolean isInputMultiLoops = false;
if (mapperManager.getMainInputTree() != null && mapperManager.getMainInputTree().isMultiLoops()) {
isInputMultiLoops = true;
}
AbstractInOutTree abstractTree = XmlMapUtil.getAbstractInOutTree(model);
if (abstractTree instanceof OutputXmlTree) {
OutputXmlTree outputTree = ((OutputXmlTree) abstractTree);
if (outputTree.isAllInOne()) {
return false;
}
// fixed for TDI-20808 ,disable group and aggregate for 501
if (isInputMultiLoops && outputTree.isMultiLoops()) {
return false;
}
}
if (!model.isAggregate()) {
setText("As aggregate element");
} else {
setText("Remove aggregate element");
}
} else {
return false;
}
}
return true;
}
use of org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode in project tdi-studio-se by Talend.
the class SetGroupAction method run.
@Override
public void run() {
OutputTreeNode model = (OutputTreeNode) nodePart.getModel();
OutputTreeNode outputDocumentRoot = (OutputTreeNode) XmlMapUtil.getTreeNodeRoot(model);
if (outputDocumentRoot != null) {
XmlMapUtil.cleanSubGroup(outputDocumentRoot);
}
if (!isRemove) {
model.setGroup(true);
if (!subGroupTraceNames.isEmpty()) {
for (TreeNode groupNode : subGroupTraceNames) {
if (groupNode.isChoice() || groupNode.isSubstitution()) {
groupNode.setGroup(false);
} else {
groupNode.setGroup(true);
}
}
}
} else {
model.setGroup(false);
if (!subGroupTraceNames.isEmpty()) {
for (TreeNode groupNode : subGroupTraceNames) {
groupNode.setGroup(false);
}
}
}
}
use of org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode in project tdi-studio-se by Talend.
the class SetGroupAction method calculateEnabled.
@Override
protected boolean calculateEnabled() {
subGroupTraceNames.clear();
if (getSelectedObjects().isEmpty()) {
return false;
}
Object s = getSelectedObjects().get(0);
if (s instanceof List && !((List) s).isEmpty()) {
List selectedarts = (List) s;
Object obj = selectedarts.get(selectedarts.size() - 1);
if (obj instanceof OutputTreeNodeEditPart) {
nodePart = (OutputTreeNodeEditPart) obj;
OutputTreeNode model = (OutputTreeNode) nodePart.getModel();
if (model.eContainer() instanceof TreeNode && XmlMapUtil.DOCUMENT.equals(((TreeNode) model.eContainer()).getType())) {
return false;
}
if (NodeType.ATTRIBUT.equals(model.getNodeType()) || NodeType.NAME_SPACE.equals(model.getNodeType()) || !(model.eContainer() instanceof TreeNode) || model.isChoice() || model.isSubstitution()) {
//$NON-NLS-N$
return false;
}
// fixed for TDI-20808 ,disable group and aggregate for 501
AbstractInOutTree abstractTree = XmlMapUtil.getAbstractInOutTree(model);
if (abstractTree instanceof OutputXmlTree) {
OutputXmlTree outputTree = ((OutputXmlTree) abstractTree);
if (outputTree.isMultiLoops()) {
return false;
}
}
OutputTreeNode findDownLoopNode = findDownLoopNode(model);
if (findDownLoopNode == null) {
return false;
}
if (!model.isGroup()) {
setText("As group element");
isRemove = false;
} else {
setText("Remove group element");
isRemove = true;
}
if (isRemove) {
if (model.isGroup()) {
return true;
} else {
return false;
}
}
} else {
return false;
}
}
return true;
}
use of org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode in project tdi-studio-se by Talend.
the class CreateDocChildrenCommand method execute.
@Override
public void execute() {
// only drop output can create a new node now
OutputTreeNode targetOutputNode = (OutputTreeNode) targetEditPart.getModel();
String expression = "";
if (objects.getToTransfer() != null) {
for (Object obj : objects.getToTransfer()) {
OutputTreeNode createdNode = (OutputTreeNode) rq.getNewObject();
AbstractNode source = null;
if (objects.getType() == TransferdType.INPUT) {
TreeNodeEditPart part = (TreeNodeEditPart) obj;
TreeNode sourceNode = (TreeNode) part.getModel();
source = sourceNode;
createdNode.setName(sourceNode.getName());
createdNode.setType(sourceNode.getType());
createdNode.setPattern(sourceNode.getPattern());
expression = XmlMapUtil.convertToExpression(sourceNode.getXpath());
createdNode.setExpression(expression);
// INPUT => OUTPUT
if (createdNode instanceof OutputTreeNode) {
if (NodeType.NAME_SPACE.equals(sourceNode.getNodeType())) {
// namespace and only be droped as namespace
createdNode.setDefaultValue(sourceNode.getDefaultValue());
}
createdNode.setXpath(XmlMapUtil.getXPath(targetOutputNode.getXpath(), createdNode.getName(), createdNode.getNodeType()));
createdNode.setExpression(XmlMapUtil.convertToExpression(sourceNode.getXpath()));
EList<TreeNode> sourceChildren = sourceNode.getChildren();
if (!sourceChildren.isEmpty()) {
// children must be attribute or namespace
for (TreeNode child : sourceChildren) {
OutputTreeNode childTarget = XmlmapFactory.eINSTANCE.createOutputTreeNode();
childTarget.setName(child.getName());
childTarget.setType(child.getType());
childTarget.setPattern(child.getPattern());
childTarget.setNodeType(child.getNodeType());
childTarget.setXpath(XmlMapUtil.getXPath(createdNode.getXpath(), childTarget.getName(), childTarget.getNodeType()));
createdNode.getChildren().add(childTarget);
if (NodeType.NAME_SPACE.equals(child.getNodeType())) {
childTarget.setDefaultValue(child.getDefaultValue());
// default value is already set as from source , no need the expression to get
// default value
childTarget.setExpression("");
} else {
childTarget.setExpression(XmlMapUtil.convertToExpression(child.getXpath()));
createConnection(child, childTarget);
}
}
}
// disable function of add source loop to target InputLoopNodesTable
// InputLoopTableUtil
// .addSourceLoopToInputLoopTable(sourceNode, targetOutputNode, manager.getMainInputTree());
}
} else if (objects.getType() == TransferdType.VAR) {
// VARE ==>OUTPUT
VarNodeEditPart part = (VarNodeEditPart) obj;
VarNode sourceNode = (VarNode) part.getModel();
source = sourceNode;
String variable = sourceNode.getName();
createdNode.setName(variable);
createdNode.setXpath(XmlMapUtil.getXPath(targetOutputNode.getXpath(), createdNode.getName(), createdNode.getNodeType()));
if (sourceNode.eContainer() instanceof VarTable) {
VarTable container = (VarTable) sourceNode.eContainer();
variable = container.getName() + TalendTextUtils.JAVA_END_STRING + variable;
}
createdNode.setExpression(variable);
}
targetOutputNode.getChildren().add(createdNode);
createConnection(source, createdNode);
if (!XmlMapUtil.isExpressionEditable(targetOutputNode)) {
targetOutputNode.setExpression("");
if (targetOutputNode.isAggregate()) {
targetOutputNode.setAggregate(false);
}
}
}
}
}
Aggregations