use of org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode in project tdi-studio-se by Talend.
the class CreateNodeAndConnectionCommand method doUpdate.
// private void createInputLoopTable(TreeNode sourceNode, OutputTreeNode targetOutputNode) {
// EditPartViewer viewer = targetEditPart.getViewer();
// if (viewer instanceof XmlMapGraphicViewer) {
// InputLoopTableUtil.addSourceLoopToInputLoopTable(sourceNode, targetOutputNode, ((XmlMapGraphicViewer) viewer)
// .getMapperManager().getMainInputTree());
// }
// }
private void doUpdate(AbstractNode sourceNode) {
if (targetEditPart instanceof OutputTreeNodeEditPart) {
OutputTreeNode targetOutputNode = (OutputTreeNode) ((OutputTreeNodeEditPart) targetEditPart).getModel();
String expression = targetOutputNode.getExpression();
if (sourceNode instanceof TreeNode) {
if (expression == null) {
expression = XmlMapUtil.convertToExpression(((TreeNode) sourceNode).getXpath());
} else {
expression = expression + " " + XmlMapUtil.convertToExpression(((TreeNode) sourceNode).getXpath());
}
} else if (sourceNode instanceof VarNode) {
String tableName = "Var";
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 instanceof TreeNode) {
// createInputLoopTable((TreeNode) sourceNode, targetOutputNode);
// }
targetOutputNode.setExpression(expression);
Connection conn = XmlmapFactory.eINSTANCE.createConnection();
conn.setSource(sourceNode);
conn.setTarget(targetOutputNode);
targetOutputNode.getIncomingConnections().add(conn);
sourceNode.getOutgoingConnections().add(conn);
if (xmlMapData != null) {
xmlMapData.getConnections().add(conn);
}
} else if (targetEditPart instanceof TreeNodeEditPart) {
/* for lookup connections */
if (sourceNode instanceof TreeNode) {
TreeNode targetTreeNode = (TreeNode) targetEditPart.getModel();
String expression = targetTreeNode.getExpression();
if (expression == null) {
expression = "";
}
expression = expression + " " + XmlMapUtil.convertToExpression(((TreeNode) sourceNode).getXpath());
targetTreeNode.setExpression(expression);
LookupConnection conn = XmlmapFactory.eINSTANCE.createLookupConnection();
conn.setSource(sourceNode);
conn.setTarget(targetTreeNode);
targetTreeNode.getLookupIncomingConnections().add(conn);
((TreeNode) sourceNode).getLookupOutgoingConnections().add(conn);
if (xmlMapData != null) {
xmlMapData.getConnections().add(conn);
}
}
} else if (targetEditPart instanceof VarNodeEditPart) {
/* for varTable drag drop */
if (sourceNode instanceof TreeNode) {
VarNodeEditPart targetPart = (VarNodeEditPart) targetEditPart;
VarNode targetNode = (VarNode) targetPart.getModel();
String expression = targetNode.getExpression();
if (expression == null) {
expression = "";
}
expression = expression + " " + XmlMapUtil.convertToExpression(((TreeNode) sourceNode).getXpath());
if (targetNode.getName() == null || "".equals(targetNode.getName())) {
String findUniqueVarColumnName = XmlMapUtil.findUniqueVarColumnName(sourceNode.getName(), xmlMapData.getVarTables().get(0));
targetNode.setName(findUniqueVarColumnName);
}
targetNode.setExpression(expression.trim());
targetNode.setType(sourceNode.getType());
Connection conn = XmlmapFactory.eINSTANCE.createConnection();
conn.setSource(sourceNode);
conn.setTarget(targetNode);
targetNode.getIncomingConnections().add(conn);
sourceNode.getOutgoingConnections().add(conn);
if (xmlMapData != null) {
xmlMapData.getConnections().add(conn);
}
}
} else if (targetEditPart instanceof InputXmlTreeEditPart || targetEditPart instanceof OutputXmlTreeEditPart) {
AbstractInOutTree treeModel = (AbstractInOutTree) targetEditPart.getModel();
String expression = treeModel.getExpressionFilter();
if (sourceNode instanceof TreeNode) {
if (expression == null) {
expression = XmlMapUtil.convertToExpression(((TreeNode) sourceNode).getXpath());
} else {
expression = expression + " " + XmlMapUtil.convertToExpression(((TreeNode) sourceNode).getXpath());
}
} else if (sourceNode instanceof VarNode) {
String tableName = "Var";
if (sourceNode.eContainer() instanceof VarTable) {
tableName = ((VarTable) sourceNode.eContainer()).getName();
}
if (expression == null) {
expression = tableName + "." + sourceNode.getName();
} else {
expression = expression + " " + tableName + "." + sourceNode.getName();
}
}
treeModel.setExpressionFilter(expression);
FilterConnection connection = XmlmapFactory.eINSTANCE.createFilterConnection();
connection.setSource(sourceNode);
connection.setTarget(treeModel);
treeModel.getFilterIncomingConnections().add(connection);
sourceNode.getFilterOutGoingConnections().add(connection);
xmlMapData.getConnections().add(connection);
}
}
use of org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode in project tdi-studio-se by Talend.
the class XmlTreeSchemaTableView method createColumns.
@Override
protected void createColumns(final TableViewerCreator<TreeNode> tableViewerCreator, Table table) {
TableViewerCreatorColumn column = new TableViewerCreatorColumn(tableViewerCreator);
column.setTitle("XPath");
column.setId(ID_COLUMN_XPATH);
column.setWeight(20);
column.setModifiable(true);
column.setBeanPropertyAccessors(new IBeanPropertyAccessors<TreeNode, Object>() {
@Override
public Object get(TreeNode bean) {
return bean.getXpath();
}
@Override
public void set(TreeNode bean, Object value) {
if (isValidName) {
bean.setName((String) value);
// String xPath = bean.getXPath();
// xPath = xPath.substring(0, xPath.lastIndexOf(XmlMapUtil.XPATH_SEPARATOR) + 1);
// NodeType nodeType = bean.getTreeNode().getNodeType();
// String typedValue = null;
// if (NodeType.ATTRIBUT.equals(nodeType)) {
// typedValue = xPath + XmlMapUtil.XPATH_ATTRIBUTE + bean.getName();
// } else if (NodeType.NAME_SPACE.equals(nodeType)) {
// typedValue = xPath + XmlMapUtil.XPATH_NAMESPACE + bean.getName();
// } else {
// typedValue = xPath + bean.getName();
// }
// bean.setXPath(typedValue);
XmlMapData mapperData = XmlMapUtil.getXmlMapData(bean);
XmlMapExpressionManager expressionManager = new XmlMapExpressionManager();
XmlMapUtil.updateXPathAndExpression(mapperData, expressionManager, bean, bean.getName(), XmlMapUtil.getXPathLength(bean.getXpath()), true);
if (!bean.getChildren().isEmpty()) {
refresh();
}
}
}
});
final TextCellEditor cellEditor = new TextCellEditor(tableViewerCreator.getTable());
cellEditor.addListener(new DialogErrorForCellEditorListener(cellEditor, column) {
@Override
public void newValidValueTyped(int itemIndex, Object previousValue, Object newValue, CELL_EDITOR_STATE state) {
}
@Override
public String validateValue(String newValue, int beanPosition) {
return validateXPath(newValue, beanPosition);
}
});
column.setCellEditor(cellEditor);
column.setColumnCellModifier(new ColumnCellModifier(column) {
@Override
public Object getValue(Object bean) {
TreeNode entry = (TreeNode) bean;
return entry.getName();
}
@Override
public boolean modify(Object bean, Object value) {
return false;
}
});
column = new TableViewerCreatorColumn(tableViewerCreator);
column.setTitle("Key");
column.setToolTipHeader("Key");
column.setId(ID_COLUMN_KEY);
//$NON-NLS-1$
column.setDisplayedValue("");
column.setWeight(10);
column.setModifiable(true);
CheckboxTableEditorContent checkbox = new CheckboxTableEditorContent();
column.setTableEditorContent(checkbox);
column.setBeanPropertyAccessors(new IBeanPropertyAccessors<TreeNode, Boolean>() {
@Override
public Boolean get(TreeNode bean) {
return bean.isKey();
}
@Override
public void set(TreeNode bean, Boolean value) {
bean.setKey(value);
}
});
column = new TableViewerCreatorColumn(tableViewerCreator);
column.setTitle("Type");
column.setToolTipHeader("Type");
column.setId(ID_COLUMN_TYPE);
column.setBeanPropertyAccessors(getTalendTypeAccessor());
column.setModifiable(true);
column.setWeight(20);
TreeSchemaJavaTypeComboValueAdapter comboValueAdapter = new TreeSchemaJavaTypeComboValueAdapter<TreeNode>(JavaTypesManager.getDefaultJavaType(), getNullableAccessor());
ComboBoxCellEditor typeComboEditor = new ComboBoxCellEditor(tableViewerCreator.getTable(), comboValueAdapter.getTalendTypesLabels(), SWT.READ_ONLY);
CCombo typeCombo = (CCombo) typeComboEditor.getControl();
typeCombo.setEditable(false);
column.setCellEditor(typeComboEditor, comboValueAdapter);
column = new TableViewerCreatorColumn(tableViewerCreator);
column.setTitle("Nullable");
column.setToolTipHeader("Nullable");
column.setId(ID_COLUMN_NULLABLE);
column.setBeanPropertyAccessors(getNullableAccessor());
column.setWeight(20);
//$NON-NLS-1$
column.setDisplayedValue("");
column.setModifiable(true);
column.setTableColumnSelectionListener(new CheckColumnSelectionListener(column, tableViewerCreator));
column.setImageHeader(ImageProvider.getImage(EImage.CHECKED_ICON));
CheckboxTableEditorContent nullableCheckbox = new CheckboxTableEditorContent();
column.setTableEditorContent(nullableCheckbox);
column = new TableViewerCreatorColumn(tableViewerCreator);
column.setTitle("Pattern");
column.setId(ID_COLUMN_PATTERN);
column.setWeight(20);
column.setBeanPropertyAccessors(new IBeanPropertyAccessors<TreeNode, String>() {
@Override
public String get(TreeNode bean) {
return bean.getPattern();
}
@Override
public void set(TreeNode bean, String value) {
bean.setPattern(value);
}
});
final ColumnCellModifier columnCellModifier = new ColumnCellModifier(column) {
@Override
public boolean canModify(Object bean) {
boolean typeIsDate = currentBeanHasJavaDateType(bean) && !isReadOnly();
return typeIsDate;
}
};
column.setColorProvider(new IColumnColorProvider() {
@Override
public Color getBackgroundColor(Object bean) {
if (!columnCellModifier.canModify(bean)) {
return READONLY_CELL_BG_COLOR;
}
return null;
}
@Override
public Color getForegroundColor(Object bean) {
return null;
}
});
column.setLabelProvider(new IColumnLabelProvider() {
/*
* (non-Javadoc)
*
* @see org.talend.commons.ui.swt.tableviewer.behavior.IColumnLabelProvider#getLabel(java.lang.Object)
*/
@Override
public String getLabel(Object bean) {
if (!currentBeanHasJavaDateType(bean)) {
//$NON-NLS-1$
return "";
}
return null;
}
});
column.setColumnCellModifier(columnCellModifier);
JavaSimpleDateFormatProposalProvider proposalProvider = new JavaSimpleDateFormatProposalProvider();
TextCellEditorWithProposal patternCellEditor = new TextCellEditorWithProposal(tableViewerCreator.getTable(), column);
ContentProposalAdapterExtended contentProposalAdapter = patternCellEditor.getContentProposalAdapter();
contentProposalAdapter.setFilterStyle(ContentProposalAdapterExtended.FILTER_NONE);
contentProposalAdapter.setProposalAcceptanceStyle(ContentProposalAdapterExtended.PROPOSAL_INSERT);
patternCellEditor.setContentProposalProvider(proposalProvider);
column.setCellEditor(patternCellEditor, CellEditorValueAdapterFactory.getNullToEmptyStringTextAdapater());
tableViewerCreator.setCellModifier(new XmlCellModifier(tableViewerCreator));
}
use of org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode in project tdi-studio-se by Talend.
the class MapDataHelper method rebuildModelOutputs.
public void rebuildModelOutputs(List<IMetadataTable> outputMetadataTables, XmlMapData mapData) {
for (IMetadataTable meatadataTable : outputMetadataTables) {
String name = meatadataTable.getTableName();
OutputXmlTree outputTree = null;
for (OutputXmlTree out : mapData.getOutputTrees()) {
if (out.getName() != null && out.getName().equals(name)) {
outputTree = out;
break;
}
}
if (outputTree == null) {
outputTree = XmlmapFactory.eINSTANCE.createOutputXmlTree();
outputTree.setName(name);
mapData.getOutputTrees().add(outputTree);
}
List<IMetadataColumn> listColumns = meatadataTable.getListColumns();
if (listColumns != null) {
EList<OutputTreeNode> nodes = outputTree.getNodes();
for (int i = 0; i < listColumns.size(); i++) {
IMetadataColumn column = listColumns.get(i);
OutputTreeNode found = null;
int j = 0;
for (; j < nodes.size(); j++) {
OutputTreeNode node = nodes.get(j);
if (node.getName() != null && node.getName().equals(column.getLabel())) {
found = node;
break;
}
}
if (found != null) {
// set in case talend type changed in metadata
found.setType(column.getTalendType());
if (i != j) {
// do switch to keep the same sequence
OutputTreeNode temp = nodes.get(j);
nodes.remove(j);
nodes.add(i, temp);
}
} else {
found = XmlmapFactory.eINSTANCE.createOutputTreeNode();
found.setName(column.getLabel());
found.setType(column.getTalendType());
found.setNullable(column.isNullable());
found.setXpath(XmlMapUtil.getXPath(outputTree.getName(), found.getName(), found.getNodeType()));
nodes.add(i, found);
}
// add a default root for document
if (XmlMapUtil.DOCUMENT.equals(found.getType())) {
EList<TreeNode> children = found.getChildren();
if (children.isEmpty()) {
XmlMapUtil.detachConnectionsSouce(found, mapData);
TreeNode treeRoot = XmlmapFactory.eINSTANCE.createOutputTreeNode();
treeRoot.setName("root");
treeRoot.setType(XmlMapUtil.DEFAULT_DATA_TYPE);
treeRoot.setNodeType(NodeType.ELEMENT);
treeRoot.setXpath(XmlMapUtil.getXPath(found.getXpath(), treeRoot.getName(), treeRoot.getNodeType()));
treeRoot.setLoop(true);
treeRoot.setMain(true);
children.add(treeRoot);
}
} else // remove children and connections for children if not document
{
EList<TreeNode> children = found.getChildren();
if (!children.isEmpty()) {
XmlMapUtil.detachNodeConnections(found, mapData, true);
found.getChildren().clear();
}
}
}
if (nodes.size() > listColumns.size()) {
List unUsed = new ArrayList();
for (int i = listColumns.size(); i < nodes.size(); i++) {
OutputTreeNode node = nodes.get(i);
XmlMapUtil.detachConnectionsSouce(node, mapData);
unUsed.add(node);
}
nodes.removeAll(unUsed);
}
}
mapData.getOutputTrees().add(outputTree);
// re-build the connections in case any unnecessary connections are created because of previous bugs and
// can't be deleted
rebuildOutputNodesConnections(outputTree.getNodes(), mapData);
}
}
use of org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode in project tdi-studio-se by Talend.
the class MapDataHelper method rebuildOutputNodesConnections.
private void rebuildOutputNodesConnections(List<? extends TreeNode> treeNodes, XmlMapData mapData) {
for (TreeNode node : treeNodes) {
if (node != null) {
if (!node.getIncomingConnections().isEmpty()) {
if (!XmlMapUtil.isExpressionEditable(node)) {
node.setExpression("");
XmlMapUtil.detachConnectionsSouce(node, mapData, false);
}
}
if (!node.getChildren().isEmpty()) {
rebuildOutputNodesConnections(node.getChildren(), mapData);
}
}
}
}
use of org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode in project tdi-studio-se by Talend.
the class XMLMapperHelper method hasAggregateColumn.
private static boolean hasAggregateColumn(final INode xmlMapperNode) {
boolean hasAggregateColumn = false;
List<? extends IConnection> outConnections = (List<? extends IConnection>) xmlMapperNode.getOutgoingConnections();
XmlMapData xmlMapData = (XmlMapData) ElementParameterParser.getObjectValueXMLTree(xmlMapperNode);
if (xmlMapData != null && outConnections != null && outConnections.size() > 0) {
List<OutputXmlTree> outputTables = xmlMapData.getOutputTrees();
HashMap<String, IConnection> hNameToConnection = new HashMap<String, IConnection>();
for (IConnection connection : outConnections) {
hNameToConnection.put(connection.getName(), connection);
}
for (OutputXmlTree outputTable : outputTables) {
String tableName = outputTable.getName();
IConnection connection = hNameToConnection.get(tableName);
if (connection == null) {
continue;
}
List<TreeNode> editableNodes = new ArrayList<TreeNode>();
for (TreeNode node : outputTable.getNodes()) {
getEditableNodes(node, editableNodes);
}
for (TreeNode node : editableNodes) {
if (((OutputTreeNode) node).isAggregate()) {
hasAggregateColumn = true;
break;
}
}
}
}
return hasAggregateColumn;
}
Aggregations