1 15 package org.apache.tapestry.workbench.table; 16 17 import java.text.DateFormat ; 18 import java.text.DecimalFormatSymbols ; 19 import java.util.Date ; 20 import java.util.Locale ; 21 import java.util.Set ; 22 23 import org.apache.tapestry.BaseComponent; 24 import org.apache.tapestry.IRequestCycle; 25 import org.apache.tapestry.contrib.table.model.ITableColumn; 26 import org.apache.tapestry.contrib.table.model.simple.ITableColumnEvaluator; 27 import org.apache.tapestry.contrib.table.model.simple.SimpleTableColumn; 28 29 32 public abstract class LocaleSelection extends BaseComponent implements ILocaleSelectionListener 33 { 34 private Locale m_objCurrentLocale; 36 37 public abstract Locale getCurrentLocale(); 39 40 public abstract Set getLocaleSet(); 41 42 public abstract void setLocaleSet(Set objLocaleSet); 43 44 47 public void localesSelected(Locale [] arrLocales) 48 { 49 Set objLocaleSet = getLocaleSet(); 50 addAll(objLocaleSet, arrLocales); 51 setLocaleSet(objLocaleSet); 53 } 54 55 private void addAll(Set objLocaleSet, Locale [] arrLocales) 56 { 57 for (int i = 0; i < arrLocales.length; i++) 58 objLocaleSet.add(arrLocales[i]); 59 } 60 61 public ITableColumn getCurrencyColumn() 62 { 63 return new SimpleTableColumn("Currency", new CurrencyEvaluator(), true); 65 } 66 67 public ITableColumn getDateFormatColumn() 68 { 69 return new DateFormatColumn(new Date ()); 71 } 72 73 79 public int getCurrentLocaleVerbosity() 80 { 81 int nVerbosity = VerbosityRating.calculateVerbosity(getCurrentLocale()); 82 return nVerbosity; 83 } 84 85 93 public String [] getDeleteLocaleContext() 94 { 95 Locale objLocale = getCurrentLocale(); 96 return new String [] 97 { objLocale.getLanguage(), objLocale.getCountry(), objLocale.getVariant() }; 98 } 99 100 108 public void deleteLocale(IRequestCycle objCycle) 109 { 110 Object [] arrParams = objCycle.getListenerParameters(); 111 Locale objLocale = new Locale (arrParams[0].toString(), arrParams[1].toString(), 112 arrParams[2].toString()); 113 getLocaleSet().remove(objLocale); 114 } 115 116 119 private static class CurrencyEvaluator implements ITableColumnEvaluator 120 { 121 private static final long serialVersionUID = 1L; 122 123 127 public Object getColumnValue(ITableColumn objColumn, Object objRow) 128 { 129 Locale objLocale = (Locale ) objRow; 130 String strCountry = objLocale.getCountry(); 131 if (strCountry == null || strCountry.equals("")) 132 return ""; 133 134 DecimalFormatSymbols objSymbols = new DecimalFormatSymbols (objLocale); 135 return objSymbols.getCurrencySymbol(); 136 } 137 } 138 139 142 private static class DateFormatColumn extends SimpleTableColumn 143 { 144 private static final long serialVersionUID = 1L; 145 private Date m_objDate; 146 147 public DateFormatColumn(Date objDate) 148 { 149 super("Date Format", true); 150 m_objDate = objDate; 151 } 152 153 public Object getColumnValue(Object objRow) 154 { 155 Locale objLocale = (Locale ) objRow; 156 DateFormat objFormat = DateFormat.getDateTimeInstance( 157 DateFormat.LONG, 158 DateFormat.LONG, 159 objLocale); 160 return objFormat.format(m_objDate); 161 } 162 } 163 164 } | Popular Tags |