001 package market;
002
003 /**
004 * The simplest implementation of ValueChecker. It only checks a String for emptiness, if wanted.<br>
005 * A VCDummy is used for text fields, that need to be a {@link market.swing.JTFCheckable} to allow
006 * access from outside the defining class, but for which no content checking is required.
007 */
008 public class VCDummy implements ValueChecker {
009
010 /**
011 * The identifier used by {@link #getErrorString()}.
012 */
013 protected String identifier;
014
015 /**
016 * Defines if an empty String is considered to be an error or not.
017 */
018 protected boolean mayBeEmpty;
019
020 /**
021 * @param identifier the identifier.
022 * @param mayBeEmpty <code>true</code> if an empty should be considered valid, otherwise <code>false</code>.
023 */
024 public VCDummy(String identifier, boolean mayBeEmpty) {
025 this.identifier = identifier;
026 this.mayBeEmpty = mayBeEmpty;
027 }
028
029 /**
030 * @param identifier the identifier.
031 */
032 public VCDummy(String identifier) {
033 this.identifier = identifier;
034 this.mayBeEmpty = false;
035 }
036
037 /**
038 * @param content the String to be checked.
039 * @return always <code>true</code> if {@link #mayBeEmpty} is <code>true</code>, otherwise it returns
040 * <code>true</code> if <code>content</code> is not empty.
041 */
042 public boolean isValidValue(String content) {
043 return (mayBeEmpty || !content.equals(""));
044 }
045
046 /**
047 * @return an error message if the String is empty when it shouldn't.
048 */
049 public String getErrorString() {
050 return "Fehlerhafte Eingabe im Feld " + identifier + ": Das Feld darf nicht leer sein.";
051 }
052 }