use of org.talend.designer.core.ui.editor.properties.macrowidgets.tableeditor.PromptDefaultValueDialog.ColumnInfo 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;
}
}
};
}
use of org.talend.designer.core.ui.editor.properties.macrowidgets.tableeditor.PromptDefaultValueDialog.ColumnInfo in project tdi-studio-se by Talend.
the class PropertiesTableToolbarEditorView method createAddPushButton.
/*
* (non-Javadoc)
*
* @see org.talend.core.ui.extended.ExtendedToolbarView#createAddPushButton()
*/
@Override
protected AddPushButton createAddPushButton() {
final AddPushButton addPushButton = new AddPushButtonForExtendedTable(this.toolbar, getExtendedTableViewer()) {
@Override
public boolean getEnabledState() {
if (model != null && !model.getElemParameter().getElement().isReadOnly() && (model.getElemParameter().getName().equals("HADOOP_ADVANCED_PROPERTIES") || model.getElemParameter().getName().equals("HBASE_PARAMETERS") || model.getElemParameter().getName().equals("SPARK_ADVANCED_PROPERTIES")) && !model.getElemParameter().isRepositoryValueUsed()) {
return true;
}
return super.getEnabledState() && (model == null || !model.getElemParameter().isBasedOnSubjobStarts());
}
@Override
protected Object getObjectToAdd() {
PropertiesTableEditorModel tableEditorModel = (PropertiesTableEditorModel) getExtendedTableViewer().getExtendedControlModel();
if (!tableEditorModel.isButtonEnabled()) {
MessageDialog.openInformation(tableEditorModel.getTableViewer().getControl().getShell(), "Information", "All output columns have been added already");
return null;
}
Object newEntry = tableEditorModel.createNewEntry();
if (tableEditorModel.isAggregateRow() && newEntry instanceof Map) {
List<ColumnInfo> tableInputs = new ArrayList<ColumnInfo>();
String[] displayNames = tableEditorModel.getElemParameter().getListItemsDisplayName();
Object[] itemsValue = tableEditorModel.getElemParameter().getListItemsValue();
// default name //$NON-NLS-1$
String paramColumnsName = "COLUMN";
for (int i = 0; i < itemsValue.length; i++) {
if (itemsValue[i] instanceof IElementParameter) {
IElementParameter tableParameter = (IElementParameter) itemsValue[i];
if (tableParameter.getFieldType().equals(EParameterFieldType.COLUMN_LIST)) {
paramColumnsName = tableParameter.getName();
} else {
ColumnInfo row = new ColumnInfo();
row.name = displayNames[i];
row.parameter = tableParameter;
row.defaultValue = "";
tableInputs.add(row);
}
}
}
Node node = (Node) tableEditorModel.getElement();
String outputTableName = null;
if (node.getMetadataList() != null && !node.getMetadataList().isEmpty()) {
IMetadataTable metadata = node.getMetadataList().get(0);
if (metadata.getListColumns() != null) {
for (IMetadataColumn column : metadata.getListColumns()) {
if (!tableEditorModel.exist(column.getLabel())) {
outputTableName = column.getLabel();
break;
}
}
}
}
if (outputTableName != null) {
Map mapObject = (Map) newEntry;
if (mapObject.containsKey(paramColumnsName)) {
mapObject.put(paramColumnsName, outputTableName);
}
for (ColumnInfo col : tableInputs) {
Object defaultValue = col.defaultValue;
Object found = findDefaultName(outputTableName, col);
if (found != null && !"".equals(found)) {
defaultValue = found;
}
if (defaultValue != null && !"".equals(defaultValue)) {
mapObject.put(col.parameter.getName(), defaultValue);
}
}
}
}
return newEntry;
}
};
// TDI-6568, after added, fire change
addPushButton.addListener(getPropertyChangeListener(), false);
return addPushButton;
}
Aggregations