KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > data > containers > ContainerEditViewFieldGroup


1 //
2
// ____.
3
// __/\ ______| |__/\. _______
4
// __ .____| | \ | +----+ \
5
// _______| /--| | | - \ _ | : - \_________
6
// \\______: :---| : : | : | \________>
7
// |__\---\_____________:______: :____|____:_____\
8
// /_____|
9
//
10
// . . . i n j a h i a w e t r u s t . . .
11
//
12
//
13
//
14
//
15
//
16
//
17
// 28.07.2002 NK
18

19
20 package org.jahia.data.containers;
21
22 import java.util.Comparator JavaDoc;
23 import java.util.HashMap JavaDoc;
24 import java.util.Locale JavaDoc;
25 import java.util.Vector JavaDoc;
26
27 import org.jahia.resourcebundle.ResourceBundleMarker;
28 import java.io.Serializable JavaDoc;
29
30
31 /**
32  * Holds information about a group of Fields used to build the Container Edition Popup.
33  *
34  * @author Khue Nguyen <a HREF="mailto:khue@jahia.org">khue@jahia.org</a>
35  */

36
37 public class ContainerEditViewFieldGroup implements Serializable JavaDoc, Comparator JavaDoc {
38
39     private static final String JavaDoc CLASS_NAME = ContainerEditViewFieldGroup.class.getName();
40     private int pos;
41     private String JavaDoc name;
42     private String JavaDoc title;
43     private String JavaDoc descr;
44     private HashMap JavaDoc fields = new HashMap JavaDoc();
45     private Vector JavaDoc fieldNames = new Vector JavaDoc();
46
47
48     //--------------------------------------------------------------------------
49
/**
50      * Constructor
51      *
52      * @param String name
53      * @param String title
54      * @param String descr
55      */

56     public ContainerEditViewFieldGroup(String JavaDoc name,String JavaDoc title,String JavaDoc descr)
57     {
58         setName(name);
59         setTitle(title);
60         setDescr(descr);
61         if ( this.title == null || this.title.equals("") ){
62             this.title = getName();
63         }
64     }
65
66     //--------------------------------------------------------------------------
67
/**
68      * Return the group name
69      *
70      */

71     public String JavaDoc getName(){
72         return this.name;
73     }
74
75     //--------------------------------------------------------------------------
76
/**
77      * Set the Group Name
78      *
79      * @param String name
80      */

81     public void setName(String JavaDoc name){
82         if ( name == null || name.trim().equals("") ){
83             return;
84         }
85         this.name = name;
86         if ( this.title == null || this.title.equals("") ){
87             this.title = getName();
88         }
89     }
90
91     //--------------------------------------------------------------------------
92
/**
93      * Return the title
94      *
95      */

96     public String JavaDoc getTitle(){
97         return this.title;
98     }
99
100     //--------------------------------------------------------------------------
101
/**
102      * Return the title
103      *
104      */

105     public String JavaDoc getTitle(Locale JavaDoc locale){
106         if ( locale == null ){
107             return this.title;
108         }
109         String JavaDoc title = this.title;
110         if ( title == null ){
111             title = "";
112         }
113         boolean multipleFields = this.title.endsWith(";...");
114         if ( multipleFields ){
115             int pos = this.title.lastIndexOf(";...");
116             title = title.substring(0,pos);
117         }
118         ResourceBundleMarker resMarker = ResourceBundleMarker.parseMarkerValue(title);
119         if ( resMarker == null ){
120             return this.title;
121         }
122         try {
123             title = resMarker.getValue(locale);
124             if ( multipleFields ){
125                 title += ";...";
126             }
127         } catch ( Throwable JavaDoc t ){
128             title = this.title;
129         }
130         return title;
131     }
132
133     //--------------------------------------------------------------------------
134
/**
135      * Set the Group Title used to display the group
136      *
137      * @param String title
138      */

139     public void setTitle(String JavaDoc title){
140         if ( title == null || title.trim().equals("") ){
141             return;
142         }
143         this.title = title;
144     }
145
146     //--------------------------------------------------------------------------
147
/**
148      * Return the group descr
149      *
150      */

151     public String JavaDoc getDescr(){
152         return this.descr;
153     }
154
155     //--------------------------------------------------------------------------
156
/**
157      * Set the Group Descr
158      *
159      * @param String Descr
160      */

161     public void setDescr(String JavaDoc descr){
162         if ( descr == null ){
163             return;
164         }
165         this.descr = descr;
166     }
167
168     //--------------------------------------------------------------------------
169
/**
170      * Add a field
171      *
172      * @param String name, the field name
173      * @param String descr, the descr
174      */

175     public void addField(String JavaDoc name,String JavaDoc descr){
176         if ( name == null || name.trim().equals("") ){
177             return;
178         }
179
180         ContainerEditViewField field = new ContainerEditViewField(name,descr);
181         if ( fields.get(name) == null ){
182             fieldNames.add(name);
183         }
184         fields.put(name,field);
185     }
186
187     //--------------------------------------------------------------------------
188
/**
189      * Add a field
190      *
191      * @param String name, the field name
192      * @param String descr, the descr
193      */

194     public void addField(ContainerEditViewField editViewField){
195         if ( editViewField==null || editViewField.getName() == null || editViewField.getName().trim().equals("") ){
196             return;
197         }
198
199         if ( fields.get(editViewField.getName()) == null ){
200             fieldNames.add(editViewField.getName());
201         }
202         fields.put(editViewField.getName(),editViewField);
203     }
204
205     //--------------------------------------------------------------------------
206
/**
207      * field exists
208      *
209      * @param String fieldName
210      */

211     public boolean fieldExists(String JavaDoc fieldName){
212         int size = fieldNames.size();
213         for ( int i=0 ; i<size ; i++ ){
214             if ( ((String JavaDoc)fieldNames.get(i)).equals(fieldName) ){
215                 return true;
216             }
217         }
218         return false;
219     }
220
221     //--------------------------------------------------------------------------
222
/**
223      * Returns the vector field names in this group
224      *
225      */

226     public Vector JavaDoc getFieldNames(){
227         return fieldNames;
228     }
229
230     //--------------------------------------------------------------------------
231
/**
232      * Returns the HashMap of fields in this group
233      *
234      */

235     public HashMap JavaDoc getFields(){
236         return fields;
237     }
238
239     //--------------------------------------------------------------------------
240
/**
241      * Returns a given ContainerEditViewField looking at it name
242      *
243      * @param name , the field name
244      * @param ContainerEditViewField
245      */

246     public ContainerEditViewField getField(String JavaDoc name){
247         return (ContainerEditViewField)fields.get(name);
248     }
249
250     //--------------------------------------------------------------------------
251
/**
252      * Set the position used to order this group
253      *
254      */

255     public void setPos(int pos){
256         this.pos = pos;
257     }
258
259     //--------------------------------------------------------------------------
260
/**
261      * Get the position used to order this group
262      *
263      */

264     public int getPos(){
265         return this.pos;
266     }
267
268     //-------------------------------------------------------------------------
269
/**
270      * Compare between two objects, sort by their pos
271      *
272      * @param Object
273      * @param Object
274      */

275     public int compare(Object JavaDoc c1, Object JavaDoc c2) throws ClassCastException JavaDoc {
276
277         Integer JavaDoc I = new Integer JavaDoc(((ContainerEditViewFieldGroup)c1).getPos());
278         Integer JavaDoc J = new Integer JavaDoc(((ContainerEditViewFieldGroup)c2).getPos());
279
280         return ( I.compareTo(J) );
281
282     }
283
284
285 }
286
Popular Tags