use of org.talend.core.model.metadata.builder.connection.MetadataColumn in project tdi-studio-se by Talend.
the class HL7MetadataEmfToolbarEditor method createMoveDownPushButton.
@Override
protected MoveDownPushButton createMoveDownPushButton() {
return new MoveDownPushButtonForExtendedTable(toolbar, extendedTableViewer) {
@Override
protected void afterCommandExecution(Command executedCommand) {
MetadataEmfTableEditor tableEditorModel = (MetadataEmfTableEditor) getExtendedTableViewer().getExtendedControlModel();
IStructuredSelection selection = (IStructuredSelection) ((HL7MultiSchemaUI) linker.getMainui()).getMetaTableViewer().getSelection();
Object selectedObj = selection.getFirstElement();
if (selectedObj != null) {
String key = ((IModel) selectedObj).getDisplayName();
List<MetadataColumn> metadataColumnList = tableEditorModel.getMetadataColumnList();
Map<String, List<MetadataColumn>> schemaRelationMap = linker.getManager().getSchemaRelationMap();
if (schemaRelationMap != null) {
List<MetadataColumn> schemas = new ArrayList<MetadataColumn>();
schemas.addAll(metadataColumnList);
schemaRelationMap.put(key, schemas);
}
}
linker.getMainui().redrawLinkers();
linker.getBackgroundRefresher().refreshBackground();
}
@Override
public boolean getEnabledState() {
// 13749
return super.getEnabledState() && !isRepository;
}
};
}
use of org.talend.core.model.metadata.builder.connection.MetadataColumn in project tdi-studio-se by Talend.
the class HL7UI method initLinkersByPrimitiveModels.
protected void initLinkersByPrimitiveModels(List<PrimitiveModel> pms) {
TableItem[] tableItems = this.linker.getTarget().getItems();
TreeItem[] treeItems = this.linker.getSource().getItems();
TreeItem sourceItem = null;
String sourceItemName = "";
Object targetItemData = null;
List<linkMapPropertis> allLinkProp = new ArrayList<linkMapPropertis>();
for (PrimitiveModel pm : pms) {
for (TableItem ti : tableItems) {
Object data = ti.getData();
MetadataColumn column = (MetadataColumn) data;
if (column.getOriginalField().equals(pm.getDisplayName())) {
sourceItemName = pm.getDisplayName();
sourceItem = findSourceItem(sourceItemName, treeItems);
targetItemData = ti.getData();
linkMapPropertis linkProp = new linkMapPropertis(sourceItem, targetItemData);
allLinkProp.add(linkProp);
}
}
}
for (linkMapPropertis linkProp : allLinkProp) {
linker.addLinks(linkProp.getSource(), linkProp.getSource().getData(), this.linker.getTarget(), linkProp.getTargetData());
}
}
use of org.talend.core.model.metadata.builder.connection.MetadataColumn in project tdi-studio-se by Talend.
the class DBTreeProvider method createColumns.
private void createColumns(RepositoryNode tableNode, IRepositoryViewObject repObj, Object currentTable, boolean isBuildIn) {
for (Object currentColumn : ((MetadataTable) currentTable).getColumns()) {
MetadataColumn metadataColumn = (MetadataColumn) currentColumn;
RepositoryNode columnNode = createMetacolumn(tableNode, repObj, metadataColumn, isBuildIn);
tableNode.getChildren().add(columnNode);
}
}
use of org.talend.core.model.metadata.builder.connection.MetadataColumn in project tdi-studio-se by Talend.
the class TableNode method isNodeSameToColumn.
/**
* Check if ColumnNode and Column are the same.
*
* @param node ColumnNode
* @param column MetadataColumnImpl
* @return isNodeSameToColumn
* @exception
*/
private boolean isNodeSameToColumn(ColumnNode node, MetadataColumnImpl column) {
SessionTreeNode sessionTreeNode = node.getSession();
TableColumnInfo[] tableColumnInfo = null;
try {
tableColumnInfo = sessionTreeNode.getMetaData().getColumnInfo(ptableInfo);
} catch (SQLException e) {
SqlBuilderPlugin.log(e.getMessage(), e);
return false;
}
// Retrive metadataColumns from Database
IMetadataConnection iMetadataConnection = ConvertionHelper.convert(connection);
List<TdColumn> metadataColumns = new ArrayList<TdColumn>();
metadataColumns = ExtractMetaDataFromDataBase.returnMetadataColumnsFormTable(iMetadataConnection, getLabelText());
Iterator iterate = metadataColumns.iterator();
while (iterate.hasNext()) {
MetadataColumn metadataColumn = (MetadataColumn) iterate.next();
for (TableColumnInfo info : tableColumnInfo) {
if (metadataColumn.getLabel().equals(node.getLabelText()) && info.getColumnName().equals(node.getLabelText())) {
boolean divergency = isEquivalent(metadataColumn, column);
metadataColumn.setDivergency(divergency);
return divergency;
}
}
}
return true;
}
use of org.talend.core.model.metadata.builder.connection.MetadataColumn in project tdi-studio-se by Talend.
the class JSONFileStep3Form method refreshMetaDataTable.
/**
* DOC ocarbone Comment method "refreshMetaData".
*
* @param csvArray
*/
public void refreshMetaDataTable(final CsvArray csvArray, List<SchemaTarget> schemaTarget, Boolean flag) {
informationLabel.setText(" " + "Guess successful");
List mcolumns = new ArrayList();
mcolumns.addAll(tableEditorView.getMetadataEditor().getMetadataColumnList());
// clear all items
tableEditorView.getMetadataEditor().removeAll();
List<MetadataColumn> columns = new ArrayList<MetadataColumn>();
String file = ((JSONFileConnection) this.connectionItem.getConnection()).getJSONFilePath();
if (isContextMode()) {
ContextType contextType = ConnectionContextHelper.getContextTypeForContextMode(connectionItem.getConnection(), connectionItem.getConnection().getContextName());
file = TalendQuoteUtils.removeQuotes(ConnectionContextHelper.getOriginalValue(contextType, file));
}
if (csvArray == null || csvArray.getRows().isEmpty()) {
return;
} else {
List<String[]> csvRows = csvArray.getRows();
String[] fields = csvRows.get(0);
int numberOfCol = fields.length;
// define the label to the metadata width the content of the first row
int firstRowToExtractMetadata = 0;
// the first rows is used to define the label of any metadata
String[] label = new String[numberOfCol];
for (int i = 0; i < numberOfCol; i++) {
label[i] = DEFAULT_LABEL + i;
if (firstRowToExtractMetadata == 0) {
if (schemaTarget.get(i).getTagName() != null && !schemaTarget.get(i).getTagName().equals("")) {
//$NON-NLS-1$
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
label[i] = "" + schemaTarget.get(i).getTagName().trim().replaceAll(" ", "_");
label[i] = MetadataToolHelper.validateColumnName(label[i], i);
}
}
// if (firstRowToExtractMetadata == 1) {
// String value = fields.get(i).getValue();
// if (!value.equals("")) {
// label[i] = value;
// }
// }
}
for (int i = 0; i < numberOfCol; i++) {
// define the first currentType and assimile it to globalType
String globalType = null;
int lengthValue = 0;
int precisionValue = 0;
int current = firstRowToExtractMetadata;
while (globalType == null) {
if (LanguageManager.getCurrentLanguage() == ECodeLanguage.JAVA) {
if (i >= csvRows.get(current).length) {
//$NON-NLS-1$
globalType = "id_String";
} else {
globalType = JavaDataTypeHelper.getTalendTypeOfValue(csvRows.get(current)[i]);
current++;
// if (current == csvRows.size()) {
// globalType = "id_String"; //$NON-NLS-1$
// }
}
} else {
if (i >= csvRows.get(current).length) {
//$NON-NLS-1$
globalType = "String";
} else {
globalType = PerlDataTypeHelper.getTalendTypeOfValue(csvRows.get(current)[i]);
current++;
// if (current == csvRows.size()) {
// globalType = "String"; //$NON-NLS-1$
// }
}
}
}
// for another lines
for (int f = firstRowToExtractMetadata; f < csvRows.size(); f++) {
fields = csvRows.get(f);
if (fields.length > i) {
String value = fields[i];
if (!value.equals("")) {
if (LanguageManager.getCurrentLanguage() == ECodeLanguage.JAVA) {
if (!JavaDataTypeHelper.getTalendTypeOfValue(value).equals(globalType)) {
globalType = JavaDataTypeHelper.getCommonType(globalType, JavaDataTypeHelper.getTalendTypeOfValue(value));
}
} else {
if (!PerlDataTypeHelper.getTalendTypeOfValue(value).equals(globalType)) {
globalType = PerlDataTypeHelper.getCommonType(globalType, PerlDataTypeHelper.getTalendTypeOfValue(value));
}
}
if (lengthValue < value.length()) {
lengthValue = value.length();
}
int positionDecimal = 0;
if (value.indexOf(',') > -1) {
positionDecimal = value.lastIndexOf(',');
precisionValue = lengthValue - positionDecimal;
} else if (value.indexOf('.') > -1) {
positionDecimal = value.lastIndexOf('.');
precisionValue = lengthValue - positionDecimal;
}
} else {
IPreferenceStore preferenceStore = null;
if (GlobalServiceRegister.getDefault().isServiceRegistered(IDesignerCoreUIService.class)) {
IDesignerCoreUIService designerCoreUiService = (IDesignerCoreUIService) GlobalServiceRegister.getDefault().getService(IDesignerCoreUIService.class);
preferenceStore = designerCoreUiService.getPreferenceStore();
}
if (preferenceStore != null && preferenceStore.getString(MetadataTypeLengthConstants.VALUE_DEFAULT_TYPE) != null && !preferenceStore.getString(MetadataTypeLengthConstants.VALUE_DEFAULT_TYPE).equals("")) {
//$NON-NLS-1$
globalType = preferenceStore.getString(MetadataTypeLengthConstants.VALUE_DEFAULT_TYPE);
if (preferenceStore.getString(MetadataTypeLengthConstants.VALUE_DEFAULT_LENGTH) != null && !preferenceStore.getString(MetadataTypeLengthConstants.VALUE_DEFAULT_LENGTH).equals("")) {
//$NON-NLS-1$
lengthValue = Integer.parseInt(preferenceStore.getString(MetadataTypeLengthConstants.VALUE_DEFAULT_LENGTH));
}
}
}
}
}
// define the metadataColumn to field i
MetadataColumn metadataColumn = ConnectionFactory.eINSTANCE.createMetadataColumn();
// hshen bug7249
//$NON-NLS-1$
metadataColumn.setPattern("\"dd-MM-yyyy\"");
// Convert javaType to TalendType
String talendType = null;
talendType = globalType;
if (globalType.equals(JavaTypesManager.FLOAT.getId()) || globalType.equals(JavaTypesManager.DOUBLE.getId())) {
metadataColumn.setPrecision(precisionValue);
} else {
metadataColumn.setPrecision(0);
}
metadataColumn.setTalendType(talendType);
metadataColumn.setLength(lengthValue);
// Check the label and add it to the table
metadataColumn.setLabel(tableEditorView.getMetadataEditor().getNextGeneratedColumnName(label[i]));
columns.add(i, metadataColumn);
}
}
if (!flag) {
for (int i = 0; i < columns.size(); i++) {
for (int j = 0; j < mcolumns.size(); j++) {
if (columns.get(i).getLabel().equals(((MetadataColumn) mcolumns.get(j)).getLabel())) {
columns.remove(i);
columns.add(i, (MetadataColumn) mcolumns.get(j));
}
}
}
}
tableEditorView.getMetadataEditor().addAll(columns);
checkFieldsValue();
tableEditorView.getTableViewerCreator().layout();
tableEditorView.getTableViewerCreator().getTable().deselectAll();
informationLabel.setText("Click to update schema preview");
}
Aggregations