1 /**
2 * This file Copyright (c) 2003-2011 Magnolia International
3 * Ltd. (http://www.magnolia-cms.com). All rights reserved.
4 *
5 *
6 * This file is dual-licensed under both the Magnolia
7 * Network Agreement and the GNU General Public License.
8 * You may elect to use one or the other of these licenses.
9 *
10 * This file is distributed in the hope that it will be
11 * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the
12 * implied warranty of MERCHANTABILITY or FITNESS FOR A
13 * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT.
14 * Redistribution, except as permitted by whichever of the GPL
15 * or MNA you select, is prohibited.
16 *
17 * 1. For the GPL license (GPL), you can redistribute and/or
18 * modify this file under the terms of the GNU General
19 * Public License, Version 3, as published by the Free Software
20 * Foundation. You should have received a copy of the GNU
21 * General Public License, Version 3 along with this program;
22 * if not, write to the Free Software Foundation, Inc., 51
23 * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24 *
25 * 2. For the Magnolia Network Agreement (MNA), this file
26 * and the accompanying materials are made available under the
27 * terms of the MNA which accompanies this distribution, and
28 * is available at http://www.magnolia-cms.com/mna.html
29 *
30 * Any modifications to this file must keep this entire header
31 * intact.
32 *
33 */
34 package info.magnolia.cms.gui.controlx.list;
35
36 import info.magnolia.cms.gui.controlx.impl.AbstractControl;
37
38
39 /**
40 * This represents a column in a list.
41 * @author Philipp Bracher
42 * @version $Revision: 44898 $ ($Author: dlipp $)
43 */
44 public class ListColumn extends AbstractControl {
45
46 /**
47 *
48 */
49 public static final String RENDER_TYPE = "listColumn";
50
51 /**
52 * The columnName of the column.
53 */
54 private String columnName;
55
56 /**
57 * The label showed
58 */
59 private String label;
60
61 /**
62 * Width of the table
63 */
64 private String width;
65
66 /**
67 * Show a separator after this column
68 */
69 private boolean separator;
70
71 /**
72 * Empty Constructor. Used for anonymous classes.
73 */
74 public ListColumn() {
75 this.setRenderType(RENDER_TYPE);
76 }
77
78 /**
79 * Create a new column.
80 * @param columnName
81 * @param label
82 * @param width
83 * @param separator
84 */
85 public ListColumn(String columnName, String label, String width, boolean separator) {
86 this();
87 this.setName(columnName);
88 this.setColumnName(columnName);
89 this.setLabel(label);
90 this.setWidth(width);
91 this.setSeparator(separator);
92 }
93
94 /**
95 * Get the list control this column belongs to.
96 * @return the list control
97 */
98 public ListControl getListControl() {
99 return (ListControl) this.getParent();
100 }
101
102 /**
103 * @return Returns the label.
104 */
105 public String getLabel() {
106 if (this.label == null) {
107 return this.getName();
108 }
109 return this.label;
110 }
111
112 /**
113 * @param label The label to set.
114 */
115 public void setLabel(String label) {
116 this.label = label;
117 }
118
119 /**
120 * @return Returns the separator.
121 */
122 public boolean isSeparator() {
123 return this.separator;
124 }
125
126 /**
127 * @param separator The separator to set.
128 */
129 public void setSeparator(boolean separator) {
130 this.separator = separator;
131 }
132
133 /**
134 * @return Returns the width.
135 */
136 public String getWidth() {
137 return this.width;
138 }
139
140 /**
141 * @param width The width to set.
142 */
143 public void setWidth(String width) {
144 this.width = width;
145 }
146
147 /**
148 * Called by the renderer
149 * @return the object to render
150 */
151 public Object getValue() {
152 return this.getListControl().getIteratorValue(this.getColumnName());
153 }
154
155 /**
156 * @return Returns the columnName.
157 */
158 public String getColumnName() {
159 if(this.columnName == null){
160 return this.getName();
161 }
162 return this.columnName;
163 }
164
165 /**
166 * @param columnName The columnName to set.
167 */
168 public void setColumnName(String columnName) {
169 this.columnName = columnName;
170 }
171
172 }