1 13 14 package info.magnolia.cms.gui.controlx.list; 15 16 import info.magnolia.cms.gui.control.ContextMenu; 17 import info.magnolia.cms.gui.controlx.impl.AbstractControl; 18 19 import java.util.ArrayList ; 20 import java.util.List ; 21 22 import org.apache.commons.lang.StringUtils; 23 24 25 30 public class ListControl extends AbstractControl { 31 32 35 public static final String RENDER_TYPE = "listControl"; 36 37 40 private ListModelIterator iterator; 41 42 45 private ListModel model; 46 47 50 private ContextMenu contextMenu; 51 52 55 private List sortableFields = new ArrayList (); 56 57 60 private List groupableFields = new ArrayList (); 61 62 65 private int maxRowsPerGroup = 5; 66 67 70 public ListControl() { 71 this.setRenderType(RENDER_TYPE); 72 } 73 74 public ListModel getModel() { 75 return this.model; 76 } 77 78 public void setModel(ListModel model) { 79 this.model = model; 80 } 81 82 85 public void addColumn(ListColumn column) { 86 this.addChild(column); 87 } 88 89 93 public ListModelIterator getIterator() { 94 if (this.iterator == null) { 95 this.iterator = this.getModel().getListModelIterator(); 96 } 97 return iterator; 98 } 99 100 105 public Object getIteratorValue(String name) { 106 return this.getIterator().getValue(name); 107 } 108 109 113 public Object getIteratorValueObject() { 114 return this.getIterator().getValueObject(); 115 } 116 117 120 public void resetIterator() { 121 this.iterator = null; 122 } 123 124 public ContextMenu getContextMenu() { 125 return this.contextMenu; 126 } 127 128 public void setContextMenu(ContextMenu contextMenu) { 129 this.contextMenu = contextMenu; 130 } 131 132 public List getGroupableFields() { 133 return this.groupableFields; 134 } 135 136 public List getSortableFields() { 137 return this.sortableFields; 138 } 139 140 public void addSortableField(String name) { 141 this.sortableFields.add(name); 142 } 143 144 public void addGroupableField(String name) { 145 this.groupableFields.add(name); 146 } 147 148 public int getMaxRowsPerGroup() { 149 return this.maxRowsPerGroup; 150 } 151 152 public void setMaxRowsPerGroup(int maxRowsPerGroup) { 153 this.maxRowsPerGroup = maxRowsPerGroup; 154 } 155 156 159 public String getGroupBy() { 160 return StringUtils.defaultString(this.model.getGroupBy()); 161 } 162 163 166 public String getGroupByOrder() { 167 return StringUtils.defaultIfEmpty(this.model.getGroupByOrder(), "asc"); 168 } 169 170 173 public String getSortBy() { 174 return StringUtils.defaultString(this.model.getSortBy()); 175 } 176 177 180 public String getSortByOrder() { 181 return StringUtils.defaultIfEmpty(this.model.getSortByOrder(), "asc"); 182 } 183 184 187 public void setGroupBy(String name) { 188 this.model.setGroupBy(name, this.model.getGroupByOrder()); 189 } 190 191 194 public void setGroupByOrder(String order) { 195 this.model.setGroupBy(this.model.getGroupBy(), order); 196 } 197 198 203 public String getColumnLabel(String name) { 204 ListColumn column = (ListColumn) this.getChild(name); 205 return column.getLabel(); 206 } 207 208 211 public void setSortBy(String name) { 212 this.model.setSortBy(name, this.model.getSortByOrder()); 213 } 214 215 public void setSortByOrder(String order) { 216 this.model.setSortBy(this.model.getSortBy(), order); 217 } 218 219 } 220 | Popular Tags |