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 * ID for serialization.
012 */
013 private static final long serialVersionUID = -2470573985933440464L;
014
015 /**
016 * The identifier used by {@link #getErrorString()}.
017 */
018 protected String identifier;
019
020 /**
021 * Defines if an empty String is considered to be an error or not.
022 */
023 protected boolean mayBeEmpty;
024
025 /**
026 * @param identifier the identifier.
027 * @param mayBeEmpty <code>true</code> if an empty should be considered valid, otherwise <code>false</code>.
028 */
029 public VCDummy(String identifier, boolean mayBeEmpty) {
030 this.identifier = identifier;
031 this.mayBeEmpty = mayBeEmpty;
032 }
033
034 /**
035 * @param identifier the identifier.
036 */
037 public VCDummy(String identifier) {
038 this.identifier = identifier;
039 this.mayBeEmpty = false;
040 }
041
042 /**
043 * @param content the String to be checked.
044 * @return always <code>true</code> if {@link #mayBeEmpty} is <code>true</code>, otherwise it returns
045 * <code>true</code> if <code>content</code> is not empty.
046 */
047 public boolean isValidValue(String content) {
048 return (mayBeEmpty || !content.equals(""));
049 }
050
051 /**
052 * @return an error message if the String is empty when it shouldn't.
053 */
054 public String getErrorString() {
055 return "Fehlerhafte Eingabe im Feld " + identifier + ": Das Feld darf nicht leer sein.";
056 }
057 }