Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » Databinding: How to add validator for cell editor?
Databinding: How to add validator for cell editor? [message #528282] Mon, 19 April 2010 22:41 Go to next message
chengdong is currently offline chengdongFriend
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 Go to previous messageGo to next message
budili Missing name is currently offline budili Missing nameFriend
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

Re: Databinding: How to add validator for cell editor? [message #533010 is a reply to message #532515] Tue, 11 May 2010 20:06 Go to previous messageGo to next message
chengdong is currently offline chengdongFriend
Messages: 17
Registered: July 2009
Junior Member
Hi, budili:

Thank you for your reply.

One thing I am still not very clear, as I posted in my previous post, the dirty variable will control whether to save the cell editor value. In your impl, can you explain how do you change the dirty flag? Because editing suport depends on this to update model.

	final protected void saveCellEditorValue(CellEditor cellEditor,
			ViewerCell cell) {
		if (dirty) {
			editingState.binding.updateTargetToModel();
			dirty = false;
		}
	}



IMHO, it is probably better to subclass EditingSuport directly, and rewrite the YourObservableValueEditingSupport. (This may not be encouraged to do Sad )
Re: Databinding: How to add validator for cell editor? [message #540990 is a reply to message #533010] Thu, 17 June 2010 21:46 Go to previous message
Tim  is currently offline Tim Friend
Messages: 12
Registered: December 2009
Junior Member
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
Previous Topic:Set text color of Action
Next Topic:Wizard Progress sometimes does not work
Goto Forum:
  


Current Time: Thu Apr 25 09:31:35 GMT 2024

Powered by FUDForum. Page generated in 0.03268 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top