1 18 19 package org.apache.struts.webapp.tiles.dynPortal; 20 21 import java.util.ArrayList ; 22 import java.util.Iterator ; 23 import java.util.List ; 24 25 28 public class PortalSettings 29 { 30 31 protected int numCols; 32 33 protected List lists = new ArrayList (); 34 35 protected List choices = new ArrayList (); 36 37 protected List choiceLabels = new ArrayList (); 38 39 42 public String getLabel( Object key ) 43 { 44 int index = choices.indexOf( key ); 45 return (String )choiceLabels.get(index); 46 } 47 48 51 public int getNumCols() 52 { 53 return numCols; 54 } 55 58 public void setNumCols( String numCols ) 59 { 60 this.numCols = Integer.parseInt(numCols); 61 } 62 65 public void setNumCols( int numCols ) 66 { 67 this.numCols = numCols; 68 } 69 72 public List getListAt( int index ) 73 { 74 return (List )lists.get(index); 75 } 76 77 80 public List getListLabelAt( int index ) 81 { 82 List listLabels = new ArrayList (); 83 List list = getListAt(index); 84 85 Iterator i = list.iterator(); 86 while(i.hasNext()) 87 { 88 Object key = i.next(); 89 listLabels.add( getLabel(key) ); 90 } return listLabels; 92 } 93 94 97 public void addList( List list ) 98 { 99 lists.add( list); 100 } 101 102 105 public void setChoices( List list) 106 { 107 setChoices(list, list); 108 } 109 110 113 public void addChoices( List list) 114 { 115 addChoices( list, list); 116 } 117 118 121 public void setChoices( List list, List labels) 122 { 123 if( labels == null ) 125 labels = list; 126 if( list.size() != labels.size() ) 128 { System.out.println( "Error : list and labels size must be the same." ); 130 } 131 this.choices = list; 132 choiceLabels = labels; 133 } 134 135 141 public void addChoices( List list, List labels) 142 { 143 if( labels == null ) 145 labels = list; 146 if(choices== null) 148 { 149 setChoices(list, labels); 150 return; 151 } 152 153 if( list.size() != labels.size() ) 154 { System.out.println( "Error : list and labels size must be the same." ); 156 } 157 choices.addAll(list); 158 choiceLabels.addAll(labels); 159 } 160 161 164 public List getChoices( ) 165 { 166 return choices; 167 } 168 169 172 public void setChoiceLabels( List list) 173 { 174 this.choiceLabels = list; 175 } 176 179 public void addChoiceLabels( List list) 180 { 181 if(choiceLabels== null) 182 { 183 setChoiceLabels(list); 184 return; 185 } 186 choiceLabels.addAll(list); 187 } 188 191 public List getChoiceLabels( ) 192 { 193 return choiceLabels; 194 } 195 196 203 public void resetListAt( int index, String keys[] ) 204 { 205 List list = getListAt(index); 206 list.clear(); 207 addListAt(index, keys); 208 } 209 216 public void addListAt( int index, String keys[] ) 217 { 218 while( index>lists.size()-1 ) lists.add(new ArrayList ()); 220 221 List list = getListAt(index);; 222 for(int i=0;i<keys.length;i++) 224 { 225 String key = keys[i]; 226 if( key.indexOf( '@' )>0 ) 227 { } 229 if( choices.contains( key ) ) 230 { list.add( key ); 232 } 233 } lists.add( list); 235 } 236 237 } 238 | Popular Tags |