Changeset 5543 for branches/OmeroEditor/src/fields/Field.java
- Timestamp:
- 07/17/08 16:32:21 (4 months ago)
- Files:
-
- 1 modified
-
branches/OmeroEditor/src/fields/Field.java (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/OmeroEditor/src/fields/Field.java
r5536 r5543 26 26 import java.util.HashMap; 27 27 28 import tree.DataFieldConstants; 28 29 29 public class Field { 30 31 public class Field 32 implements IField { 30 33 31 34 HashMap<String, String> allAttributesMap; 32 35 36 /** 37 * The "Value" of the field. 38 * This could be a simple string, or a mixture of dates, times etc. 39 * It represents the experimental parameters that are stored by this 40 * field. 41 */ 42 private IFieldValue fieldValue; 43 33 44 public Field() { 34 this("untitled", "no value");45 this("untitled", null, DataFieldConstants.FIXED_PROTOCOL_STEP); 35 46 } 36 47 37 public Field(String name, String value ) {48 public Field(String name, String value, String fieldType) { 38 49 39 50 allAttributesMap = new HashMap<String, String>(); 40 51 41 setAttribute("name", name); 42 setAttribute("value", value); 52 fieldValue = FieldValueFactory.getFieldValue(fieldType); 53 54 setAttribute(DataFieldConstants.ELEMENT_NAME, name); 55 setAttribute(DataFieldConstants.VALUE, value); 43 56 } 44 57 45 58 public String getAttribute(String name) { 59 //System.out.println("Field getAttribute()"); 60 if (fieldValue.isValueAttribute(name)) { 61 return fieldValue.getAttribute(name); 62 } 63 46 64 return allAttributesMap.get(name); 47 65 } 48 66 49 67 public void setAttribute(String name, String value) { 68 System.out.println("Field setAttribute() " + name + " = " + value); 69 if (fieldValue.isValueAttribute(name)) { 70 fieldValue.setAttribute(name, value); 71 } 50 72 allAttributesMap.put(name, value); 51 73 } 52 74 53 75 public String toString() { 54 return getAttribute("name") + ": " + getAttribute("value"); 76 return getAttribute(DataFieldConstants.ELEMENT_NAME) + ": " + 77 getAttribute(DataFieldConstants.VALUE); 78 } 79 80 public boolean isAttributeTrue(String attributeName) { 81 String value = getAttribute(attributeName); 82 return DataFieldConstants.TRUE.equals(value); 83 } 84 85 public IFieldValue getValueObject() { 86 return fieldValue; 87 } 88 89 /** 90 * Gets the names of the attributes where this field stores its "value"s. 91 * This is used eg. (if a single value is returned) 92 * as the destination to copy the default value when defaults are loaded. 93 * Also used by EditClearFields to set all values back to null. 94 * This method delegates to the Value object for this field. 95 * 96 * @return the names of the attributes that holds the "value" of this field 97 */ 98 public String[] getValueAttributes() { 99 return fieldValue.getValueAttributes(); 100 } 101 102 /** 103 * This method tests to see whether the field has been filled out. 104 * ie, Has the user entered a "valid" value into the Form. 105 * For fields that have a single 'value', this method will return true if 106 * that value is filled (not null). 107 * For fields with several attributes, it depends on what is considered 'filled'. 108 * This method can be used to check that 'Obligatory Fields' have been completed 109 * when a file is saved. 110 * Subclasses should override this method. 111 * 112 * @return True if the field has been filled out by user. Required values are not null. 113 */ 114 public boolean isFieldFilled() { 115 return fieldValue.isFieldFilled(); 55 116 } 56 117 }
