1 17 package org.alfresco.web.config; 18 19 import java.util.ArrayList ; 20 import java.util.HashMap ; 21 import java.util.Iterator ; 22 import java.util.List ; 23 import java.util.Map ; 24 25 import org.alfresco.config.ConfigElement; 26 import org.alfresco.config.element.ConfigElementAdapter; 27 import org.alfresco.config.element.GenericConfigElement; 28 29 34 public class PropertySheetConfigElement extends ConfigElementAdapter 35 { 36 39 private List <ItemConfig> items = new ArrayList <ItemConfig>(); 40 private List <ItemConfig> editableItems = new ArrayList <ItemConfig>(); 41 private Map <String , ItemConfig> itemsMap = new HashMap <String , ItemConfig>(); 42 private Map <String , ItemConfig> editableItemsMap = new HashMap <String , ItemConfig>(); 43 private List <String > itemNames = new ArrayList <String >(); 44 private List <String > editableItemNames = new ArrayList <String >(); 45 private boolean kidsPopulated = false; 46 47 50 public PropertySheetConfigElement() 51 { 52 super("property-sheet"); 53 } 54 55 60 public PropertySheetConfigElement(String name) 61 { 62 super(name); 63 } 64 65 68 public List <ConfigElement> getChildren() 69 { 70 73 List <ConfigElement> kids = null; 74 75 if (this.items.size() > 0) 76 { 77 if (this.kidsPopulated == false) 78 { 79 Iterator <ItemConfig> items = this.items.iterator(); 80 while (items.hasNext()) 81 { 82 ItemConfig pc = items.next(); 83 GenericConfigElement ce = null; 84 if (pc instanceof PropertyConfig) 85 { 86 ce = new GenericConfigElement(PropertySheetElementReader.ELEMENT_SHOW_PROPERTY); 87 } 88 else if (pc instanceof AssociationConfig) 89 { 90 ce = new GenericConfigElement(PropertySheetElementReader.ELEMENT_SHOW_ASSOC); 91 } 92 else 93 { 94 ce = new GenericConfigElement(PropertySheetElementReader.ELEMENT_SHOW_CHILD_ASSOC); 95 } 96 97 ce.addAttribute(PropertySheetElementReader.ATTR_NAME, pc.getName()); 98 ce.addAttribute(PropertySheetElementReader.ATTR_DISPLAY_LABEL, pc.getDisplayLabel()); 99 ce.addAttribute(PropertySheetElementReader.ATTR_DISPLAY_LABEL_ID, pc.getDisplayLabelId()); 100 ce.addAttribute(PropertySheetElementReader.ATTR_READ_ONLY, Boolean.toString(pc.isReadOnly())); 101 ce.addAttribute(PropertySheetElementReader.ATTR_CONVERTER, pc.getConverter()); 102 ce.addAttribute(PropertySheetElementReader.ATTR_SHOW_IN_EDIT_MODE, Boolean.toString(pc.isShownInEditMode())); 103 this.children.add(ce); 104 } 105 106 this.kidsPopulated = true; 107 } 108 109 kids = super.getChildren(); 110 } 111 112 return kids; 113 } 114 115 118 public ConfigElement combine(ConfigElement configElement) 119 { 120 PropertySheetConfigElement combined = new PropertySheetConfigElement(); 121 122 Iterator <ItemConfig> items = this.getItemsToShow().iterator(); 124 while (items.hasNext()) 125 { 126 combined.addItem(items.next()); 127 } 128 129 items = ((PropertySheetConfigElement)configElement).getItemsToShow().iterator(); 131 while (items.hasNext()) 132 { 133 combined.addItem(items.next()); 134 } 135 136 return combined; 137 } 138 139 144 void addItem(ItemConfig itemConfig) 145 { 146 if (this.itemsMap.containsKey(itemConfig.getName()) == false) 147 { 148 this.items.add(itemConfig); 149 this.itemsMap.put(itemConfig.getName(), itemConfig); 150 this.itemNames.add(itemConfig.getName()); 151 152 if (itemConfig.isShownInEditMode()) 154 { 155 this.editableItems.add(itemConfig); 156 this.editableItemsMap.put(itemConfig.getName(), itemConfig); 157 this.editableItemNames.add(itemConfig.getName()); 158 } 159 } 160 } 161 162 173 void addProperty(String name, String displayLabel, String displayLabelId, String readOnly, 174 String converter, String inEdit) 175 { 176 addItem(new PropertyConfig(name, displayLabel, displayLabelId, Boolean.parseBoolean(readOnly), 177 converter, inEdit)); 178 } 179 180 191 void addAssociation(String name, String displayLabel, String displayLabelId, String readOnly, 192 String converter, String inEdit) 193 { 194 addItem(new AssociationConfig(name, displayLabel, displayLabelId, Boolean.parseBoolean(readOnly), 195 converter, inEdit)); 196 } 197 198 207 void addChildAssociation(String name, String displayLabel, String displayLabelId, String readOnly, 208 String converter, String inEdit) 209 { 210 addItem(new ChildAssociationConfig(name, displayLabel, displayLabelId, Boolean.parseBoolean(readOnly), 211 converter, inEdit)); 212 } 213 214 217 public List <String > getItemNamesToShow() 218 { 219 return this.itemNames; 220 } 221 222 225 public List <ItemConfig> getItemsToShow() 226 { 227 return this.items; 228 } 229 230 233 public Map <String , ItemConfig> getItemsMapToShow() 234 { 235 return this.itemsMap; 236 } 237 238 241 public List <String > getEditableItemNamesToShow() 242 { 243 return this.editableItemNames; 244 } 245 246 249 public List <ItemConfig> getEditableItemsToShow() 250 { 251 return this.editableItems; 252 } 253 254 257 public Map <String , ItemConfig> getEditableItemsMapToShow() 258 { 259 return this.editableItemsMap; 260 } 261 262 265 public abstract class ItemConfig 266 { 267 private String name; 268 private String displayLabel; 269 private String displayLabelId; 270 private String converter; 271 private boolean readOnly; 272 private boolean showInEditMode = true; 273 274 public ItemConfig(String name, String displayLabel, String displayLabelId, 275 boolean readOnly, String converter, String inEdit) 276 { 277 this.name = name; 278 this.displayLabel = displayLabel; 279 this.displayLabelId = displayLabelId; 280 this.readOnly = readOnly; 281 this.converter = converter; 282 283 if (inEdit != null) 284 { 285 this.showInEditMode = Boolean.parseBoolean(inEdit); 286 } 287 } 288 289 292 public String getDisplayLabel() 293 { 294 return this.displayLabel; 295 } 296 297 300 public String getDisplayLabelId() 301 { 302 return this.displayLabelId; 303 } 304 305 308 public String getName() 309 { 310 return this.name; 311 } 312 313 316 public boolean isReadOnly() 317 { 318 return this.readOnly; 319 } 320 321 public String getConverter() 322 { 323 return this.converter; 324 } 325 326 public boolean isShownInEditMode() 327 { 328 return this.showInEditMode; 329 } 330 331 334 public String toString() 335 { 336 StringBuilder buffer = new StringBuilder (super.toString()); 337 buffer.append(" (name=").append(this.name); 338 buffer.append(" displaylabel=").append(this.displayLabel); 339 buffer.append(" displaylabelId=").append(this.displayLabelId); 340 buffer.append(" converter=").append(this.converter); 341 buffer.append(" readonly=").append(this.readOnly); 342 buffer.append(" showInEditMode=").append(this.showInEditMode).append(")"); 343 return buffer.toString(); 344 } 345 } 346 347 350 public class PropertyConfig extends ItemConfig 351 { 352 public PropertyConfig(String name, String displayLabel, String displayLabelId, 353 boolean readOnly, String converter, String inEdit) 354 { 355 super(name, displayLabel, displayLabelId, readOnly, converter, inEdit); 356 } 357 } 358 359 362 public class AssociationConfig extends ItemConfig 363 { 364 public AssociationConfig(String name, String displayLabel, String displayLabelId, 365 boolean readOnly, String converter, String inEdit) 366 { 367 super(name, displayLabel, displayLabelId, readOnly, converter, inEdit); 368 } 369 } 370 371 374 public class ChildAssociationConfig extends ItemConfig 375 { 376 public ChildAssociationConfig(String name, String displayLabel, String displayLabelId, 377 boolean readOnly, String converter, String inEdit) 378 { 379 super(name, displayLabel, displayLabelId, readOnly, converter, inEdit); 380 } 381 } 382 } 383 | Popular Tags |