A little bit later answer, but any way. Few days ago a faced this task also - text or combo boxes has to be used in one column for cell editing. Here are my implementation:
final GridInlineEditingTextOrCombo editing = new GridInlineEditingTextOrCombo(attributeTableGrid);
editing.addEditor(valueCol);
And custom GridInlineEditing implementation is as this:
/**
* Class intended to create GridInlineEditing functionality,
* but with two type of editors in one column - TextField or SimpleComboBox,
* depending of SnmpParameterDefDTO.getAllowedValues().
*/
class GridInlineEditingTextOrCombo extends GridInlineEditing<SnmpParameterDefDTO> {
IsField<String> textField = new TextField();
SimpleComboBox<String> simpleComboBox = new SimpleComboBox<String>(new StringLabelProvider<String>());
Grid.GridCell currentCell = null;
private boolean currentCellChanged = false;
IsField<String> currentCellEditor;
//ComboBox<String> comboBox = new ComboBox<String>();
public GridInlineEditingTextOrCombo(Grid<SnmpParameterDefDTO> editableGrid) {
super(editableGrid);
simpleComboBox.setEditable(false);
simpleComboBox.setAllowTextSelection(false);
simpleComboBox.setTriggerAction(ComboBoxCell.TriggerAction.ALL);
}
@Override
@SuppressWarnings("unchecked")
public <O> IsField<O> getEditor(ColumnConfig<SnmpParameterDefDTO, ?> columnConfig) {
IsField<O> field = super.getEditor(columnConfig);
if(field!=null ){
if(!currentCellChanged){
return (IsField<O>)currentCellEditor;
}else{
currentCellChanged = false;
SnmpParameterDefDTO param = this.editableGrid.getStore().get(this.currentCell.getRow());
if(param.getAllowedValues() == null || param.getAllowedValues().size() == 0){
currentCellEditor = (IsField<String>)field;
}else{
simpleComboBox.getStore().clear();
simpleComboBox.add(param.getAllowedValues());
currentCellEditor = simpleComboBox;
}
return (IsField<O>)currentCellEditor;
}
}
return null;
}
@Override
public <T> void addEditor(ColumnConfig<SnmpParameterDefDTO, T> columnConfig, IsField<T> field) {
throw new RuntimeException("You can not call this method. Please use addEditor(ColumnConfig<SnmpParameterDefDTO, T> columnConfig) instead");
}
public <T> void addEditor(ColumnConfig<SnmpParameterDefDTO, T> columnConfig) {
super.addEditor(columnConfig, (IsField<T>)textField);
}
@Override
public void startEditing(Grid.GridCell cell){
currentCell = cell;
currentCellChanged = true;
super.startEditing(cell);
}
It is rather workaround, not elegant implementation, but any way, it works fine