|
Re: [DataBinding] Databinding support for Dialogs [message #518422 is a reply to message #515234] |
Mon, 01 March 2010 19:11 |
Matthew Hall Messages: 368 Registered: July 2009 |
Senior Member |
|
|
Tibor Bekesi wrote:
> Hi Everybody,
>
> There is a very useful class, WizardPageSupport that connects the
> validation result from the given data binding context to the given
> wizard page.
>
> However, I would like to use something very similar on my Eclipse Forms
> FormDialog to be able to display the validation results on the form
> heading area of my dialog.
>
> What do you suggest, how should I solve this?
>
> Or more generally: how to connect the validation results of a data
> binding context to a simple SWT Dialog or FormDialog?
I'm not familiar with FormDialog, but assuming we're talking about a
setMessage(String message, int messageType) setter method, it would be
very easy to implement your own value property, and then bind the
aggregate validation status to an observable created from that value
property, e.g.:
public class FormDialogMessageProperty extends SimpleValueProperty {
public Object getElementType() { return IStatus.class; }
protected void doGetValue(Object source) {
FormDialog dialog = (FormDialog) source;
return createStatus(dialog.getMessageType(), dialog.getMessage());
}
private IStatus createStatus(int messageType, String message) {
// convert from IMessageProvider message type constants to IStatus
// severity constants
}
protected void doSetValue(Object source, Object value) {
FormDialog dialog = (FormDialog) source;
IStatus status = (IStatue) value;
int messageType = toMessageType(status.getSeverity());
String message = status.getMessage();
dialog.setMessage(messageType, message);
}
public INativePropertyListener adaptListener(
ISimplePropertyListener listener) {
return null; // I'm assuming there is no listener API here
}
}
With this in place you could simply bind an AggregateValidationStatus to
the dialog message:
DataBindingContext dbc = ...
IObservableValue validationStatus = new AggregateValidationStatus(
dbc, AggregateValidationStatus.MAX_SEVERITY);
dbc.bindValue(new FormDialogMessageProperty().observe(dialog),
validationStatus);
You may also want to override the observe(Realm, Object) method in your
value property to hook a listener that disposes the returned observable
when the dialog is disposed.
Hope this helps,
Matthew
|
|
|
Powered by
FUDForum. Page generated in 0.02737 seconds