PDA

View Full Version : Update SimpleComboBox in Grid



jazzer
31 Aug 2009, 4:50 AM
I have a SimpleComboBox editor in a grid that is populated from a database (see below). When a new project is added by the user, I query the db, get an updated project list and repopulate the project list and rebuild the new editor. I can't seem to get the grid to dynamically accept the new, updated combo box - it always continues to use the original combo box.

Thanks!


/// Reconfigure the grid

grid.getColumnModel().setEditor(6, Project.buildProjectComboBox());

/// I also tried this

grid.reconfigure(store, new ColumnModel(getNewListOfColumnConfigs()));

/// Build the editor from a project list

private static List<Project> projects = new ArrayList<Project>();

public static CellEditor buildProjectComboBox() {
final SimpleComboBox<String> combo = new SimpleComboBox<String>();
combo.setForceSelection(true);
combo.setTriggerAction(TriggerAction.ALL);
for (Project p : projects) {
combo.add(p.getName());
}
CellEditor editor = new CellEditor(combo) {
@Override
public Object preProcessValue(Object value) {
if (value == null) {
return value;
}
return combo.findModel(value.toString());
}

@Override
public Object postProcessValue(Object value) {
if (value == null) {
return value;
}
return ((ModelData) value).get("value");
}
};
return editor;
}

Arno.Nyhm
31 Aug 2009, 5:15 AM
my ideas:

a) hold a reference to your combobox. and then remove and add projects at this combobox reference
b) use a normal combobox with a MemoryProxy. and then switch the data in this memoryproxy. then the data should updated.

jazzer
31 Aug 2009, 6:04 AM
I tried (a) - making the combo static and changing the values in the combo - that worked fine. Thanks.

Arno.Nyhm
31 Aug 2009, 6:23 AM
:-)