
package uk.co.wingpath.gui;

/**
* This class implements {@link Verifier} by simply checking that something
* other than an empty string has been entered.
*/
public class NonEmptyVerifier
    implements Verifier
{
    private final String label;
    private final StatusBar statusBar;

    /**
    * Constructs a {@code NonEmptyVerifier}.
    * @param label label of the field being verified, for use in error
    * messages. May be {@code null}.
    * @param statusBar where to report errors. May be {@code null}.
    */
    public NonEmptyVerifier (String label, StatusBar statusBar)
    {
        this.label = label;
        this.statusBar = statusBar;
    }

    public String verify (String str, boolean isChanging)
    {
        if (isChanging)
        {
            if (statusBar != null)
                statusBar.clear ();
            return str;
        }
        str = str.trim ();
        if (str.equals (""))
        {
            String msg = "Value missing";
            if (label != null)
                msg = label + ": " + msg;
            statusBar.showError (msg);
            return null;
        }

        return str;
    }
}
