1 19 20 package org.jahia.data.containers; 21 22 import java.util.Comparator ; 23 import java.util.HashMap ; 24 import java.util.Locale ; 25 import java.util.Vector ; 26 27 import org.jahia.resourcebundle.ResourceBundleMarker; 28 import java.io.Serializable ; 29 30 31 36 37 public class ContainerEditViewFieldGroup implements Serializable , Comparator { 38 39 private static final String CLASS_NAME = ContainerEditViewFieldGroup.class.getName(); 40 private int pos; 41 private String name; 42 private String title; 43 private String descr; 44 private HashMap fields = new HashMap (); 45 private Vector fieldNames = new Vector (); 46 47 48 56 public ContainerEditViewFieldGroup(String name,String title,String descr) 57 { 58 setName(name); 59 setTitle(title); 60 setDescr(descr); 61 if ( this.title == null || this.title.equals("") ){ 62 this.title = getName(); 63 } 64 } 65 66 71 public String getName(){ 72 return this.name; 73 } 74 75 81 public void setName(String name){ 82 if ( name == null || name.trim().equals("") ){ 83 return; 84 } 85 this.name = name; 86 if ( this.title == null || this.title.equals("") ){ 87 this.title = getName(); 88 } 89 } 90 91 96 public String getTitle(){ 97 return this.title; 98 } 99 100 105 public String getTitle(Locale locale){ 106 if ( locale == null ){ 107 return this.title; 108 } 109 String title = this.title; 110 if ( title == null ){ 111 title = ""; 112 } 113 boolean multipleFields = this.title.endsWith(";..."); 114 if ( multipleFields ){ 115 int pos = this.title.lastIndexOf(";..."); 116 title = title.substring(0,pos); 117 } 118 ResourceBundleMarker resMarker = ResourceBundleMarker.parseMarkerValue(title); 119 if ( resMarker == null ){ 120 return this.title; 121 } 122 try { 123 title = resMarker.getValue(locale); 124 if ( multipleFields ){ 125 title += ";..."; 126 } 127 } catch ( Throwable t ){ 128 title = this.title; 129 } 130 return title; 131 } 132 133 139 public void setTitle(String title){ 140 if ( title == null || title.trim().equals("") ){ 141 return; 142 } 143 this.title = title; 144 } 145 146 151 public String getDescr(){ 152 return this.descr; 153 } 154 155 161 public void setDescr(String descr){ 162 if ( descr == null ){ 163 return; 164 } 165 this.descr = descr; 166 } 167 168 175 public void addField(String name,String descr){ 176 if ( name == null || name.trim().equals("") ){ 177 return; 178 } 179 180 ContainerEditViewField field = new ContainerEditViewField(name,descr); 181 if ( fields.get(name) == null ){ 182 fieldNames.add(name); 183 } 184 fields.put(name,field); 185 } 186 187 194 public void addField(ContainerEditViewField editViewField){ 195 if ( editViewField==null || editViewField.getName() == null || editViewField.getName().trim().equals("") ){ 196 return; 197 } 198 199 if ( fields.get(editViewField.getName()) == null ){ 200 fieldNames.add(editViewField.getName()); 201 } 202 fields.put(editViewField.getName(),editViewField); 203 } 204 205 211 public boolean fieldExists(String fieldName){ 212 int size = fieldNames.size(); 213 for ( int i=0 ; i<size ; i++ ){ 214 if ( ((String )fieldNames.get(i)).equals(fieldName) ){ 215 return true; 216 } 217 } 218 return false; 219 } 220 221 226 public Vector getFieldNames(){ 227 return fieldNames; 228 } 229 230 235 public HashMap getFields(){ 236 return fields; 237 } 238 239 246 public ContainerEditViewField getField(String name){ 247 return (ContainerEditViewField)fields.get(name); 248 } 249 250 255 public void setPos(int pos){ 256 this.pos = pos; 257 } 258 259 264 public int getPos(){ 265 return this.pos; 266 } 267 268 275 public int compare(Object c1, Object c2) throws ClassCastException { 276 277 Integer I = new Integer (((ContainerEditViewFieldGroup)c1).getPos()); 278 Integer J = new Integer (((ContainerEditViewFieldGroup)c2).getPos()); 279 280 return ( I.compareTo(J) ); 281 282 } 283 284 285 } 286 | Popular Tags |