Databinding: How to add validator for cell editor? [message #528282] |
Mon, 19 April 2010 18:41  |
Eclipse User |
|
|
|
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 07:18   |
Eclipse User |
|
|
|
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 12:25] by Moderator
|
|
|
|
Re: Databinding: How to add validator for cell editor? [message #540990 is a reply to message #533010] |
Thu, 17 June 2010 17:46  |
Eclipse User |
|
|
|
Hi,
if you want only to set validators and convert to a cell editor,
you dont need to handle the dirty flag of the databinding framework. The framework done self the whole work.
I would suggest you to extend the ObservableValueEditingSupport-class and override the methods:
- doCreateCellEditorObservable
- doCreateElementObservable
- createBinding
In createBinding you have the possibility to set the converters and validators. Very easy concept.
Hope that helps.
Tim
|
|
|
Powered by
FUDForum. Page generated in 0.80382 seconds