use of org.talend.designer.scd.model.Type3Field in project tdi-studio-se by Talend.
the class ScdManager method createOutputSchema.
/**
* DOC chuang Comment method "createOutputSchema".
*
* @param unusedFields
*/
public void createOutputSchema() {
// adding the surrogate Keys column
Map<String, IMetadataColumn> surrogateKeysColumnMap = new HashMap<String, IMetadataColumn>();
List<IMetadataColumn> outputColumnsAll = getOutputColumns(component);
for (IMetadataColumn column : outputColumnsAll) {
if (column.isKey()) {
surrogateKeysColumnMap.put(column.getLabel(), column);
break;
}
}
// the unused columns must not be present in the output schema and also
// remove all generated column from
// output schema
Map<String, IMetadataColumn> outputColumns = removeUnusedAndGeneratedColumns(component.getMetadataList(), unusedFields);
IMetadataTable schema = component.getMetadataList().get(0);
// adding all used columns to output schema
Map<String, IMetadataColumn> inputColumnsMap = new HashMap<String, IMetadataColumn>();
List<IMetadataColumn> inputColumns = getInputColumns(component);
for (IMetadataColumn column : inputColumns) {
inputColumnsMap.put(column.getLabel(), column);
if (!unusedFields.contains(column.getLabel()) && outputColumns.get(column.getLabel()) == null) {
schema.getListColumns().add(cloneColumn(column, column.getLabel()));
}
}
// "current value" column
if (type3Table != null) {
for (Type3Field type3 : type3Table) {
if (outputColumns.get(type3.getPreviousValue()) != null || StringUtils.isEmpty(type3.getPreviousValue())) {
continue;
}
IMetadataColumn column = inputColumnsMap.get(type3.getCurrentValue());
IMetadataColumn previous = cloneColumn(column, type3.getPreviousValue());
outputColumns.put(previous.getLabel(), previous);
schema.getListColumns().add(previous);
}
}
// removeVersionFieldsFromOutput(outputColumns, schema, new String[] {
// versionData.getStartName(),
// versionData.getEndName(),
// versionData.getVersionName(), versionData.getActiveName() });
// for versionning columns {start, end} are datetime data type, version
// is an integer, active is a
// boolean
ECodeLanguage lang = LanguageManager.getCurrentLanguage();
if (type2Table != null && !type2Table.isEmpty()) {
// start date
IMetadataColumn startColumn = createMetadataColumn(outputColumns, schema, versionData.getStartName(), Date.class, lang);
if (startColumn != null) {
startColumn.setCustomId(1);
startColumn.setCustom(true);
}
// end date
IMetadataColumn endColumn = createMetadataColumn(outputColumns, schema, versionData.getEndName(), Date.class, lang);
if (endColumn != null) {
endColumn.setNullable(true);
endColumn.setCustomId(2);
endColumn.setCustom(true);
}
if (versionData.isVersionChecked()) {
IMetadataColumn versionColumn = createMetadataColumn(outputColumns, schema, versionData.getVersionName(), Integer.class, lang);
if (versionColumn != null) {
versionColumn.setCustomId(3);
versionColumn.setCustom(true);
}
}
if (versionData.isActiveChecked()) {
IMetadataColumn activeColumn = createMetadataColumn(outputColumns, schema, versionData.getActiveName(), Boolean.class, lang);
if (activeColumn != null) {
activeColumn.setCustomId(4);
activeColumn.setCustom(true);
}
}
}
fixKeyColumnsInOutputSchema(schema, inputColumnsMap, surrogateKeysColumnMap, lang);
// removed by TDI-30934
// sort column by name
// Collections.sort(schema.getListColumns(), new Comparator<IMetadataColumn>() {
//
// public int compare(IMetadataColumn o1, IMetadataColumn o2) {
//
// return o1.getLabel().compareTo(o2.getLabel());
// }
//
// });
}
use of org.talend.designer.scd.model.Type3Field in project tdi-studio-se by Talend.
the class ScdManager method updateType3Parameter.
public void updateType3Parameter(List<Type3Field> model) {
IElementParameter useL3 = paramsMap.get(ScdParameterConstants.USE_L3);
if (useL3 == null) {
return;
}
if (model == null || model.size() == 0) {
useL3.setValue(Boolean.FALSE);
} else {
useL3.setValue(Boolean.TRUE);
List<Map<String, String>> table = new ArrayList<Map<String, String>>();
for (Type3Field field : model) {
Map<String, String> row = new HashMap<String, String>();
row.put(ScdParameterConstants.L3_ITEM_CURRENT_VALUE, field.getCurrentValue());
row.put(ScdParameterConstants.L3_ITEM_PREV_VALUE, field.getPreviousValue());
table.add(row);
}
updateElementParameter(ScdParameterConstants.L3_FIELDS_PARAM_NAME, table);
}
}
use of org.talend.designer.scd.model.Type3Field in project tdi-studio-se by Talend.
the class Type3Section method onDropItems.
/*
* (non-Javadoc)
*
* @see org.talend.designer.scd.ui.IDragDropDelegate#onDropItems(java.lang.String, org.eclipse.swt.graphics.Point)
*/
public void onDropItems(String data, Point position) {
//$NON-NLS-1$
String[] items = data.split("\\|");
// skip items[0], which is the number of selected elements
for (int i = 1; i < items.length; i++) {
Type3Field field = new Type3Field();
// drop to current field
field.setCurrentValue(items[i]);
field.setPreviousValue(PREVIOUS_NAME_PREFIX + items[i]);
if (!scdManager.getTypeTable().contains(items[i])) {
scdManager.getTypeTable().add(items[i]);
} else {
continue;
}
tableModel.add(field);
}
tableViewer.setInput(tableModel);
}
use of org.talend.designer.scd.model.Type3Field in project tdi-studio-se by Talend.
the class ScdManager method reloadType3Parameter.
public void reloadType3Parameter() {
IElementParameter useL3 = paramsMap.get(ScdParameterConstants.USE_L3);
if (useL3 != null && useL3.getValue().equals(Boolean.TRUE)) {
IElementParameter l3FieldsParam = paramsMap.get(ScdParameterConstants.L3_FIELDS_PARAM_NAME);
type3Table = new ArrayList<Type3Field>();
List<Map<String, String>> values = (List<Map<String, String>>) l3FieldsParam.getValue();
for (Map<String, String> entry : values) {
String current = entry.get(ScdParameterConstants.L3_ITEM_CURRENT_VALUE);
String previous = entry.get(ScdParameterConstants.L3_ITEM_PREV_VALUE);
type3Table.add(new Type3Field(current, previous));
}
}
}
use of org.talend.designer.scd.model.Type3Field in project tdi-studio-se by Talend.
the class Type3Section method addToolbarListener.
@Override
protected void addToolbarListener() {
addEntryItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (inputColumns.size() > 0 && outputColumns.size() > 0) {
Type3Field field = new Type3Field(outputColumns.get(0), inputColumns.get(0));
tableModel.add(field);
tableViewer.setInput(tableModel);
}
}
});
removeEntryItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
int[] selection = tableViewer.getTable().getSelectionIndices();
if (selection == null || selection.length == 0) {
return;
}
tableViewer.cancelEditing();
for (int i = selection.length - 1; i >= 0; i--) {
tableModel.remove(selection[i]);
}
tableViewer.setInput(tableModel);
}
});
moveUpEntryItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
int[] selection = tableViewer.getTable().getSelectionIndices();
if (selection == null || selection.length == 0) {
return;
}
tableViewer.cancelEditing();
// indices of item which will be updated
List<Integer> updateIndices = new ArrayList<Integer>();
int[] newSelectionIndices = adjustIndicesUp(selection, tableModel, updateIndices);
// refresh
tableViewer.setInput(tableModel);
}
});
moveDownEntryItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
int[] selection = tableViewer.getTable().getSelectionIndices();
if (selection == null || selection.length == 0) {
return;
}
tableViewer.cancelEditing();
// indices of item which will be updated
List<Integer> updateIndices = new ArrayList<Integer>();
int[] newSelectionIndices = adjustIndicesDown(selection, tableModel, updateIndices);
// refresh
tableViewer.setInput(tableModel);
}
});
}
Aggregations