1 13 package info.magnolia.cms.gui.controlx.impl; 14 15 import info.magnolia.cms.gui.controlx.Control; 16 import info.magnolia.cms.gui.controlx.RenderKit; 17 import info.magnolia.cms.gui.controlx.Renderer; 18 19 import java.util.Collection ; 20 21 import org.apache.commons.collections.OrderedMap; 22 import org.apache.commons.collections.map.ListOrderedMap; 23 import org.apache.commons.lang.StringUtils; 24 25 26 31 public class AbstractControl implements Control { 32 33 36 private String name; 37 38 41 private RenderKit renderKit; 42 43 46 private String renderType; 47 48 51 private Renderer renderer; 52 53 56 private Control parent; 57 58 61 private OrderedMap children = new ListOrderedMap(); 62 63 66 public Control getParent() { 67 return parent; 68 } 69 70 73 public void setParent(Control parent) { 74 this.parent = parent; 75 } 76 77 80 public void addChild(Control control) { 81 control.setParent(this); 82 if (StringUtils.isEmpty(control.getName())) { 83 control.setName(this.getName() + "_" + this.children.size()); 84 } 85 this.children.put(control.getName(), control); 86 } 87 88 public Control getChild(String name) { 89 return (Control) this.children.get(name); 90 } 91 92 public Collection getChildren() { 93 return this.children.values(); 94 } 95 96 99 public String getName() { 100 return name; 101 } 102 103 106 public void setName(String name) { 107 this.name = name; 108 } 109 110 113 public RenderKit getRenderKit() { 114 if (this.renderKit == null) { 115 if (this.getParent() != null) { 116 this.renderKit = this.getParent().getRenderKit(); 117 } 118 } 119 return renderKit; 120 } 121 122 125 public void setRenderKit(RenderKit renderKit) { 126 this.renderKit = renderKit; 127 } 128 129 132 public String render() { 133 return this.getRenderer().render(this); 134 } 135 136 139 public String getRenderType() { 140 return renderType; 141 } 142 143 146 public void setRenderType(String renderType) { 147 this.renderType = renderType; 148 } 149 150 153 public Renderer getRenderer() { 154 if (this.renderer == null) { 155 this.renderer = this.getRenderKit().getRenderer(this.getRenderType()); 156 } 157 158 return this.renderer; 159 } 160 161 164 public void setRenderer(Renderer renderer) { 165 this.renderer = renderer; 166 } 167 168 } 169 | Popular Tags |