use of org.talend.designer.xmlmap.model.emf.xmlmap.VarNode in project tdi-studio-se by Talend.
the class VarToolBarFigure method moveDown.
@Override
protected void moveDown() {
CommandStack commandStack = getTableManager().getGraphicalViewer().getEditDomain().getCommandStack();
commandStack.execute(new Command() {
@Override
public void execute() {
List selectedEditParts = getTableManager().getGraphicalViewer().getSelectedEditParts();
List<Integer> indexToMove = new ArrayList<Integer>();
EList<VarNode> nodes = parentTable.getNodes();
for (int i = 0; i < selectedEditParts.size(); i++) {
Object obj = selectedEditParts.get(i);
if (obj instanceof VarNodeEditPart) {
VarNode node = (VarNode) ((VarNodeEditPart) obj).getModel();
int indexOf = nodes.indexOf(node);
if (indexOf != -1 && indexOf < nodes.size() - 1) {
indexToMove.add(indexOf);
}
}
}
Collections.sort(indexToMove);
Collections.reverse(indexToMove);
for (int i = 0; i < indexToMove.size(); i++) {
int index = indexToMove.get(i);
VarNode temp = nodes.get(index);
nodes.remove(temp);
nodes.add(index + 1, temp);
}
for (int i = 0; i < indexToMove.size(); i++) {
EditPart part = (EditPart) tablePart.getChildren().get(indexToMove.get(i) + 1);
tablePart.getViewer().appendSelection(part);
}
}
});
}
use of org.talend.designer.xmlmap.model.emf.xmlmap.VarNode in project tdi-studio-se by Talend.
the class VarToolBarFigure method moveUp.
@Override
protected void moveUp() {
CommandStack commandStack = getTableManager().getGraphicalViewer().getEditDomain().getCommandStack();
commandStack.execute(new Command() {
@Override
public void execute() {
List selectedEditParts = getTableManager().getGraphicalViewer().getSelectedEditParts();
List<Integer> indexToMove = new ArrayList<Integer>();
EList<VarNode> nodes = parentTable.getNodes();
for (int i = 0; i < selectedEditParts.size(); i++) {
Object obj = selectedEditParts.get(i);
if (obj instanceof VarNodeEditPart) {
VarNode node = (VarNode) ((VarNodeEditPart) obj).getModel();
int indexOf = nodes.indexOf(node);
if (indexOf != -1 && indexOf > 0) {
indexToMove.add(indexOf);
}
}
}
Collections.sort(indexToMove);
for (int i = 0; i < indexToMove.size(); i++) {
int index = indexToMove.get(i);
VarNode temp = nodes.get(index);
nodes.remove(temp);
nodes.add(index - 1, temp);
}
for (int i = 0; i < indexToMove.size(); i++) {
EditPart part = (EditPart) tablePart.getChildren().get(indexToMove.get(i) - 1);
tablePart.getViewer().appendSelection(part);
}
}
});
}
use of org.talend.designer.xmlmap.model.emf.xmlmap.VarNode in project tdi-studio-se by Talend.
the class SearchZoneMapper method search.
public void search(Map<Integer, Map<Integer, Figure>> searchMaps, String searchValue) {
if (searchValue.equals("") || searchValue == null) {
return;
}
List<InputXmlTree> inputTrees = mapperManager.getExternalData().getInputTrees();
List<VarTable> varTables = mapperManager.getExternalData().getVarTables();
List<OutputXmlTree> outputTrees = mapperManager.getExternalData().getOutputTrees();
matcher.setPattern("*" + searchValue.trim() + "*");
int index = -1;
// for the InputTables
for (InputXmlTree inputXmlTree : inputTrees) {
// ExpressionFilter
if (inputXmlTree.getExpressionFilter() != null && matcher.matches(inputXmlTree.getExpressionFilter())) {
EList<Adapter> adapter = inputXmlTree.eAdapters();
if (adapter.size() > 0) {
if (adapter.get(0) instanceof InputXmlTreeEditPart) {
InputXmlTreeEditPart inputXmlTreeEditPart = (InputXmlTreeEditPart) adapter.get(0);
if (inputXmlTreeEditPart != null && inputXmlTreeEditPart.getFigure() != null && inputXmlTreeEditPart.getFigure() instanceof InputXmlTreeFigure) {
InputXmlTreeFigure inputXmlTreeFigure = (InputXmlTreeFigure) inputXmlTreeEditPart.getFigure();
Map<Integer, Figure> map = new HashMap<Integer, Figure>();
map.put(0, inputXmlTreeFigure.getFilterContainer());
index++;
searchMaps.put(index, map);
}
}
}
}
// TreeNode
for (TreeNode node : inputXmlTree.getNodes()) {
// id_Document type
if (XmlMapUtil.DOCUMENT.equals(node.getType())) {
for (TreeNode nodeTemp : XmlMapUtil.getFlatChildrenList(node)) {
if (getMatcherNodeFigure(nodeTemp).size() > 0) {
index++;
searchMaps.put(index, getMatcherNodeFigure(nodeTemp));
}
}
}
if (getMatcherNodeFigure(node).size() > 0) {
index++;
searchMaps.put(index, getMatcherNodeFigure(node));
}
}
}
// for the VarsTables
for (VarTable varTable : varTables) {
for (VarNode node : varTable.getNodes()) {
if (getMatcherNodeFigure(node).size() > 0) {
index++;
searchMaps.put(index, getMatcherNodeFigure(node));
}
}
}
// for the OutputTables
for (OutputXmlTree outputXmlTree : outputTrees) {
// ExpressionFilter
if (outputXmlTree.getExpressionFilter() != null && matcher.matches(outputXmlTree.getExpressionFilter())) {
EList<Adapter> adapter = outputXmlTree.eAdapters();
if (adapter.size() > 0) {
if (adapter.get(0) instanceof OutputXmlTreeEditPart) {
OutputXmlTreeEditPart outputXmlTreeEditPart = (OutputXmlTreeEditPart) adapter.get(0);
if (outputXmlTreeEditPart != null && outputXmlTreeEditPart.getFigure() != null && outputXmlTreeEditPart.getFigure() instanceof OutputXmlTreeFigure) {
OutputXmlTreeFigure outputXmlTreeFigure = (OutputXmlTreeFigure) outputXmlTreeEditPart.getFigure();
Map<Integer, Figure> map = new HashMap<Integer, Figure>();
map.put(0, outputXmlTreeFigure.getFilterContainer());
index++;
searchMaps.put(index, map);
}
}
}
}
// OutputTreeNode
for (OutputTreeNode node : outputXmlTree.getNodes()) {
// id_Document type
if (XmlMapUtil.DOCUMENT.equals(node.getType())) {
for (TreeNode nodeTemp : XmlMapUtil.getFlatChildrenList(node)) {
if (getMatcherNodeFigure(nodeTemp).size() > 0) {
index++;
searchMaps.put(index, getMatcherNodeFigure(nodeTemp));
}
}
} else {
if (getMatcherNodeFigure(node).size() > 0) {
index++;
searchMaps.put(index, getMatcherNodeFigure(node));
}
}
}
}
}
use of org.talend.designer.xmlmap.model.emf.xmlmap.VarNode 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);
}
}
}
}
}
use of org.talend.designer.xmlmap.model.emf.xmlmap.VarNode 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);
}
}
}
}
Aggregations