Databinding: How to add validator for cell editor? [message #528282] |
Mon, 19 April 2010 22:41 |
chengdong Messages: 17 Registered: July 2009 |
Junior Member |
|
|
Is it possible to add validations to cell editor? If possible, could anyone give me some hint? Thanks in advance.
BTW, I have looked at the ObservableValueEditingSupport, looks like I should override createBinding(IObservableValue target,IObservableValue model), however the dirty is not visible to subclass, which means saveCellEditorValue will do nothing:
// class ObservableValueEditingSupport{
boolean dirty = false;
...
protected Binding createBinding(IObservableValue target,
IObservableValue model) {
dirty = false;
Binding binding = dbc.bindValue(target, model, new UpdateValueStrategy(
UpdateValueStrategy.POLICY_CONVERT), null);
target.addChangeListener(new IChangeListener() {
public void handleChange(ChangeEvent event) {
dirty = true;
}
});
return binding;
}
...
final protected void saveCellEditorValue(CellEditor cellEditor,
ViewerCell cell) {
if (dirty) {
editingState.binding.updateTargetToModel();
dirty = false;
}
}
|
|
|
Re: Databinding: How to add validator for cell editor? [message #532515 is a reply to message #528282] |
Mon, 10 May 2010 11:18 |
budili Missing name Messages: 64 Registered: May 2010 |
Member |
|
|
hello,
that's not difficult, you are on the right way with the "ObservableValueEditingSupport"-Class.
You should to extend the class and define in the new class the cellEditor and the observable elements (override doCreateCellEditorObservable and doCreateElementObservable).
so, now you are ready, if you would not need the validators and conversters.
For the validators and converters you have to override the method:
- createBinding
for example:
@Override
protected final Binding createBinding(final IObservableValue target, final IObservableValue model)
{
final UpdateValueStrategy model2Target = new UpdateValueStrategy();
target2Model.setConverter(new AddMyConverter());
target2Model.setAfterGetValidator(new MySuperValidator(cellEditor));
model2Target.setConverter(new AddMy2Converter());
return DBC.bindValue(target, model, target2Model, model2Target);
}
ready ...
[Updated on: Mon, 10 May 2010 16:25] Report message to a moderator
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03817 seconds