use of org.talend.commons.ui.swt.advanced.dataeditor.button.AddAllPushButtonForExtendedTable in project tdi-studio-se by Talend.
the class PropertiesTableToolbarEditorView method createAddAllPushButton.
/*
* (non-Javadoc)
*
* @see org.talend.commons.ui.swt.advanced.dataeditor.ExtendedToolbarView#createAddAllPushButton()
*/
@Override
protected AddAllPushButton createAddAllPushButton() {
final PropertiesTableEditorModel tableEditorModel = (PropertiesTableEditorModel) getExtendedTableViewer().getExtendedControlModel();
if (!TableController.isNeedAddAllButton(tableEditorModel.getElemParameter())) {
return null;
}
return new AddAllPushButtonForExtendedTable(this.toolbar, getExtendedTableViewer()) {
@Override
public boolean getEnabledState() {
return super.getEnabledState() && (model == null || !model.getElemParameter().isBasedOnSubjobStarts());
}
@Override
protected List<Object> getObjectToAdd() {
if (!tableEditorModel.isButtonEnabled()) {
MessageDialog.openInformation(tableEditorModel.getTableViewer().getControl().getShell(), "Information", "All output columns have been added already");
return new ArrayList<Object>();
}
IElement element = tableEditorModel.getElement();
if (element != null && element instanceof INode) {
List<ColumnInfo> tableInputs = null;
IElementParameter param = tableEditorModel.getElemParameter();
String componentName = ((INode) element).getComponent().getName();
// prompt the dialog when clicking the button of "Add All".
if ("tStewardshipTaskOutput".equalsIgnoreCase(componentName)) {
//$NON-NLS-1$
if ("EXTRA_INFO".equals(param.getName())) {
//$NON-NLS-1$
tableInputs = promptForDefaultValue(tableEditorModel.getTableViewer().getControl().getShell(), param);
} else {
tableInputs = new ArrayList<ColumnInfo>();
}
} else {
// diplay a dialog for setting default values. see 0005416: When click Add All in a table, add
// the
// possibility to setup the default parameters value.
tableInputs = promptForDefaultValue(tableEditorModel.getTableViewer().getControl().getShell(), param);
}
if (tableInputs == null) {
return new ArrayList<Object>();
}
// default name //$NON-NLS-1$
String paramColumnsName = "COLUMN";
// default name //$NON-NLS-1$
String paramSizeName = "SIZE";
for (Object object : param.getListItemsValue()) {
if (object instanceof IElementParameter) {
IElementParameter tableParameter = (IElementParameter) object;
if (tableParameter.getFieldType().equals(EParameterFieldType.COLUMN_LIST)) {
paramColumnsName = tableParameter.getName();
}
if (tableParameter.getContext() != null && tableParameter.getContext().equals("LENGTH")) {
//$NON-NLS-1$
paramSizeName = tableParameter.getName();
}
}
}
INode node = (INode) element;
if (node.getMetadataList() != null && !node.getMetadataList().isEmpty()) {
IMetadataTable metadata = node.getMetadataList().get(0);
if (metadata.getListColumns() != null && !metadata.getListColumns().isEmpty()) {
List<Object> objects = new ArrayList<Object>();
for (IMetadataColumn column : metadata.getListColumns()) {
if (tableEditorModel.exist(column.getLabel())) {
continue;
}
Object entry = tableEditorModel.createNewEntry();
if (!(entry instanceof Map)) {
continue;
}
Map mapObject = (Map) entry;
if (mapObject.containsKey(paramColumnsName)) {
mapObject.put(paramColumnsName, column.getLabel());
}
if (mapObject.containsKey(paramSizeName)) {
if (column.getLength() != null) {
mapObject.put(paramSizeName, Integer.toString(column.getLength()));
}
}
// set default values
for (ColumnInfo col : tableInputs) {
Object defaultValue = col.defaultValue;
Object found = findDefaultName(column.getLabel(), col);
if (found != null && !"".equals(found)) {
defaultValue = found;
}
mapObject.put(col.parameter.getName(), defaultValue);
}
objects.add(entry);
}
return objects;
}
}
}
return Collections.EMPTY_LIST;
}
private List<ColumnInfo> promptForDefaultValue(Shell shell, IElementParameter param) {
List<ColumnInfo> tableInputs = new ArrayList<ColumnInfo>();
Object[] listItemsValue = param.getListItemsValue();
String[] displayNames = param.getListItemsDisplayName();
for (int i = 0; i < listItemsValue.length; i++) {
if (listItemsValue[i] instanceof IElementParameter) {
IElementParameter colParam = (IElementParameter) listItemsValue[i];
if (colParam.getFieldType().equals(EParameterFieldType.COLUMN_LIST)) {
continue;
}
ColumnInfo row = new ColumnInfo();
row.name = displayNames[i];
row.parameter = colParam;
tableInputs.add(row);
}
}
PromptDefaultValueDialog dialog = new PromptDefaultValueDialog(shell, tableInputs);
if (dialog.open() == Window.OK) {
return tableInputs;
} else {
return null;
}
}
};
}
Aggregations