PDA

View Full Version : EditorGrid - ComboBox - Button -How to enable/disable button depending ComboBox value



ashly.jos@gmail.com
7 Apr 2011, 1:19 AM
Hi All,

I have combo box in one column and button in another. Depending on the value selected in the combo box, I need to make the button enabled/disabled. How do I do that?



final SimpleComboBox<String> combo = new SimpleComboBox<String>();
combo.setForceSelection(true);
combo.setTriggerAction(TriggerAction.ALL);
combo.add("role 1");
combo.add("role 2");
combo.add("role 3");

combo.addSelectionChangedListener(new SelectionChangedListener<SimpleComboValue<String>>() {

@Override
public void selectionChanged(SelectionChangedEvent<SimpleComboValue<String>> se) {
Info.display("Info", "Selection changed to " + (String) se.getSelectedItem().get("value"));
}
});

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

column = new ColumnConfig();
column.setId("role");
column.setHeader("Role");
column.setWidth(80);
column.setEditor(editor);
configs.add(column);



/*************************************************************************/
GridCellRenderer buttonRenderer = new GridCellRenderer() {

public Object render(final ModelData model, String property, ColumnData config, final int rowIndex, int colIndex, ListStore store, Grid grid) {
Button b = new Button("Countries", new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
if(model instanceof UserDTO){
Info.display("infor", "cooooll Button clicked: " + ((UserDTO) model).getFirstName());
} else {
Info.display("infor", "Button clicked: " + rowIndex);
}

}
});
b.setWidth(grid.getColumnModel().getColumnWidth(colIndex) - 10);
b.setToolTip("Click for more information");
if(model instanceof UserDTO){
UserDTO user = (UserDTO) model;
if(user != null && "Marketer".equalsIgnoreCase(user.getRole())){
b.setEnabled(false);
}
}

return b;
}

};

/******************************************************/
column = new ColumnConfig();
column.setId("countries");
column.setHeader("Countries");
column.setWidth(100);
column.setRenderer(buttonRenderer);
configs.add(column);


Thanks in advance,
-ash