KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > struts > webapp > tiles > dynPortal > PortalSettings


1 /*
2  * $Id: PortalSettings.java 54929 2004-10-16 16:38:42Z germuska $
3  *
4  * Copyright 1999-2004 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 package org.apache.struts.webapp.tiles.dynPortal;
20
21 import java.util.ArrayList JavaDoc;
22 import java.util.Iterator JavaDoc;
23 import java.util.List JavaDoc;
24
25   /**
26    * Objects of this class hold portal settings for one user.
27    */

28    public class PortalSettings
29    {
30        /** Number of columms*/
31      protected int numCols;
32        /** List of lists (one per column) */
33      protected List JavaDoc lists = new ArrayList JavaDoc();
34        /** Choices Tiles */
35      protected List JavaDoc choices = new ArrayList JavaDoc();
36        /** Choices Tiles labels */
37      protected List JavaDoc choiceLabels = new ArrayList JavaDoc();
38
39        /**
40         * Get label for specified Tile, identified by its key.
41         */

42      public String JavaDoc getLabel( Object JavaDoc key )
43        {
44        int index = choices.indexOf( key );
45        return (String JavaDoc)choiceLabels.get(index);
46        }
47
48        /**
49         * Get number of columns.
50         */

51      public int getNumCols()
52        {
53        return numCols;
54        }
55        /**
56         * Set number of columns
57         */

58      public void setNumCols( String JavaDoc numCols )
59        {
60        this.numCols = Integer.parseInt(numCols);
61        }
62        /**
63         * Set number of columns
64         */

65      public void setNumCols( int numCols )
66        {
67        this.numCols = numCols;
68        }
69        /**
70         * Get list at specified index
71         */

72      public List JavaDoc getListAt( int index )
73        {
74        return (List JavaDoc)lists.get(index);
75        }
76
77        /**
78         * Get labels for list at specified index.
79         */

80      public List JavaDoc getListLabelAt( int index )
81        {
82        List JavaDoc listLabels = new ArrayList JavaDoc();
83        List JavaDoc list = getListAt(index);
84
85        Iterator JavaDoc i = list.iterator();
86        while(i.hasNext())
87          {
88          Object JavaDoc key = i.next();
89          listLabels.add( getLabel(key) );
90          } // end loop
91
return listLabels;
92        }
93
94        /**
95         * Add a list without checking
96         */

97      public void addList( List JavaDoc list )
98        {
99        lists.add( list);
100        }
101
102        /**
103         * Set list of choices Tiles
104         */

105      public void setChoices( List JavaDoc list)
106        {
107        setChoices(list, list);
108        }
109
110        /**
111         * add list to list of choices Tiles
112         */

113      public void addChoices( List JavaDoc list)
114        {
115        addChoices( list, list);
116        }
117
118        /**
119         * Set list of choices Tiles
120         */

121      public void setChoices( List JavaDoc list, List JavaDoc labels)
122        {
123          // If no labels, use list keys
124
if( labels == null )
125          labels = list;
126          // Check sizes
127
if( list.size() != labels.size() )
128          {// error
129
System.out.println( "Error : list and labels size must be the same." );
130          }
131        this.choices = list;
132        choiceLabels = labels;
133        }
134
135        /**
136         * add list and labels to list of choices Tiles.
137         * If labels is null, use keys list as labels.
138         * @list list of choice keys to add
139         * @labels corresponding labels (list size must be the same as list).
140         */

141      public void addChoices( List JavaDoc list, List JavaDoc labels)
142        {
143          // If no labels, use list keys
144
if( labels == null )
145          labels = list;
146          // Check sizes
147
if(choices== null)
148          {
149          setChoices(list, labels);
150          return;
151          }
152
153        if( list.size() != labels.size() )
154          {// error
155
System.out.println( "Error : list and labels size must be the same." );
156          }
157        choices.addAll(list);
158        choiceLabels.addAll(labels);
159        }
160
161        /**
162         * Get list of choices Tiles
163         */

164      public List JavaDoc getChoices( )
165        {
166        return choices;
167        }
168
169        /**
170         * Set labels for choices Tiles.
171         */

172      public void setChoiceLabels( List JavaDoc list)
173        {
174        this.choiceLabels = list;
175        }
176        /**
177         * add list to list of choices Tiles
178         */

179      public void addChoiceLabels( List JavaDoc list)
180        {
181        if(choiceLabels== null)
182          {
183          setChoiceLabels(list);
184          return;
185          }
186        choiceLabels.addAll(list);
187        }
188        /**
189         * Get list of choices Tiles
190         */

191      public List JavaDoc getChoiceLabels( )
192        {
193        return choiceLabels;
194        }
195
196        /**
197         * Reset list at specified index, and fill it with keys from array.
198         * Keys are added only if they are in the choices list.
199         * Special keys are transformed in appropriate 'definition'.
200         * @index index of the list to add.
201         * @keys array of keys to initialize list.
202         */

203      public void resetListAt( int index, String JavaDoc keys[] )
204        {
205        List JavaDoc list = getListAt(index);
206        list.clear();
207        addListAt(index, keys);
208        }
209        /**
210         * Add keys from array to list at specified index.
211         * Keys are added only if they are in the choices list.
212         * Special keys are transformed in appropriate 'definition'.
213         * @index index of the list to add.
214         * @keys array of keys to add to list.
215         */

216      public void addListAt( int index, String JavaDoc keys[] )
217        {
218          // First, ensure capacity
219
while( index>lists.size()-1 ) lists.add(new ArrayList JavaDoc());
220
221        List JavaDoc list = getListAt(index);;
222          // add keys to list
223
for(int i=0;i<keys.length;i++)
224          {
225          String JavaDoc key = keys[i];
226          if( key.indexOf( '@' )>0 )
227            { // special key
228
}
229          if( choices.contains( key ) )
230            { // ok, add it
231
list.add( key );
232            }
233          } // end loop
234
lists.add( list);
235        }
236
237    }
238
Popular Tags