use of org.talend.core.model.metadata.MetadataColumn in project tdi-studio-se by Talend.
the class InputTable method initFromExternalData.
/*
* (non-Javadoc)
*
* @see
* org.talend.designer.dbmap.model.table.AbstractInOutTable#initFromExternalData(org.talend.designer.dbmap.external
* .data.ExternalMapperTable)
*/
@Override
public void initFromExternalData(ExternalDbMapTable externalMapperTable) {
boolean isAliasTable = externalMapperTable != null && externalMapperTable.getAlias() != null;
if (isAliasTable) {
// dbmap table is alias
setMetadataTable(connection.getTable().clone());
} else if (connection != null) {
// dbmap table references a physical table
setMetadataTable(connection.getTable());
}
super.initFromExternalData(externalMapperTable);
List<IMetadataColumn> columns = getMetadataTable().getListColumns();
Map<String, ExternalDbMapEntry> nameToPerTabEntry = new HashMap<String, ExternalDbMapEntry>();
if (externalMapperTable != null && externalMapperTable.getMetadataTableEntries() != null) {
for (ExternalDbMapEntry perTableEntry : externalMapperTable.getMetadataTableEntries()) {
nameToPerTabEntry.put(perTableEntry.getName(), perTableEntry);
}
}
ArrayList<IMetadataColumn> columnsToRemove = new ArrayList<IMetadataColumn>();
for (IMetadataColumn column : columns) {
InputColumnTableEntry inputEntry = (InputColumnTableEntry) getNewTableEntry(column);
ExternalDbMapEntry externalMapperTableEntry = nameToPerTabEntry.get(inputEntry.getMetadataColumn().getLabel());
// Entry match with current column
if (externalMapperTableEntry != null) {
fillInputEntry(inputEntry, externalMapperTableEntry);
nameToPerTabEntry.remove(externalMapperTableEntry.getName());
}
if (externalMapperTableEntry != null || !isAliasTable) {
dataMapTableEntries.add(inputEntry);
} else {
columnsToRemove.add(column);
}
}
columns.removeAll(columnsToRemove);
// create unmatching entries
for (ExternalDbMapEntry perTableEntry : nameToPerTabEntry.values()) {
MetadataColumn column = new MetadataColumn();
column.setLabel(perTableEntry.getName());
InputColumnTableEntry inputEntry = (InputColumnTableEntry) getNewTableEntry(column);
ExternalDbMapEntry externalMapperTableEntry = nameToPerTabEntry.get(inputEntry.getMetadataColumn().getLabel());
fillInputEntry(inputEntry, externalMapperTableEntry);
dataMapTableEntries.add(inputEntry);
columns.add(column);
}
if (externalMapperTable != null) {
joinType = mapperManager.getCurrentLanguage().getJoin(externalMapperTable.getJoinType());
if (joinType == null) {
joinType = mapperManager.getCurrentLanguage().getAvailableJoins()[0];
}
alias = externalMapperTable.getAlias();
tableName = externalMapperTable.getTableName() != null ? externalMapperTable.getTableName() : connection.getName();
}
}
use of org.talend.core.model.metadata.MetadataColumn in project tdi-studio-se by Talend.
the class TabFolderEditors method addListenersToOutputButtons.
/**
* DOC amaumont Comment method "addListenersToInputButtons".
*/
private void addListenersToOutputButtons() {
MetadataToolbarEditorView toolBar = outputMetaEditor.getToolBar();
outputToolBarButtons = toolBar.getButtons();
beforeCommandListenerForOutputButtons = new IExtendedButtonListener() {
@Override
public void handleEvent(ExtendedButtonEvent event) {
// TableViewerCreator tableViewerCreator =
// mapperManager.getUiManager().getCurrentSelectedOutputTableView()
// .getTableViewerCreatorForColumns();
// if (tableViewerCreator != null) {
// tableViewerCreator.applyActivatedCellEditor();
// }
}
};
for (ExtendedPushButton extendedPushButton : outputToolBarButtons) {
extendedPushButton.addListener(beforeCommandListenerForOutputButtons, true);
if (extendedPushButton instanceof RemovePushButton) {
removeButton = (RemovePushButtonForExtendedTable) extendedPushButton;
}
}
if (removeButton != null) {
final TableViewerCreator tableViewerCreator = removeButton.getExtendedTableViewer().getTableViewerCreator();
tableViewerCreator.getSelectionHelper().addAfterSelectionListener(new ILineSelectionListener() {
@Override
public void handle(LineSelectionEvent e) {
for (TableItem item : tableViewerCreator.getTable().getSelection()) {
if (item.getData() instanceof MetadataColumn) {
MetadataColumn column = (MetadataColumn) item.getData();
removeButton.getButton().setEnabled(!column.isCustom());
break;
}
}
}
});
}
this.addDisposeListener(new DisposeListener() {
/*
* (non-Javadoc)
*
* @see org.eclipse.swt.events.DisposeListener#widgetDisposed(org.eclipse.swt.events.DisposeEvent)
*/
@Override
public void widgetDisposed(DisposeEvent e) {
for (ExtendedPushButton extendedPushButton : outputToolBarButtons) {
extendedPushButton.removeListener(beforeCommandListenerForOutputButtons, true);
}
}
});
}
use of org.talend.core.model.metadata.MetadataColumn in project tdi-studio-se by Talend.
the class MetadataEmfFactory method setMetadataTypeCommon.
@SuppressWarnings("unchecked")
private void setMetadataTypeCommon(final MetadataType metadataType) {
this.metadataType = metadataType;
IMetadataColumn metaCol;
ColumnType colType;
EList listColType;
List<IMetadataColumn> listMetadataColumn;
metadataTable.setComment(metadataType.getComment());
metadataTable.setTableName(metadataType.getName());
metadataTable.setLabel(metadataType.getLabel());
metadataTable.setTableType(metadataType.getType());
EMap<String, String> properties = metadataType.getAdditionalProperties();
if (properties != null) {
for (Map.Entry<String, String> entry : properties.entrySet()) {
metadataTable.getAdditionalProperties().put(entry.getKey(), entry.getValue());
}
}
if (metadataType.getConnector() != null) {
metadataTable.setAttachedConnector(metadataType.getConnector());
} else {
metadataTable.setAttachedConnector(EConnectionType.FLOW_MAIN.getName());
}
listColType = metadataType.getColumn();
listMetadataColumn = new ArrayList<IMetadataColumn>();
for (int i = 0; i < listColType.size(); i++) {
colType = (ColumnType) listColType.get(i);
metaCol = new MetadataColumn();
metaCol.setComment(colType.getComment());
metaCol.setKey(colType.isKey());
metaCol.setNullable(colType.isNullable());
if (colType.getLength() >= 0) {
metaCol.setLength(new Integer(colType.getLength()));
} else {
metaCol.setLength(null);
}
if (colType.getOriginalLength() >= 0) {
metaCol.setOriginalLength(new Integer(colType.getOriginalLength()));
} else {
metaCol.setOriginalLength(null);
}
if (colType.getAdditionalField().size() > 0) {
Iterator it = colType.getAdditionalField().keySet().iterator();
while (it.hasNext()) {
String key = (String) it.next();
metaCol.getAdditionalField().put(key, (String) colType.getAdditionalField().get(key));
}
}
metaCol.setLabel(colType.getName());
if (colType.getPrecision() >= 0) {
metaCol.setPrecision(new Integer(colType.getPrecision()));
} else {
metaCol.setPrecision(null);
}
metaCol.setTalendType(colType.getType());
metaCol.setType(colType.getSourceType());
metaCol.setPattern(colType.getPattern());
metaCol.setDefault(colType.getDefaultValue());
metaCol.setRelatedEntity(colType.getRelatedEntity());
metaCol.setRelationshipType(colType.getRelationshipType());
if (colType.getOriginalDbColumnName() == null) {
metaCol.setOriginalDbColumnName(colType.getName());
} else {
metaCol.setOriginalDbColumnName(colType.getOriginalDbColumnName());
}
metaCol.setUsefulColumn(colType.isUsefulColumn());
listMetadataColumn.add(metaCol);
}
metadataTable.setListColumns(listMetadataColumn);
List<String> columnNames = new ArrayList<String>();
for (IMetadataColumn column : listMetadataColumn) {
columnNames.add(column.getLabel());
}
metadataTable.setOriginalColumns(columnNames);
}
use of org.talend.core.model.metadata.MetadataColumn in project tdi-studio-se by Talend.
the class MapperManager method addRejectOutput.
public void addRejectOutput() {
String baseName = ERROR_REJECT;
IProcess process = getAbstractMapComponent().getProcess();
String tableName = baseName;
if (!process.checkValidConnectionName(baseName) && process instanceof IProcess2) {
final String uniqueName = ((IProcess2) process).generateUniqueConnectionName("row", baseName);
tableName = uniqueName;
((IProcess2) process).addUniqueConnectionName(uniqueName);
} else if (process instanceof IProcess2) {
tableName = baseName;
((IProcess2) process).addUniqueConnectionName(baseName);
}
IMetadataTable metadataTable = getNewMetadataTable();
metadataTable.setTableName(tableName);
MetadataColumn errorMessageCol = new MetadataColumn();
errorMessageCol.setLabel(ERROR_REJECT_MESSAGE);
errorMessageCol.setTalendType(DesignerPlugin.getDefault().getPreferenceStore().getString(MetadataTypeLengthConstants.FIELD_DEFAULT_TYPE));
errorMessageCol.setNullable(true);
errorMessageCol.setOriginalDbColumnName(ERROR_REJECT_MESSAGE);
errorMessageCol.setReadOnly(true);
errorMessageCol.setCustom(true);
errorMessageCol.setCustomId(0);
metadataTable.getListColumns().add(errorMessageCol);
MetadataColumn errorStackTrace = new MetadataColumn();
errorStackTrace.setLabel(ERROR_REJECT_STACK_TRACE);
errorStackTrace.setTalendType(DesignerPlugin.getDefault().getPreferenceStore().getString(MetadataTypeLengthConstants.FIELD_DEFAULT_TYPE));
errorStackTrace.setNullable(true);
errorStackTrace.setOriginalDbColumnName(ERROR_REJECT_STACK_TRACE);
errorStackTrace.setReadOnly(true);
errorStackTrace.setCustom(true);
errorStackTrace.setCustomId(1);
metadataTable.getListColumns().add(errorStackTrace);
OutputTable abstractDataMapTable = new OutputTable(this, metadataTable, tableName);
abstractDataMapTable.setErrorRejectTable(true);
abstractDataMapTable.initFromExternalData(null);
TablesZoneView tablesZoneViewOutputs = uiManager.getTablesZoneViewOutputs();
DataMapTableView rejectDataMapTableView = uiManager.createNewOutputTableView(null, abstractDataMapTable, tablesZoneViewOutputs);
tablesZoneViewOutputs.setSize(tablesZoneViewOutputs.computeSize(SWT.DEFAULT, SWT.DEFAULT));
List<DataMapTableView> outputsTablesView = uiManager.getOutputsTablesView();
int sizeList = outputsTablesView.size();
for (int i = 0; i < sizeList; i++) {
if (i + 1 < sizeList) {
FormData formData = (FormData) outputsTablesView.get(i + 1).getLayoutData();
formData.top = new FormAttachment(outputsTablesView.get(i));
}
}
CustomTableManager.addCustomManagementToTable(uiManager.getOutputMetaEditorView(), true);
tablesZoneViewOutputs.setSize(tablesZoneViewOutputs.computeSize(SWT.DEFAULT, SWT.DEFAULT));
tablesZoneViewOutputs.layout();
uiManager.moveOutputScrollBarZoneToMax();
uiManager.refreshBackground(true, false);
uiManager.selectDataMapTableView(rejectDataMapTableView, true, false);
}
use of org.talend.core.model.metadata.MetadataColumn in project tdi-studio-se by Talend.
the class MetadataExtPasteCommand method createPastableBeansList.
@Override
public List createPastableBeansList(ExtendedTableModel extendedTable, List copiedObjectsList) {
ArrayList list = new ArrayList();
ArrayList countList = new ArrayList();
ArrayList<String> labelsExisted = getLabelsExisted(extendedTable);
for (Object current : copiedObjectsList) {
if (current instanceof IMetadataColumn) {
IMetadataColumn copy = ((IMetadataColumn) current).clone();
String nextGeneratedColumnName = ((MetadataTableEditor) extendedTable).getNextGeneratedColumnName(copy.getLabel());
if (labelsExisted.contains(nextGeneratedColumnName)) {
nextGeneratedColumnName = validateColumnName(nextGeneratedColumnName, labelsExisted);
}
labelsExisted.add(nextGeneratedColumnName);
copy.setLabel(nextGeneratedColumnName);
if (copy instanceof MetadataColumnExt) {
list.add(copy);
} else {
MetadataColumnExt metadataColumnExt = new MetadataColumnExt((MetadataColumn) copy);
metadataColumnExt.setFunction(functionManagerExt.getDefaultFunction(metadataColumnExt, metadataColumnExt.getTalendType()));
list.add(metadataColumnExt);
}
} else if (current instanceof org.talend.core.model.metadata.builder.connection.MetadataColumn) {
MetadataTableEditor tableEditor = (MetadataTableEditor) extendedTable;
org.talend.core.model.metadata.builder.connection.MetadataColumn metadataColumn = (org.talend.core.model.metadata.builder.connection.MetadataColumn) current;
String nextGeneratedColumnName = metadataColumn.getLabel();
//$NON-NLS-1$
String tempNewColumnName = "";
boolean iMetaColumnUnique = false;
boolean metaColumnUnique = false;
while (iMetaColumnUnique == false || metaColumnUnique == false) {
nextGeneratedColumnName = tableEditor.getNextGeneratedColumnName(nextGeneratedColumnName, null);
iMetaColumnUnique = true;
metaColumnUnique = false;
if (list.size() == 0)
metaColumnUnique = true;
else {
tempNewColumnName = this.getUniqueString(list, nextGeneratedColumnName);
if (tempNewColumnName.equals(nextGeneratedColumnName))
metaColumnUnique = true;
else {
metaColumnUnique = false;
nextGeneratedColumnName = tempNewColumnName;
}
}
}
org.talend.core.model.metadata.builder.connection.MetadataColumn newColumnCopy = new ConnectionFactoryImpl().copy(metadataColumn, nextGeneratedColumnName);
IMetadataColumn copy = (ConvertionHelper.convertToIMetaDataColumn(newColumnCopy)).clone();
copy.setLabel(nextGeneratedColumnName);
MetadataColumnExt metadataColumnExt = new MetadataColumnExt((MetadataColumn) copy);
metadataColumnExt.setFunction(functionManagerExt.getDefaultFunction(metadataColumnExt, metadataColumnExt.getTalendType()));
list.add(metadataColumnExt);
countList.add(nextGeneratedColumnName);
}
}
return list;
}
Aggregations