use of org.talend.designer.xmlmap.model.emf.xmlmap.VarTable in project tdi-studio-se by Talend.
the class XmlMapNodeDirectEditManager method initCellEditor.
/*
* (non-Javadoc)
*
* @see org.eclipse.gef.tools.DirectEditManager#initCellEditor()
*/
@Override
protected void initCellEditor() {
DirectEditType directEditType = cellAndType.get(getCellEditor());
if (model instanceof AbstractNode) {
final AbstractNode abstractNode = (AbstractNode) model;
if (directEditType != null) {
switch(directEditType) {
case EXPRESSION:
String expression = abstractNode.getExpression() == null ? "" : abstractNode.getExpression();
getCellEditor().setValue(expression);
Text text = ((ExtendedTextCellEditor) getCellEditor()).getTextControl();
text.selectAll();
break;
case NODE_NAME:
String variable = abstractNode.getName();
if (variable == null) {
variable = "";
}
getCellEditor().setValue(variable);
final Text nametext = (Text) ((TextCellEditor) getCellEditor()).getControl();
nametext.selectAll();
if (model instanceof VarNode) {
nametext.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
List<VarNode> children = new ArrayList<VarNode>();
children.addAll(((VarTable) abstractNode.eContainer()).getNodes());
children.remove(model);
String message = XmlMapUtil.isValidColumnName(children, ((Text) e.widget).getText());
if (message != null) {
nametext.setBackground(ColorConstants.red);
} else {
nametext.setBackground(ColorConstants.white);
}
}
});
}
break;
case VAR_NODE_TYPE:
if (getCellEditor() instanceof ComboBoxCellEditor) {
CCombo combo = (CCombo) getCellEditor().getControl();
combo.setText(getTypeDisplayValue((VarNode) abstractNode));
}
break;
}
}
} else if (model instanceof InputXmlTree) {
InputXmlTree inputxmlTree = (InputXmlTree) model;
if (directEditType != null) {
switch(directEditType) {
case EXPRESSION_FILTER:
String expressionFilter = inputxmlTree.getExpressionFilter();
if (expressionFilter == null) {
expressionFilter = "";
}
getCellEditor().setValue(expressionFilter);
Text textarea = ((ExtendedTextCellEditor) getCellEditor()).getTextControl();
textarea.selectAll();
break;
case LOOKUP_MODEL:
if (getCellEditor() instanceof ComboBoxCellEditor) {
CCombo combo = (CCombo) getCellEditor().getControl();
combo.setText(getLookupDisplayName(inputxmlTree.getLookupMode()));
}
break;
case MATCH_MODEL:
if (getCellEditor() instanceof ComboBoxCellEditor) {
CCombo combo = (CCombo) getCellEditor().getControl();
combo.setText(getMatchModelDisplayName(inputxmlTree.getMatchingMode()));
}
break;
case JOIN_MODEL:
if (getCellEditor() instanceof ComboBoxCellEditor) {
CCombo combo = (CCombo) getCellEditor().getControl();
String join = "";
if (inputxmlTree.isInnerJoin()) {
join = joinModel[0];
} else {
join = joinModel[1];
}
combo.setText(join);
}
break;
case PERSISTENT_MODEL:
if (getCellEditor() instanceof ComboBoxCellEditor) {
CCombo combo = (CCombo) getCellEditor().getControl();
combo.setText(String.valueOf(inputxmlTree.isPersistent()));
}
break;
}
}
} else if (model instanceof OutputXmlTree) {
OutputXmlTree outputTree = (OutputXmlTree) model;
if (directEditType != null) {
switch(directEditType) {
case EXPRESSION_FILTER:
String expressionFilter = outputTree.getExpressionFilter();
if (expressionFilter == null) {
expressionFilter = "";
}
getCellEditor().setValue(expressionFilter);
Text textarea = ((ExtendedTextCellEditor) getCellEditor()).getTextControl();
textarea.selectAll();
break;
case OUTPUT_REJECT:
if (getCellEditor() instanceof ComboBoxCellEditor) {
CCombo combo = (CCombo) getCellEditor().getControl();
combo.setText(String.valueOf(outputTree.isReject()));
}
break;
case LOOK_UP_INNER_JOIN_REJECT:
if (getCellEditor() instanceof ComboBoxCellEditor) {
CCombo combo = (CCombo) getCellEditor().getControl();
combo.setText(String.valueOf(outputTree.isRejectInnerJoin()));
}
break;
case ALL_IN_ONE:
if (getCellEditor() instanceof ComboBoxCellEditor) {
CCombo combo = (CCombo) getCellEditor().getControl();
combo.setText(String.valueOf(outputTree.isAllInOne()));
}
break;
case ENABLE_EMPTY_ELEMENT:
if (getCellEditor() instanceof ComboBoxCellEditor) {
CCombo combo = (CCombo) getCellEditor().getControl();
combo.setText(String.valueOf(outputTree.isEnableEmptyElement()));
}
}
}
} else if (model instanceof XmlMapData) {
XmlMapData xmlMapData = (XmlMapData) model;
if (directEditType != null) {
switch(directEditType) {
case SERACH:
Text text = (Text) getCellEditor().getControl();
text.selectAll();
break;
}
}
}
}
use of org.talend.designer.xmlmap.model.emf.xmlmap.VarTable in project tdi-studio-se by Talend.
the class XmlMapVarTablePart method createFigure.
@Override
protected IFigure createFigure() {
/* Center var figure */
VarTable model = (VarTable) getModel();
VarTableManager manager = new VarTableManager(model, this);
centerVarFigure = new VarTableContainer(manager);
return centerVarFigure;
}
use of org.talend.designer.xmlmap.model.emf.xmlmap.VarTable in project tdi-studio-se by Talend.
the class XmlMapComponent method checkNeededRoutines.
@Override
public List<String> checkNeededRoutines(List<String> possibleRoutines, String additionalString) {
List<String> routinesToAdd = new ArrayList<String>();
XmlMapData xmlMapData = (XmlMapData) getExternalEmfData();
for (String routine : possibleRoutines) {
List<OutputXmlTree> listOutput = xmlMapData.getOutputTrees();
for (OutputXmlTree outTable : listOutput) {
List<OutputTreeNode> listOutEntry = outTable.getNodes();
if (listOutEntry != null && !listOutEntry.isEmpty()) {
for (OutputTreeNode outEntry : listOutEntry) {
String expression = outEntry.getExpression();
if (expression != null && !routinesToAdd.contains(routine) && expression.contains(routine + additionalString)) {
routinesToAdd.add(routine);
}
}
}
String filter = outTable.getExpressionFilter();
if (filter != null && !routinesToAdd.contains(routine) && filter.contains(routine + additionalString)) {
routinesToAdd.add(routine);
}
}
List<InputXmlTree> listInput = xmlMapData.getInputTrees();
for (InputXmlTree inputTable : listInput) {
List<TreeNode> listInEntry = inputTable.getNodes();
if (listInEntry != null && !listInEntry.isEmpty()) {
for (TreeNode inEntry : listInEntry) {
String expression = inEntry.getExpression();
if (expression != null && !routinesToAdd.contains(routine) && expression.contains(routine + additionalString)) {
routinesToAdd.add(routine);
}
}
}
String filter = inputTable.getExpressionFilter();
if (filter != null && !routinesToAdd.contains(routine) && filter.contains(routine + additionalString)) {
routinesToAdd.add(routine);
}
}
List<VarTable> listVar = xmlMapData.getVarTables();
for (VarTable varTable : listVar) {
List<VarNode> listVarEntry = varTable.getNodes();
if (listVarEntry != null && !listVarEntry.isEmpty()) {
for (VarNode varEntry : listVarEntry) {
String expression = varEntry.getExpression();
if (expression != null && !routinesToAdd.contains(routine) && expression.contains(routine + additionalString)) {
routinesToAdd.add(routine);
}
}
}
}
}
return routinesToAdd;
}
use of org.talend.designer.xmlmap.model.emf.xmlmap.VarTable in project tdi-studio-se by Talend.
the class XmlMapDataImplTest method createSparkData.
private XmlMapData createSparkData(String inputDiff, String outputDiff, String varDiff) {
XmlMapData data = XmlmapFactory.eINSTANCE.createXmlMapData();
//
InputXmlTree inputTree = XmlmapFactory.eINSTANCE.createInputXmlTree();
inputTree.setName("input_1");
inputTree.setLookup(true);
inputTree.setInnerJoin(false);
inputTree.setLookupMode("LOAD_ONCE");
inputTree.setMatchingMode("ALL_ROWS");
inputTree.setMinimized(false);
inputTree.setMultiLoops(false);
inputTree.setPersistent(false);
data.getInputTrees().add(inputTree);
TreeNode treeNode = XmlmapFactory.eINSTANCE.createTreeNode();
treeNode.setName("inputTreeNode");
treeNode.setXpath("row1/newColumn");
treeNode.setExpression(inputDiff);
treeNode.setType("id_String");
treeNode.setLoop(false);
treeNode.setPattern(inputDiff);
treeNode.setKey(false);
treeNode.setGroup(false);
treeNode.setMain(false);
treeNode.setDefaultValue("value");
treeNode.setNullable(false);
treeNode.setChoice(false);
treeNode.setSubstitution(false);
treeNode.setOptional(false);
treeNode.setNodeType(org.talend.designer.xmlmap.model.emf.xmlmap.NodeType.ATTRIBUT);
inputTree.getNodes().add(treeNode);
OutputXmlTree outputTree = XmlmapFactory.eINSTANCE.createOutputXmlTree();
outputTree.setName("output_1");
outputTree.setReject(false);
outputTree.setRejectInnerJoin(false);
outputTree.setErrorReject(false);
outputTree.setAllInOne(false);
outputTree.setEnableEmptyElement(false);
data.getOutputTrees().add(outputTree);
OutputTreeNode treeNode2 = XmlmapFactory.eINSTANCE.createOutputTreeNode();
treeNode2.setName("outputTreeNode");
treeNode2.setXpath("out/newColumn");
treeNode2.setType("id_String");
treeNode2.setAggregate(false);
treeNode2.setLoop(false);
treeNode2.setPattern(outputDiff);
treeNode2.setExpression(outputDiff);
treeNode2.setKey(false);
treeNode2.setGroup(false);
treeNode2.setMain(false);
treeNode2.setDefaultValue("value");
treeNode2.setNullable(false);
treeNode2.setChoice(false);
treeNode2.setSubstitution(false);
treeNode2.setOptional(false);
treeNode2.setNodeType(org.talend.designer.xmlmap.model.emf.xmlmap.NodeType.ATTRIBUT);
outputTree.getNodes().add(treeNode2);
VarTable vatTable = XmlmapFactory.eINSTANCE.createVarTable();
vatTable.setName("varTable");
vatTable.setMinimized(true);
VarNode varNode = XmlmapFactory.eINSTANCE.createVarNode();
varNode.setName("varNode");
varNode.setNullable(false);
varNode.setType("id_String");
varNode.setExpression(varDiff);
vatTable.getNodes().add(varNode);
data.getVarTables().add(vatTable);
Connection connection = XmlmapFactory.eINSTANCE.createConnection();
connection.setSource(treeNode);
connection.setTarget(treeNode2);
data.getConnections().add(connection);
treeNode.getOutgoingConnections().add(connection);
treeNode2.getIncomingConnections().add(connection);
FilterConnection fc = XmlmapFactory.eINSTANCE.createFilterConnection();
fc.setSource(treeNode);
fc.setTarget(outputTree);
data.getConnections().add(fc);
treeNode.getFilterOutGoingConnections().add(fc);
outputTree.getFilterIncomingConnections().add(fc);
return data;
}
use of org.talend.designer.xmlmap.model.emf.xmlmap.VarTable 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