use of org.talend.core.model.metadata.builder.connection.MetadataColumn in project tdi-studio-se by Talend.
the class AbstractJSONFileStepForm method initMetadataTable.
protected void initMetadataTable(List<FOXTreeNode> list, EList columnList) {
int maxColumnsNumber = CoreUIPlugin.getDefault().getPreferenceStore().getInt(ITalendCorePrefConstants.MAXIMUM_AMOUNT_OF_COLUMNS_FOR_XML);
for (FOXTreeNode node : list) {
if (columnList.size() > maxColumnsNumber) {
return;
}
MetadataEmfTableEditor editor = new MetadataEmfTableEditor();
if (node instanceof Element) {
String label = node.getLabel();
if (!node.hasChildren() && label != null && !label.equals("")) {
String columnName = label;
if (columnName.contains(":")) {
//$NON-NLS-1$
//$NON-NLS-1$
columnName = columnName.split(":")[1];
}
columnName = columnName.replaceAll("[^a-zA-Z0-9]", "_");
String dataType = node.getDataType();
MetadataColumn metadataColumn = ConnectionFactory.eINSTANCE.createMetadataColumn();
metadataColumn.setLabel(editor.getNextGeneratedColumnName(columnName, columnList));
metadataColumn.setOriginalField(label);
metadataColumn.setTalendType(dataType);
columnList.add(metadataColumn);
node.setColumn(ConvertionHelper.convertToIMetaDataColumn(metadataColumn));
}
}
if (node instanceof Attribute) {
String label = node.getLabel();
if (label != null && !label.equals("")) {
String columnName = label;
if (columnName.contains(":")) {
//$NON-NLS-1$
//$NON-NLS-1$
columnName = columnName.split(":")[1];
}
columnName = columnName.replaceAll("[^a-zA-Z0-9]", "_");
String dataType = node.getDataType();
MetadataColumn metadataColumn = ConnectionFactory.eINSTANCE.createMetadataColumn();
metadataColumn.setLabel(editor.getNextGeneratedColumnName(columnName, columnList));
metadataColumn.setOriginalField(label);
metadataColumn.setTalendType(dataType);
columnList.add(metadataColumn);
node.setColumn(ConvertionHelper.convertToIMetaDataColumn(metadataColumn));
}
}
if (node.hasChildren()) {
List<FOXTreeNode> children = node.getChildren();
initMetadataTable(children, columnList);
}
}
}
use of org.talend.core.model.metadata.builder.connection.MetadataColumn in project tdi-studio-se by Talend.
the class JSONFileOutputStep2Form method updateJSONTreeViewer.
private void updateJSONTreeViewer() {
LinksManager<Item, Object, Tree, Object> linkManager = linker.getLinkManager();
List<LinkDescriptor<Item, Object, Tree, Object>> links = linkManager.getLinks();
for (int i = 0; i < links.size(); i++) {
LinkDescriptor<Item, Object, Tree, Object> linkDescriptor = links.get(i);
IExtremityLink<Item, Object> ex1 = linkDescriptor.getExtremity1();
IExtremityLink<Tree, Object> ex2 = linkDescriptor.getExtremity2();
MetadataColumn metaColumn = (MetadataColumn) ex1.getDataItem();
FOXTreeNode node = (FOXTreeNode) ex2.getDataItem();
if (ex1.getGraphicalObject() != null) {
Item item = ex1.getGraphicalObject();
if (!item.isDisposed() && metaColumn.equals(item.getData())) {
node.setColumn(ConvertionHelper.convertToIMetaDataColumn(metaColumn));
} else {
node.setColumn(null);
}
}
node.setDataType(metaColumn.getTalendType());
}
JSONViewer.refresh();
updateConnection();
}
use of org.talend.core.model.metadata.builder.connection.MetadataColumn in project tdi-studio-se by Talend.
the class GenerateSelectSQLAction method createTableSelect.
/**
* @return query string for full table select
*/
protected String createTableSelect() {
RepositoryNode node = (RepositoryNode) selectedNodes.get(0);
String fix = getPrePostfix(node);
String tablePrefix = getTablePrefix(node);
//$NON-NLS-1$
StringBuffer query = new StringBuffer("select ");
//$NON-NLS-1$
String sep = "";
EList columns = ((MetadataTableRepositoryObject) node.getObject()).getTable().getColumns();
Iterator it = columns.iterator();
if (columns.isEmpty()) {
//$NON-NLS-1$
query.append("*");
}
while (it.hasNext()) {
String column = ((MetadataColumn) it.next()).getOriginalField();
if (column == null || column.trim().equals("")) {
//$NON-NLS-1$
continue;
}
query.append(sep);
query.append(fix + column + fix);
//$NON-NLS-1$
sep = ", ";
}
//$NON-NLS-1$
query.append(" from ");
if (fix != null && !fix.trim().equals("")) {
//$NON-NLS-1$
if (tablePrefix == null || tablePrefix.equals("")) {
//$NON-NLS-1$
query.append(fix + ((SqlBuilderRepositoryObject) node.getObject()).getSourceName() + fix);
} else {
query.append(//$NON-NLS-1$
fix + tablePrefix + fix + "." + fix + ((SqlBuilderRepositoryObject) node.getObject()).getSourceName() + fix);
}
} else {
if (tablePrefix == null || tablePrefix.equals("")) {
//$NON-NLS-1$
query.append(((SqlBuilderRepositoryObject) node.getObject()).getSourceName());
} else {
//$NON-NLS-1$
query.append(tablePrefix + "." + ((SqlBuilderRepositoryObject) node.getObject()).getSourceName());
}
}
return query.toString();
}
use of org.talend.core.model.metadata.builder.connection.MetadataColumn in project tdi-studio-se by Talend.
the class MetadataRefreshAction method init.
/**
* DOC dev Comment method "init".
*/
public void init() {
IStructuredSelection selection = (IStructuredSelection) selectionProvider.getSelection();
repositorynodes.clear();
columnNodes.clear();
boolean flag = true;
for (Object object : selection.toList()) {
if (!((RepositoryNode) object).getProperties(EProperties.CONTENT_TYPE).equals(RepositoryNodeType.COLUMN)) {
this.setEnabled(false);
return;
}
MetadataColumn col = ((DBTreeProvider.MetadataColumnRepositoryObject) ((RepositoryNode) object).getObject()).getColumn();
if (col.getLabel().equals("")) {
//$NON-NLS-1$
this.setEnabled(false);
return;
}
if (col.isSynchronised()) {
if (!repositorynodes.isEmpty() && repositorynodes.get(0) != null && !SQLBuilderRepositoryNodeManager.getRoot(repositorynodes.get(0)).equals(SQLBuilderRepositoryNodeManager.getRoot(((RepositoryNode) object)))) {
this.setEnabled(false);
return;
}
repositorynodes.add((RepositoryNode) object);
this.setEnabled(true);
flag = false;
columnNodes.add(col);
}
}
if (flag) {
this.setEnabled(false);
return;
}
}
use of org.talend.core.model.metadata.builder.connection.MetadataColumn in project tdi-studio-se by Talend.
the class MetadataUtils method createColumn.
/**
* Create a column instance by <code>columnAttrMap</code>.
* <p>
* FIXME: will add more attributes support if needed.
*
* @param columnAttrMap
* @return
*/
private static MetadataColumn createColumn(Map<String, Object> columnAttrMap) {
MetadataColumn column = ConnectionFactory.eINSTANCE.createMetadataColumn();
Object columnNameObj = columnAttrMap.get(IMetadataTableConstants.COLUMN_NAME);
if (columnNameObj == null) {
// Column name must not be null.
return null;
}
column.setName(String.valueOf(columnNameObj));
column.setLabel(column.getName());
//$NON-NLS-1$
String columnType = "id_String";
Object columnTypeObj = columnAttrMap.get(IMetadataTableConstants.COLUMN_TYPE);
if (columnTypeObj != null) {
columnType = String.valueOf(columnTypeObj);
}
column.setTalendType(columnType);
return column;
}
Aggregations