TitleAreaDialog using databinding validation to disable the OK button [message #647707] |
Fri, 07 January 2011 17:18  |
Eclipse User |
|
|
|
Hi Folks,
I needed to create a few simple dialogs with text fields to allow users to input data. Examples are like inputing a Persons details like forename, surname, age, address etc. The dialogs just have Ok and Cancel buttons.
Extending TitleAreaDialog I was able to create a dialog laid out as required, the validation I've done myself, disabling the OK button for erroneous data entries. Now I'd like to use JFace databinding on the dialog but have seen that the TitleAreaDialogSupport does not disable the OK button when a validation error occurs, it just shows up the error message.
I have tried using a WizardDialog with one page and changing the name of the Finish button to OK. This works but is surely not the way to go for my simple common use case.
I think it may be possible to extend TitleAreaDialogSupport to also disable the OK button. However the lack of OK button disablement on validation failure is such an obvious omission from TitleAreaDialogSupport that I think I'm missing the point somewhere. Maybe I should not be using TitleAreaDialog at all whenever validation is needed.
This is such a common GUI use case I wanted to check that I'm not doing more work than necessary.
thanks,
Martin.
|
|
|
|
|
Re: TitleAreaDialog using databinding validation to disable the OK button [message #647768 is a reply to message #647707] |
Sat, 08 January 2011 13:06   |
Eclipse User |
|
|
|
http://tomsondev.bestsolution.at/2011/01/08/enhanced-rcp-usa ge-of-titlearedialogsupport/
Am 07.01.11 23:18, schrieb Martin:
> Hi Folks,
>
> I needed to create a few simple dialogs with text fields to allow users
> to input data. Examples are like inputing a Persons details like
> forename, surname, age, address etc. The dialogs just have Ok and
> Cancel buttons.
>
> Extending TitleAreaDialog I was able to create a dialog laid out as
> required, the validation I've done myself, disabling the OK button for
> erroneous data entries. Now I'd like to use JFace databinding on the
> dialog but have seen that the TitleAreaDialogSupport does not disable
> the OK button when a validation error occurs, it just shows up the error
> message.
>
> I have tried using a WizardDialog with one page and changing the name of
> the Finish button to OK. This works but is surely not the way to go for
> my simple common use case.
>
> I think it may be possible to extend TitleAreaDialogSupport to also
> disable the OK button. However the lack of OK button disablement on
> validation failure is such an obvious omission from
> TitleAreaDialogSupport that I think I'm missing the point somewhere.
> Maybe I should not be using TitleAreaDialog at all whenever validation
> is needed.
> This is such a common GUI use case I wanted to check that I'm not doing
> more work than necessary.
>
> thanks,
> Martin.
|
|
|
Re: TitleAreaDialog using databinding validation to disable the OK button [message #647799 is a reply to message #647768] |
Sun, 09 January 2011 06:29  |
Eclipse User |
|
|
|
Thanks Tom,
I've gone with the solution below. I'll got to yours if I find problems with the code below later.
many thanks,
Martin.
public class TitleDialog extends TitleAreaDialog {
private static final Logger log = Logger.getLogger(TitleDialog.class);
public static final String title = "Enter the values for Stock Code and Name.";
private String message = null;
private int messageType;
public TitleDialog(Shell parentShell) {
super(parentShell);
log.debug("TitleDialog constructed");
}
@Override
public void setErrorMessage(String newErrorMessage) {
Button okButton = getButton(IDialogConstants.OK_ID);
if (okButton != null)
okButton.setEnabled(newErrorMessage == null);
super.setErrorMessage(newErrorMessage);
}
@Override
public void setMessage(String newMessage, int type){
log.debug("setMessage called with '" + newMessage + "'");
if (this.message == null){
this.message = newMessage;/// Done just once
this.messageType = type;
}
if (newMessage == null && this.message != null){
newMessage = this.message;
type = this.messageType;
}
super.setMessage(newMessage, type);
}
}
|
|
|
Powered by
FUDForum. Page generated in 0.11111 seconds