1 15 package org.apache.tapestry.workbench.table; 16 17 import java.util.HashSet ; 18 import java.util.Locale ; 19 import java.util.Set ; 20 import java.util.StringTokenizer ; 21 22 import org.apache.tapestry.BaseComponent; 23 import org.apache.tapestry.IActionListener; 24 import org.apache.tapestry.IRequestCycle; 25 import org.apache.tapestry.annotations.Parameter; 26 import org.apache.tapestry.contrib.table.model.IPrimaryKeyConvertor; 27 28 31 public abstract class LocaleList extends BaseComponent 32 { 33 34 @Parameter(required = true) 35 public abstract ILocaleSelectionListener getLocaleSelectionListener(); 36 37 private IPrimaryKeyConvertor m_objLocaleConvertor; 39 40 public LocaleList() 41 { 42 m_objLocaleConvertor = new IPrimaryKeyConvertor() 45 { 46 public Object getPrimaryKey(Object objValue) 47 { 48 Locale objLocale = (Locale ) objValue; 49 return objLocale.toString(); 50 } 51 52 public Object getValue(Object objPrimaryKey) 53 { 54 StringTokenizer objTokenizer = new StringTokenizer ((String ) objPrimaryKey, "_"); 55 56 String strLanguage = ""; 57 if (objTokenizer.hasMoreTokens()) 58 strLanguage = objTokenizer.nextToken(); 59 60 String strCountry = ""; 61 if (objTokenizer.hasMoreTokens()) 62 strCountry = objTokenizer.nextToken(); 63 64 String strVariant = ""; 65 if (objTokenizer.hasMoreTokens()) 66 strVariant = objTokenizer.nextToken(); 67 68 return new Locale (strLanguage, strCountry, strVariant); 69 } 70 }; 71 } 72 73 public IPrimaryKeyConvertor getLocaleConvertor() 74 { 75 return m_objLocaleConvertor; 76 } 77 78 public boolean getCheckboxSelected() 79 { 80 return getSelectedLocales().contains(getCurrentLocale()); 81 } 82 83 public void setCheckboxSelected(boolean bSelected) 84 { 85 Locale objLocale = getCurrentLocale(); 86 Set setSelectedLocales = getSelectedLocales(); 87 88 if (bSelected) 89 setSelectedLocales.add(objLocale); 90 else 91 setSelectedLocales.remove(objLocale); 92 93 setSelectedLocales(setSelectedLocales); 95 } 96 97 public void selectLocales(IRequestCycle objCycle) 98 { 99 Set setSelectedLocales = getSelectedLocales(); 100 Locale [] arrLocales = new Locale [setSelectedLocales.size()]; 101 setSelectedLocales.toArray(arrLocales); 102 103 ILocaleSelectionListener objListener = getLocaleSelectionListener(); 104 105 objListener.localesSelected(arrLocales); 106 107 setSelectedLocales(new HashSet ()); 109 } 110 111 public abstract Locale getCurrentLocale(); 112 113 public abstract Set getSelectedLocales(); 114 115 public abstract void setSelectedLocales(Set set); 116 } | Popular Tags |