| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| BaseFieldAttributes |
|
| 1.0;1 |
| 1 | /* | |
| 2 | * $Source$ | |
| 3 | * $Revision$ | |
| 4 | * | |
| 5 | * Copyright (C) 2000 William Chesters | |
| 6 | * | |
| 7 | * Part of Melati (http://melati.org), a framework for the rapid | |
| 8 | * development of clean, maintainable web applications. | |
| 9 | * | |
| 10 | * Melati is free software; Permission is granted to copy, distribute | |
| 11 | * and/or modify this software under the terms either: | |
| 12 | * | |
| 13 | * a) the GNU General Public License as published by the Free Software | |
| 14 | * Foundation; either version 2 of the License, or (at your option) | |
| 15 | * any later version, | |
| 16 | * | |
| 17 | * or | |
| 18 | * | |
| 19 | * b) any version of the Melati Software License, as published | |
| 20 | * at http://melati.org | |
| 21 | * | |
| 22 | * You should have received a copy of the GNU General Public License and | |
| 23 | * the Melati Software License along with this program; | |
| 24 | * if not, write to the Free Software Foundation, Inc., | |
| 25 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA to obtain the | |
| 26 | * GNU General Public License and visit http://melati.org to obtain the | |
| 27 | * Melati Software License. | |
| 28 | * | |
| 29 | * Feel free to contact the Developers of Melati (http://melati.org), | |
| 30 | * if you would like to work out a different arrangement than the options | |
| 31 | * outlined here. It is our intention to allow Melati to be used by as | |
| 32 | * wide an audience as possible. | |
| 33 | * | |
| 34 | * This program is distributed in the hope that it will be useful, | |
| 35 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 36 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 37 | * GNU General Public License for more details. | |
| 38 | * | |
| 39 | * Contact details for copyright holder: | |
| 40 | * | |
| 41 | * William Chesters <williamc At paneris.org> | |
| 42 | * http://paneris.org/~williamc | |
| 43 | * Obrechtstraat 114, 2517VX Den Haag, The Netherlands | |
| 44 | */ | |
| 45 | ||
| 46 | package org.melati.poem; | |
| 47 | ||
| 48 | import org.melati.poem.util.StringUtils; | |
| 49 | ||
| 50 | /** | |
| 51 | * Base class of all {@link Field}s. | |
| 52 | * All the fields of a Field except its value. | |
| 53 | */ | |
| 54 | public class BaseFieldAttributes<T> implements FieldAttributes<T> { | |
| 55 | ||
| 56 | private String name; | |
| 57 | private String displayName; | |
| 58 | private String description; | |
| 59 | private PoemType<T> type; | |
| 60 | private String renderInfo; | |
| 61 | private int width, height; | |
| 62 | private boolean indexed; | |
| 63 | private boolean userEditable; | |
| 64 | private boolean userCreateable; | |
| 65 | ||
| 66 | /** | |
| 67 | * Full Constructor. | |
| 68 | * | |
| 69 | * @param name simple name | |
| 70 | * @param displayName human readable name | |
| 71 | * @param description a short description | |
| 72 | * @param type the PoemType of the new Field | |
| 73 | * @param width how wide input widgets should be | |
| 74 | * @param height how high input widgets should be | |
| 75 | * @param renderInfo the name of a special templet to render this field | |
| 76 | * @param indexed whether the Field is indexed. | |
| 77 | * @param userEditable whether users should be able to modify the value | |
| 78 | * @param userCreateable whether users should be allowed to create new instances | |
| 79 | */ | |
| 80 | public BaseFieldAttributes( | |
| 81 | String name, String displayName, String description, PoemType<T> type, | |
| 82 | int width, int height, String renderInfo, boolean indexed, | |
| 83 | 94 | boolean userEditable, boolean userCreateable) { |
| 84 | 94 | this.name = name; |
| 85 | 94 | this.displayName = displayName; |
| 86 | 94 | this.description = description; |
| 87 | 94 | this.type = type; |
| 88 | 94 | this.width = width; |
| 89 | 94 | this.height = height; |
| 90 | 94 | this.renderInfo = renderInfo; |
| 91 | 94 | this.indexed = indexed; |
| 92 | 94 | this.userEditable = userEditable; |
| 93 | 94 | this.userCreateable = userCreateable; |
| 94 | 94 | } |
| 95 | ||
| 96 | ||
| 97 | /** | |
| 98 | * Convenience constructor. | |
| 99 | * | |
| 100 | * @param name used as the name and, capitalised, the display name | |
| 101 | * @param type the Poem datatype | |
| 102 | */ | |
| 103 | public BaseFieldAttributes(String name, PoemType<T> type) { | |
| 104 | 4 | this(name, StringUtils.capitalised(name), null, type, 0, 0, null, |
| 105 | false, true, true); | |
| 106 | 4 | } |
| 107 | ||
| 108 | /** | |
| 109 | * Create a new BaseFieldAttributes based upon another, but overriding its type. | |
| 110 | * | |
| 111 | * @param other the FieldAttributes to clone | |
| 112 | * @param type allows overriding of type | |
| 113 | */ | |
| 114 | @SuppressWarnings("unchecked") | |
| 115 | public BaseFieldAttributes(FieldAttributes<T> other, @SuppressWarnings("rawtypes") PoemType type) { | |
| 116 | 4 | this(other.getName(), other.getDisplayName(), other.getDescription(), |
| 117 | 2 | type, other.getWidth(), other.getHeight(), other.getRenderInfo(), |
| 118 | 2 | other.getIndexed(), other.getUserEditable(), |
| 119 | 2 | other.getUserCreateable()); |
| 120 | 2 | } |
| 121 | ||
| 122 | /** | |
| 123 | * Create a new BaseFieldAttributes based upon another, overriding its name. | |
| 124 | * | |
| 125 | * @param other the FieldAttributes to clone | |
| 126 | * @param name the new name | |
| 127 | */ | |
| 128 | public BaseFieldAttributes(FieldAttributes<T> other, String name) { | |
| 129 | 4 | this(name, other.getDisplayName(), other.getDescription(), |
| 130 | 2 | other.getType(), other.getWidth(), other.getHeight(), |
| 131 | 2 | other.getRenderInfo(),other.getIndexed(), other.getUserEditable(), |
| 132 | 2 | other.getUserCreateable()); |
| 133 | 2 | } |
| 134 | ||
| 135 | /** | |
| 136 | * Allow the description to vary as well. | |
| 137 | * @param other the FieldAttributes to clone | |
| 138 | * @param name the new name | |
| 139 | * @param description the new description | |
| 140 | */ | |
| 141 | public BaseFieldAttributes(FieldAttributes<T> other, String name, | |
| 142 | String description) { | |
| 143 | 4 | this(name, other.getDisplayName(), description, |
| 144 | 2 | other.getType(), other.getWidth(), other.getHeight(), |
| 145 | 2 | other.getRenderInfo(), |
| 146 | 2 | other.getIndexed(), other.getUserEditable(), |
| 147 | 2 | other.getUserCreateable()); |
| 148 | 2 | } |
| 149 | ||
| 150 | /** | |
| 151 | * Create a new BaseFieldAttributes based upon another, overriding its nullability. | |
| 152 | * | |
| 153 | * @param other the FieldAttributes to clone | |
| 154 | * @param nullable the new nullability | |
| 155 | */ | |
| 156 | public BaseFieldAttributes(FieldAttributes<T> other, boolean nullable) { | |
| 157 | 2 | this(other, other.getType().withNullable(nullable)); |
| 158 | 2 | } |
| 159 | ||
| 160 | /* (non-Javadoc) | |
| 161 | * @see org.melati.poem.FieldAttributes#getName() | |
| 162 | */ | |
| 163 | public String getName() { | |
| 164 | 40 | return name; |
| 165 | } | |
| 166 | ||
| 167 | /* (non-Javadoc) | |
| 168 | * @see org.melati.poem.FieldAttributes#getDisplayName() | |
| 169 | */ | |
| 170 | public String getDisplayName() { | |
| 171 | 8 | return displayName; |
| 172 | } | |
| 173 | ||
| 174 | /* (non-Javadoc) | |
| 175 | * @see org.melati.poem.FieldAttributes#getDescription() | |
| 176 | */ | |
| 177 | public String getDescription() { | |
| 178 | 8 | return description; |
| 179 | } | |
| 180 | ||
| 181 | /* (non-Javadoc) | |
| 182 | * @see org.melati.poem.FieldAttributes#getType() | |
| 183 | */ | |
| 184 | public PoemType<T> getType() { | |
| 185 | 78 | return type; |
| 186 | } | |
| 187 | ||
| 188 | /* (non-Javadoc) | |
| 189 | * @see org.melati.poem.FieldAttributes#getIndexed() | |
| 190 | */ | |
| 191 | public boolean getIndexed() { | |
| 192 | 8 | return indexed; |
| 193 | } | |
| 194 | ||
| 195 | /* (non-Javadoc) | |
| 196 | * @see org.melati.poem.FieldAttributes#getUserEditable() | |
| 197 | */ | |
| 198 | public boolean getUserEditable() { | |
| 199 | 8 | return userEditable; |
| 200 | } | |
| 201 | ||
| 202 | /* (non-Javadoc) | |
| 203 | * @see org.melati.poem.FieldAttributes#getUserCreateable() | |
| 204 | */ | |
| 205 | public boolean getUserCreateable() { | |
| 206 | 8 | return userCreateable; |
| 207 | } | |
| 208 | ||
| 209 | /* (non-Javadoc) | |
| 210 | * @see org.melati.poem.FieldAttributes#getWidth() | |
| 211 | */ | |
| 212 | public int getWidth() { | |
| 213 | 8 | return width; |
| 214 | } | |
| 215 | ||
| 216 | /* (non-Javadoc) | |
| 217 | * @see org.melati.poem.FieldAttributes#getHeight() | |
| 218 | */ | |
| 219 | public int getHeight() { | |
| 220 | 8 | return height; |
| 221 | } | |
| 222 | ||
| 223 | /* (non-Javadoc) | |
| 224 | * @see org.melati.poem.FieldAttributes#getRenderInfo() | |
| 225 | */ | |
| 226 | public String getRenderInfo() { | |
| 227 | 8 | return renderInfo; |
| 228 | } | |
| 229 | } |