use of org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode in project tdi-studio-se by Talend.
the class CreateNodeAndConnectionCommand method execute.
@Override
public void execute() {
if (targetEditPart == null) {
return;
}
xmlMapData = getXmlMapData(targetEditPart.getModel());
if (xmlMapData == null) {
return;
}
if (newObjects instanceof TransferedObject) {
TransferedObject tranceferedObj = (TransferedObject) newObjects;
// this node type is only used when drag leaf element or attribute or varnode to create output node
NodeType selectedNodeType = NodeType.ELEMENT;
if (!update && targetEditPart instanceof OutputTreeNodeEditPart) {
OutputTreeNode targetOutputNode = (OutputTreeNode) ((OutputTreeNodeEditPart) targetEditPart).getModel();
Shell shell = targetEditPart.getViewer().getControl().getShell();
// if allNamespace , create output as namespace , if allsubTree , create output subtree , no need prompt
boolean needPrompt = false;
boolean hasSubTree = false;
for (Object o : tranceferedObj.getToTransfer()) {
if (o instanceof VarNodeEditPart) {
needPrompt = true;
} else if (o instanceof TreeNodeEditPart) {
TreeNode treeNode = (TreeNode) ((TreeNodeEditPart) o).getModel();
if (NodeType.ATTRIBUT.equals(treeNode.getNodeType())) {
needPrompt = true;
}
if (NodeType.ELEMENT.equals(treeNode.getNodeType())) {
if (treeNode.getChildren().isEmpty()) {
needPrompt = true;
} else {
hasSubTree = true;
}
}
}
}
if (needPrompt) {
DragAndDrogDialog selectDialog = new DragAndDrogDialog(shell, !targetOutputNode.getChildren().isEmpty());
int open = selectDialog.open();
if (open == Window.OK) {
if (DragAndDrogDialog.CREATE_AS_SUBELEMENT.equals(selectDialog.getSelectValue())) {
selectedNodeType = NodeType.ELEMENT;
} else if (DragAndDrogDialog.CREATE_AS_ATTRIBUTE.equals(selectDialog.getSelectValue())) {
selectedNodeType = NodeType.ATTRIBUT;
} else if (DragAndDrogDialog.CREATE_AS_SUBELEMENT.equals(selectDialog.getSelectValue())) {
selectedNodeType = NodeType.NAME_SPACE;
} else if (DragAndDrogDialog.CREATE_AS_TEXT.equals(selectDialog.getSelectValue())) {
update = true;
}
} else {
return;
}
}
if (!update) {
if (!targetOutputNode.getIncomingConnections().isEmpty() && ((selectedNodeType != NodeType.ATTRIBUT && selectedNodeType != NodeType.NAME_SPACE) || hasSubTree)) {
boolean 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) {
XmlMapUtil.detachNodeConnections(targetOutputNode, xmlMapData, false);
} else {
return;
}
}
}
}
for (Object o : (tranceferedObj.getToTransfer())) {
if (!(o instanceof TableEntityPart)) {
continue;
}
AbstractNode sourceNode = (AbstractNode) ((TableEntityPart) o).getModel();
if (update) {
doUpdate(sourceNode);
} else {
// only drop output can create a new node now
if (targetEditPart instanceof OutputTreeNodeEditPart) {
OutputTreeNode targetOutputNode = (OutputTreeNode) ((OutputTreeNodeEditPart) targetEditPart).getModel();
OutputTreeNode targetNode = XmlmapFactory.eINSTANCE.createOutputTreeNode();
targetNode.setName(sourceNode.getName());
targetNode.setType(XmlMapUtil.DEFAULT_DATA_TYPE);
if (sourceNode instanceof TreeNode) {
NodeType nodeType = selectedNodeType;
if (NodeType.NAME_SPACE.equals(((TreeNode) sourceNode).getNodeType())) {
// namespace and only be droped as namespace
nodeType = NodeType.NAME_SPACE;
targetNode.setDefaultValue(((TreeNode) sourceNode).getDefaultValue());
} else if (!((TreeNode) sourceNode).getChildren().isEmpty()) {
nodeType = ((TreeNode) sourceNode).getNodeType();
}
targetNode.setXpath(XmlMapUtil.getXPath(targetOutputNode.getXpath(), targetNode.getName(), nodeType));
targetNode.setNodeType(nodeType);
targetNode.setExpression(XmlMapUtil.convertToExpression(((TreeNode) sourceNode).getXpath()));
EList<TreeNode> sourceChildren = ((TreeNode) 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.setNodeType(child.getNodeType());
childTarget.setXpath(XmlMapUtil.getXPath(targetNode.getXpath(), childTarget.getName(), childTarget.getNodeType()));
targetNode.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()));
Connection conn = XmlmapFactory.eINSTANCE.createConnection();
conn.setSource(child);
conn.setTarget(childTarget);
// attach source and target
childTarget.getIncomingConnections().add(conn);
child.getOutgoingConnections().add(conn);
if (xmlMapData != null) {
xmlMapData.getConnections().add(conn);
}
}
}
}
} else if (sourceNode instanceof VarNode) {
String variable = sourceNode.getName();
targetNode.setXpath(XmlMapUtil.getXPath(targetOutputNode.getXpath(), targetNode.getName(), selectedNodeType));
targetNode.setNodeType(selectedNodeType);
if (sourceNode.eContainer() instanceof VarTable) {
VarTable container = (VarTable) sourceNode.eContainer();
variable = container.getName() + TalendTextUtils.JAVA_END_STRING + variable;
}
targetNode.setExpression(variable);
}
targetOutputNode.getChildren().add(targetNode);
// add connection
Connection conn = XmlmapFactory.eINSTANCE.createConnection();
conn.setSource(sourceNode);
conn.setTarget(targetNode);
// attach source and target
targetNode.getIncomingConnections().add(conn);
sourceNode.getOutgoingConnections().add(conn);
if (xmlMapData != null) {
xmlMapData.getConnections().add(conn);
}
// if (sourceNode instanceof TreeNode) {
// createInputLoopTable((TreeNode) sourceNode, targetNode);
// }
}
}
}
}
if (targetEditPart instanceof OutputTreeNodeEditPart) {
OutputTreeNode model = (OutputTreeNode) targetEditPart.getModel();
if (NodeType.NAME_SPACE.equals(model.getNodeType()) && model.getExpression() != null && !"".equals(model.getExpression())) {
model.setDefaultValue("");
}
if (!XmlMapUtil.isExpressionEditable(model)) {
model.setExpression("");
if (model.isAggregate()) {
model.setAggregate(false);
}
}
}
}
use of org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode in project tdi-studio-se by Talend.
the class UpdateExpressionCommand method execute.
@Override
public void execute() {
AbstractNode targetNode = (AbstractNode) targetEditPart.getModel();
boolean targetVar = targetNode instanceof VarNode;
boolean targetOutput = targetNode instanceof OutputTreeNode;
boolean targetInput = targetNode instanceof TreeNode && !(targetNode instanceof OutputTreeNode);
String expression = targetNode.getExpression();
if (objects.getToTransfer() != null) {
for (Object obj : objects.getToTransfer()) {
AbstractNode sourceNode = null;
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());
}
targetNode.setExpression(expression);
// INPUT => OUTPUT/VAR
if (targetVar || targetOutput) {
createConnection(sourceNode, targetNode);
if (targetOutput) {
OutputTreeNode model = (OutputTreeNode) targetNode;
if (NodeType.NAME_SPACE.equals(model.getNodeType()) && model.getExpression() != null && !"".equals(model.getExpression())) {
model.setDefaultValue("");
}
// disable function of add source loop to target InputLoopNodesTable
// InputLoopTableUtil.addSourceLoopToInputLoopTable((TreeNode) sourceNode, model,
// manager.getMainInputTree());
}
} else // INPUT => INPUT
if (targetInput) {
createLookupConnection((TreeNode) sourceNode, (TreeNode) targetNode);
}
} else if (objects.getType() == TransferdType.VAR) {
// VARE ==>OUTPUT
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();
}
targetNode.setExpression(expression);
createConnection(sourceNode, targetNode);
}
}
}
}
use of org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode 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.OutputTreeNode in project tdi-studio-se by Talend.
the class RenameTreeNodeAction method run.
@Override
public void run() {
if (selectedNode != null) {
// validataor
IInputValidator validataor = new IInputValidator() {
public String isValid(String newText) {
String xpath = XmlMapUtil.getXPath(((TreeNode) selectedNode.eContainer()).getXpath(), newText, selectedNode.getNodeType());
EList<TreeNode> children = ((TreeNode) selectedNode.eContainer()).getChildren();
boolean exist = false;
for (TreeNode child : children) {
if (child.getNodeType().equals(selectedNode.getNodeType())) {
if (child.getXpath() != null && child.getXpath().equals(xpath) && !child.equals(selectedNode)) {
exist = true;
break;
}
}
}
if (exist) {
if (selectedNode.getNodeType().equals(NodeType.ATTRIBUT)) {
return "Atribute '" + newText + "' already exist !";
} else if (selectedNode.getNodeType().equals(NodeType.ELEMENT)) {
return "Element '" + newText + "' already exist !";
}
}
return null;
}
};
String name = selectedNode.getName();
if (selectedNode.isSubstitution()) {
name = name.substring(0, name.lastIndexOf(XSDPopulationUtil2.SUBS));
}
InputDialog dialog = new InputDialog(null, "Rename Tree Node", "", name, validataor);
if (dialog.open() == Window.OK) {
if (selectedNode.isSubstitution()) {
selectedNode.setName(dialog.getValue() + XSDPopulationUtil2.SUBS);
} else {
selectedNode.setName(dialog.getValue());
}
// refresh
if (selectedNode.isSubstitution()) {
TreeNode realParent = XmlMapUtil.getRealParentNode(selectedNode);
if (realParent != null) {
selectedNode.setXpath(XmlMapUtil.getXPath(realParent.getXpath(), selectedNode.getName(), selectedNode.getNodeType()));
}
} else {
XmlMapData externalEmfData = (XmlMapData) mapperManager.getExternalData();
XmlMapUtil.updateXPathAndExpression(externalEmfData, mapperManager.getMapperComponent().getExpressionManager(), selectedNode, dialog.getValue(), XmlMapUtil.getXPathLength(selectedNode.getXpath()), true);
}
TabFolderEditors tabFolderEditors = mapperManager.getMapperUI().getTabFolderEditors();
if (tabFolderEditors != null) {
if (selectedNode instanceof OutputTreeNode) {
tabFolderEditors.getOutputTreeSchemaEditor().refresh();
} else if (selectedNode instanceof TreeNode) {
tabFolderEditors.getInputTreeSchemaEditor().refresh();
}
}
}
}
}
use of org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode in project tdi-studio-se by Talend.
the class AddChoiceAction 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();
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 a choice for the selected element ?");
}
if (canContinue) {
XmlMapUtil.detachNodeConnections(parent, mapperManager.getExternalData(), false);
treeNode.setName(parent.getName() + XSDPopulationUtil2.CHOICE);
treeNode.setNodeType(NodeType.ELEMENT);
treeNode.setXpath(XmlMapUtil.getXPath(this.parent.getXpath(), treeNode.getName(), treeNode.getNodeType()));
treeNode.setChoice(true);
parent.getChildren().add(treeNode);
if (!input) {
OutputTreeNode output = (OutputTreeNode) parent;
if (!XmlMapUtil.isExpressionEditable(output) && output.isAggregate()) {
output.setAggregate(false);
}
}
Object object = graphicViewer.getEditPartRegistry().get(treeNode);
if (object instanceof TreeNodeEditPart) {
graphicViewer.select((TreeNodeEditPart) object);
}
}
}
Aggregations