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;
}
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;
}