use of org.talend.core.model.metadata.MetadataTable in project tesb-studio-se by Talend.
the class RestResponseSchemaController method createComboCommand.
@Override
public Command createComboCommand(SelectionEvent event) {
// Change the body type according to selected return body type
Command changePropertyCommand = super.createComboCommand(event);
Object newReturnType = null;
if (changePropertyCommand != null) {
newReturnType = ((PropertyChangeCommand) changePropertyCommand).getNewValue();
}
if (newReturnType == null) {
return null;
}
// get old metadata column
List<IMetadataTable> metadataList = ((INode) elem).getMetadataList();
IMetadataTable oldMetadataTable = null;
if (metadataList != null && metadataList.size() > 0) {
oldMetadataTable = metadataList.get(0);
} else {
metadataList = new ArrayList<IMetadataTable>();
((INode) elem).setMetadataList(metadataList);
}
// create new metadata column
IMetadataTable newMetadataTable = oldMetadataTable == null ? new MetadataTable() : oldMetadataTable.clone();
List<IMetadataColumn> listColumns = newMetadataTable.getListColumns();
if (listColumns == null) {
listColumns = new ArrayList<IMetadataColumn>();
newMetadataTable.setListColumns(listColumns);
}
IMetadataColumn bodyColumn = listColumns.size() > 0 ? listColumns.get(0) : new MetadataColumn();
bodyColumn.setId("body");
bodyColumn.setTalendType(newReturnType.toString());
listColumns.clear();
listColumns.add(bodyColumn);
metadataList.clear();
metadataList.add(newMetadataTable);
// construct change metadata command
ChangeMetadataCommand changeMetadataCommand = new ChangeMetadataCommand((INode) elem, null, oldMetadataTable, newMetadataTable);
// construct compound command by combining above 2 commands
CompoundCommand compoundCommand = new CompoundCommand();
compoundCommand.add(changePropertyCommand);
compoundCommand.add(changeMetadataCommand);
return compoundCommand;
}
Aggregations