KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opensubsystems > patterns > listdata > www > ColumnDefinition


1 /*
2  * Copyright (c) 2003 - 2007 OpenSubsystems s.r.o. Slovak Republic. All rights reserved.
3  *
4  * Project: OpenSubsystems
5  *
6  * $Id: ColumnDefinition.java,v 1.3 2007/02/01 07:24:33 bastafidli Exp $
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; version 2 of the License.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  */

21  
22 package org.opensubsystems.patterns.listdata.www;
23
24 import org.opensubsystems.patterns.listdata.data.DataCondition;
25
26 /**
27  * Class describing one column of a list of items. This is based on the
28  * horizontal layour of the list when items are in the rows and columns contain
29  * individual attributes of the items. You can of course layour the list of items
30  * differently and this class will be then used as a description of one of the
31  * attributes in the list
32  *
33  * @version $Id: ColumnDefinition.java,v 1.3 2007/02/01 07:24:33 bastafidli Exp $
34  * @author Miro Halas
35  * @code.reviewer Miro Halas
36  * @code.reviewed Initial revision
37  */

38 public class ColumnDefinition
39 {
40    // Constants ////////////////////////////////////////////////////////////////
41

42    /**
43     * Possible values of boolean representation.
44     */

45    public static final String JavaDoc[] BOOLEAN_TEXTS_DISENABLED
46                                    = new String JavaDoc[] {"Disabled", "Enabled"};
47    
48    /**
49     * Possible values of boolean representation.
50     */

51    public static final String JavaDoc[] BOOLEAN_TEXTS_NOYES
52                                    = new String JavaDoc[] {"No", "Yes"};
53    
54    // Attributes ///////////////////////////////////////////////////////////////
55

56    /**
57     * Name of the column heading
58     */

59    private String JavaDoc m_strColumnName;
60
61    /**
62     * Tooltip for the column heading
63     */

64    private String JavaDoc m_strColumnTooltip;
65
66    /**
67     * Integer representation of the column data type
68     */

69    private int m_iColumnDataType;
70
71    /**
72     * Array of boolean values that will be used. Index 0 represents value for
73     * false and index 1 represents value for true.
74     */

75    private String JavaDoc[] m_arrColumnBooleanValues;
76
77     /**
78     * Width of the column heading as a relative number compared to the width of
79     * other columns. This is used for internal calculation how wide the column
80     * should really be depending on what other columns exist.
81     */

82    private double m_dColumnWidth;
83    
84    /**
85     * Flag signaling if the column has to be displayed when displaying list of
86     * items or not. Column should be flagged as mandatory to be displayed if it
87     * is for example used as a navigation element (e.g. hyperlink) to access
88     * data (for example name of the data). This is used when constructing list
89     * definition since the user interface can indicate the user what columns will
90     * be displayed regardless of his/her choice.
91     */

92    private boolean m_bIsColumnMandatory = false;
93
94    // Constructors //////////////////////////////////////////////////////////
95

96     /**
97     * Constructor
98     *
99     * @param strColumnName - column heading name
100     * @param strColumnTooltip - column tooltip
101     * @param iColumnDataType - type of data displayed in this column, one of the
102     * DataCondition.VALUE_TYPE_XYZ constants
103     * @param dColumnWidth - width of the column heading as a relative number
104     * compared to the width of other columns. 0 is valid
105     * value and means that the columns shouldn't be
106     * displayed
107     */

108    public ColumnDefinition(
109       String JavaDoc strColumnName,
110       String JavaDoc strColumnTooltip,
111       int iColumnDataType,
112       double dColumnWidth
113    )
114    {
115       m_strColumnName = strColumnName;
116       m_strColumnTooltip = strColumnTooltip;
117       m_iColumnDataType = iColumnDataType;
118       m_dColumnWidth = dColumnWidth;
119    }
120
121    /**
122     * Constructor
123     *
124     * @param strColumnName - column heading name
125     * @param strColumnTooltip - column tooltip
126     * @param arrColumnBooleanValues - array of boolean values that will be used
127     * to display booleans values in this column
128     * assuming that the column data type is
129     * boolean. Index 0 represents value for false
130     * and index 1 represents value for true.
131     * Provide are common use values in form of
132     * BOOLEAN_TEXTS_XYZ contants
133     * @param dColumnWidth - width of the column heading as a relative number
134     * compared to the width of other columns. 0 is valid
135     * value and means that the columns shouldn't be
136     * displayed
137     */

138    public ColumnDefinition(
139       String JavaDoc strColumnName,
140       String JavaDoc strColumnTooltip,
141       String JavaDoc[] arrColumnBooleanValues,
142       double dColumnWidth
143    )
144    {
145       m_strColumnName = strColumnName;
146       m_strColumnTooltip = strColumnTooltip;
147       m_iColumnDataType = DataCondition.VALUE_TYPE_BOOLEAN;
148       m_dColumnWidth = dColumnWidth;
149    }
150
151    // Public methods ////////////////////////////////////////////////////////
152

153    /**
154     * @return double - columnWidth
155     */

156    public double getColumnWidth()
157    {
158       return m_dColumnWidth;
159    }
160
161    /**
162     * @return String - columnName
163     */

164    public String JavaDoc getColumnName()
165    {
166       return m_strColumnName;
167    }
168
169    /**
170     * @return int - columnDataType
171     */

172    public int getColumnDataType()
173    {
174       return m_iColumnDataType;
175    }
176
177    /**
178     * @return String - columnTooltip
179     */

180    public String JavaDoc getColumnTooltip()
181    {
182       return m_strColumnTooltip;
183    }
184    
185    /**
186     * Get string representation of boolean values to use for this columns.
187     *
188     * @return String[] - index 0 represents value for false and index 1
189     * represents value for true.
190     */

191    public String JavaDoc[] getColumnBooleanValues()
192    {
193       return m_arrColumnBooleanValues;
194    }
195
196    /**
197     * Method returns string values for boolean column.
198     * These values are separated by separator.
199     *
200     * @param strSeparator - separator the values will be separated by
201     * @return String - value names of the boolean column
202     * [value for false][separator][value for true].
203     */

204    public String JavaDoc getColumnBooleanValueNames(
205       String JavaDoc strSeparator
206    )
207    {
208       StringBuffer JavaDoc sbOutput = new StringBuffer JavaDoc();
209
210       if (m_arrColumnBooleanValues != null
211           && m_arrColumnBooleanValues.length > 0)
212       {
213          sbOutput.append(m_arrColumnBooleanValues[0]);
214          sbOutput.append(strSeparator);
215          sbOutput.append(m_arrColumnBooleanValues[1]);
216       }
217       else
218       {
219          sbOutput.append(strSeparator);
220       }
221       
222       return sbOutput.toString();
223    }
224
225    /**
226     * Check if the column has to be displayed when displaying list of items or
227     * not. Column should be flagged as mandatory to be displayed if it is for
228     * example used as a navigation element (e.g. hyperlink) to access data (for
229     * example name of the data). This is used when constructing list definition
230     * since the user interface can indicate the user what columns will be
231     * displayed regardless of his/her choice.
232     *
233     * @return boolean - true if the column is mandatory false otherwise
234     */

235    public boolean isColumnMandatory()
236    {
237       return m_bIsColumnMandatory;
238    }
239
240    /**
241     * Specify if the column has to be displayed when displaying list of items or
242     * not. Column should be flagged as mandatory to be displayed if it is for
243     * example used as a navigation element (e.g. hyperlink) to access data (for
244     * example name of the data). This is used when constructing list definition
245     * since the user interface can indicate the user what columns will be
246     * displayed regardless of his/her choice.
247     *
248     * @param isColumnMandatory - true if the column is mandatory false otherwise
249     */

250    public void setColumnMandatory(
251       boolean isColumnMandatory
252    )
253    {
254       m_bIsColumnMandatory = isColumnMandatory;
255    }
256 }
257
Popular Tags