CVS: Tapestry/examples/Tutorial/src/tutorial/workbench/table LocaleSelection.jwc,1.2,1.3 VerbosityRating.java,1.2,1.3 LocaleSelection.java,1.4,1.5 LocaleList.jwc,1.1,1.2

Mind Bridge <[email protected]>
Newsgroups gmane.comp.java.tapestry.cvs
Message-ID <[email protected]>
Update of /cvsroot/tapestry/Tapestry/examples/Tutorial/src/tutorial/workbench/table
In directory sc8-pr-cvs1:/tmp/cvs-serv7513/examples/Tutorial/src/tutorial/workbench/table

Modified Files:
	LocaleSelection.jwc VerbosityRating.java LocaleSelection.java 
	LocaleList.jwc 
Log Message:
using the 2.3 Table features

Index: LocaleSelection.jwc
===================================================================
RCS file: /cvsroot/tapestry/Tapestry/examples/Tutorial/src/tutorial/workbench/table/LocaleSelection.jwc,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** LocaleSelection.jwc	27 Sep 2002 16:13:07 -0000	1.2
--- LocaleSelection.jwc	23 Dec 2002 12:44:06 -0000	1.3
***************
*** 14,17 ****
--- 14,18 ----
  	<component id="table" type="contrib:Table">
  		<binding name="tableModel" expression="initialTableModel"/>
+ 		<binding name="row" expression="currentLocale"/>
  		<static-binding name="rowsClass">tableRowsClass</static-binding>
  	</component>
***************
*** 21,25 ****
  	<component id="directDelete" type="DirectLink">
  		<binding name="listener" expression="listeners.deleteLocale"/>
! 		<binding name="parameters" expression="currentLocale"/>
  	</component>
  
--- 22,26 ----
  	<component id="directDelete" type="DirectLink">
  		<binding name="listener" expression="listeners.deleteLocale"/>
! 		<binding name="parameters" expression="deleteLocaleContext"/>
  	</component>
  

Index: VerbosityRating.java
===================================================================
RCS file: /cvsroot/tapestry/Tapestry/examples/Tutorial/src/tutorial/workbench/table/VerbosityRating.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** VerbosityRating.java	24 Sep 2002 12:42:26 -0000	1.2
--- VerbosityRating.java	23 Dec 2002 12:44:07 -0000	1.3
***************
*** 12,83 ****
  public class VerbosityRating implements Serializable
  {
!     
  	/**
  	 * Method calculateVerbosity.
!      * Please note that this method is relatively slow
!      * It should not be used often, unless for fun :)
  	 * @param objLocale
  	 * @return int
  	 */
!     public int calculateVerbosity(Locale objLocale) {
!         int nWeekDayVerbosity = calculateWeekDayVerbosity(objLocale);
!         int nMonthVerbosity = calculateMonthVerbosity(objLocale);
!         return nWeekDayVerbosity + nMonthVerbosity;
!     }
!     
!     public int calculateWeekDayVerbosity(Locale objLocale) {
!         SimpleDateFormat objWeekDay = new SimpleDateFormat("EEEE", objLocale);
  
!         GregorianCalendar objCalendar = new GregorianCalendar();
!         objCalendar.set(GregorianCalendar.YEAR, 2000);
!         objCalendar.set(GregorianCalendar.MONTH, 0);
!         objCalendar.set(GregorianCalendar.DATE, 1);
!         
!         int nCount = 0;
!         for (int i = 0; i < 7; i++) {
!             String strWeekDay = objWeekDay.format(objCalendar.getTime());
!             nCount += strWeekDay.length();
!             objCalendar.add(GregorianCalendar.DATE, 1);
!         }
!         
!         return nCount;
!     }
  
!     public int calculateMonthVerbosity(Locale objLocale) {
!         SimpleDateFormat objMonth = new SimpleDateFormat("MMMM", objLocale);
  
!         GregorianCalendar objCalendar = new GregorianCalendar();
!         objCalendar.set(GregorianCalendar.YEAR, 2000);
!         objCalendar.set(GregorianCalendar.MONTH, 0);
!         objCalendar.set(GregorianCalendar.DATE, 1);
!         
!         int nCount = 0;
!         for (int i = 0; i < 12; i++) {
!             String strMonth = objMonth.format(objCalendar.getTime());
!             nCount += strMonth.length();
!             objCalendar.add(GregorianCalendar.MONTH, 1);
!         }
!         
!         return nCount;
!     }
  
!     public static void main(String[] arrArgs) {
!         int nMax = 0;
!         int nMin = 1000;
!         
!         System.out.println("Starting");
!         
!         VerbosityRating objRating = new VerbosityRating();
!         Locale[] arrLocales = Locale.getAvailableLocales();
!         for (int i = 0; i < arrLocales.length; i++) {
!             Locale objLocale = arrLocales[i];
!             int nRating = objRating.calculateVerbosity(objLocale);
!             if (nRating > nMax) nMax = nRating;
!             if (nRating < nMin) nMin = nRating;
!         }
!         
!         System.out.println("Min: " + nMin);
!         System.out.println("Max: " + nMax);
!     }
  
  }
--- 12,91 ----
  public class VerbosityRating implements Serializable
  {
! 
  	/**
  	 * Method calculateVerbosity.
! 	 * Please note that this method is relatively slow
! 	 * It should not be used often, unless for fun :)
  	 * @param objLocale
  	 * @return int
  	 */
! 	public static int calculateVerbosity(Locale objLocale)
! 	{
! 		int nWeekDayVerbosity = calculateWeekDayVerbosity(objLocale);
! 		int nMonthVerbosity = calculateMonthVerbosity(objLocale);
! 		return nWeekDayVerbosity + nMonthVerbosity;
! 	}
  
! 	public static int calculateWeekDayVerbosity(Locale objLocale)
! 	{
! 		SimpleDateFormat objWeekDay = new SimpleDateFormat("EEEE", objLocale);
  
! 		GregorianCalendar objCalendar = new GregorianCalendar();
! 		objCalendar.set(GregorianCalendar.YEAR, 2000);
! 		objCalendar.set(GregorianCalendar.MONTH, 0);
! 		objCalendar.set(GregorianCalendar.DATE, 1);
  
! 		int nCount = 0;
! 		for (int i = 0; i < 7; i++)
! 		{
! 			String strWeekDay = objWeekDay.format(objCalendar.getTime());
! 			nCount += strWeekDay.length();
! 			objCalendar.add(GregorianCalendar.DATE, 1);
! 		}
  
! 		return nCount;
! 	}
! 
! 	public static int calculateMonthVerbosity(Locale objLocale)
! 	{
! 		SimpleDateFormat objMonth = new SimpleDateFormat("MMMM", objLocale);
! 
! 		GregorianCalendar objCalendar = new GregorianCalendar();
! 		objCalendar.set(GregorianCalendar.YEAR, 2000);
! 		objCalendar.set(GregorianCalendar.MONTH, 0);
! 		objCalendar.set(GregorianCalendar.DATE, 1);
! 
! 		int nCount = 0;
! 		for (int i = 0; i < 12; i++)
! 		{
! 			String strMonth = objMonth.format(objCalendar.getTime());
! 			nCount += strMonth.length();
! 			objCalendar.add(GregorianCalendar.MONTH, 1);
! 		}
! 
! 		return nCount;
! 	}
! 
! 	public static void main(String[] arrArgs)
! 	{
! 		int nMax = 0;
! 		int nMin = 1000;
! 
! 		System.out.println("Starting");
! 
! 		Locale[] arrLocales = Locale.getAvailableLocales();
! 		for (int i = 0; i < arrLocales.length; i++)
! 		{
! 			Locale objLocale = arrLocales[i];
! 			int nRating = calculateVerbosity(objLocale);
! 			if (nRating > nMax)
! 				nMax = nRating;
! 			if (nRating < nMin)
! 				nMin = nRating;
! 		}
! 
! 		System.out.println("Min: " + nMin);
! 		System.out.println("Max: " + nMax);
! 	}
  
  }

Index: LocaleSelection.java
===================================================================
RCS file: /cvsroot/tapestry/Tapestry/examples/Tutorial/src/tutorial/workbench/table/LocaleSelection.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** LocaleSelection.java	25 Sep 2002 20:46:33 -0000	1.4
--- LocaleSelection.java	23 Dec 2002 12:44:07 -0000	1.5
***************
*** 9,22 ****
  
  import net.sf.tapestry.BaseComponent;
- import net.sf.tapestry.ComponentAddress;
- import net.sf.tapestry.IRender;
  import net.sf.tapestry.IRequestCycle;
  import net.sf.tapestry.components.Block;
- import net.sf.tapestry.components.BlockRenderer;
  import net.sf.tapestry.contrib.table.model.ITableColumn;
  import net.sf.tapestry.contrib.table.model.ITableColumnModel;
  import net.sf.tapestry.contrib.table.model.ITableModel;
  import net.sf.tapestry.contrib.table.model.ITableModelSource;
  import net.sf.tapestry.contrib.table.model.ognl.ExpressionTableColumn;
  import net.sf.tapestry.contrib.table.model.simple.SimpleSetTableDataModel;
  import net.sf.tapestry.contrib.table.model.simple.SimpleTableColumn;
--- 9,22 ----
  
  import net.sf.tapestry.BaseComponent;
  import net.sf.tapestry.IRequestCycle;
  import net.sf.tapestry.components.Block;
  import net.sf.tapestry.contrib.table.model.ITableColumn;
  import net.sf.tapestry.contrib.table.model.ITableColumnModel;
  import net.sf.tapestry.contrib.table.model.ITableModel;
  import net.sf.tapestry.contrib.table.model.ITableModelSource;
+ import net.sf.tapestry.contrib.table.model.ITableRendererSource;
+ import net.sf.tapestry.contrib.table.model.common.BlockTableRendererSource;
  import net.sf.tapestry.contrib.table.model.ognl.ExpressionTableColumn;
+ import net.sf.tapestry.contrib.table.model.simple.ITableColumnEvaluator;
  import net.sf.tapestry.contrib.table.model.simple.SimpleSetTableDataModel;
  import net.sf.tapestry.contrib.table.model.simple.SimpleTableColumn;
***************
*** 39,42 ****
--- 39,45 ----
  	private Locale m_objCurrentLocale;
  
+ 	/**
+ 	 * Creates a new LocaleSelection component
+ 	 */
  	public LocaleSelection()
  	{
***************
*** 52,74 ****
  
  		// We delay the initialization until now, since some columns
! 		// rely on a completed page structure
  		m_objTableColumnModel = createColumnModel();
  	}
  
  	private ITableColumnModel createColumnModel()
  	{
! 		// Using a ComponentAddress is always necessary when working 
! 		// with IRender (see below)
! 		final ComponentAddress objAddress = new ComponentAddress(this);
  
  		return new SimpleTableColumnModel(
  			new ITableColumn[] {
! 				new ExpressionTableColumn("Locale", "toString()", true),
! 				new CurrencyColumn(),
! 				new DateFormatColumn(new Date()),
! 				new VerbosityColumn(m_objVerbosityRating, objAddress),
! 				new DeleteColumn(objAddress)});
  	}
  
  	public ITableModel getInitialTableModel()
  	{
--- 55,116 ----
  
  		// We delay the initialization until now, since some columns
! 		// rely on the completed page structure
  		m_objTableColumnModel = createColumnModel();
  	}
  
+ 	/**
+ 	 * Creates the columns that will be displayed by the Table component. <p>
+ 	 * 
+ 	 * This method demonstrates different ways to define table columns.
+ 	 * Choose the one the fits your needs best.
+ 	 * 
+ 	 * @return ITableColumnModel the created column model
+ 	 */
  	private ITableColumnModel createColumnModel()
  	{
! 		// The column value is extracted via OGNL using ExpressionTableColumn
! 		ITableColumn objLocaleColumn =
! 			new ExpressionTableColumn("Locale", "toString()", true);
! 
! 		// The column value is extracted in a custom evaluator class
! 		ITableColumn objCurrencyColumn =
! 			new SimpleTableColumn("Currency", new CurrencyEvaluator(), true);
! 
! 		// The entire column is defined using a custom column class
! 		ITableColumn objDateFormatColumn = new DateFormatColumn(new Date());
! 
! 		// The column value is extracted via OGNL using ExpressionTableColumn
! 		// and the renderer of the column is defined in a Block
! 		ExpressionTableColumn objVerbosityColumn =
! 			new ExpressionTableColumn(
! 				"Verbosity",
! 				"@tutorial.workbench.table.VerbosityRating@calculateVerbosity(#this)",
! 				true);
! 		Block objVerbosityBlock = (Block) getComponent("blockVerbosity");
! 		ITableRendererSource objVerbosityRenderer =
! 			new BlockTableRendererSource(objVerbosityBlock);
! 		objVerbosityColumn.setValueRendererSource(objVerbosityRenderer);
  
+ 		// The renderer of the column is defined in a Block and contains a link
+ 		SimpleTableColumn objDeleteColumn = new SimpleTableColumn("");
+ 		Block objDeleteBlock = (Block) getComponent("blockDelete");
+ 		ITableRendererSource objDeleteRenderer =
+ 			new BlockTableRendererSource(objDeleteBlock);
+ 		objDeleteColumn.setValueRendererSource(objDeleteRenderer);
+ 
+ 		// Create the column model out of the above columns
  		return new SimpleTableColumnModel(
  			new ITableColumn[] {
! 				objLocaleColumn,
! 				objCurrencyColumn,
! 				objDateFormatColumn,
! 				objVerbosityColumn,
! 				objDeleteColumn });
  	}
  
+ 	/**
+ 	 * Creates a table model to be used by the Table component
+ 	 * @return ITableModel the table model
+ 	 */
  	public ITableModel getInitialTableModel()
  	{
***************
*** 78,81 ****
--- 120,127 ----
  	}
  
+ 	/**
+ 	 * Returns the data model used by the displayed table
+ 	 * @return SimpleSetTableDataModel the data model
+ 	 */
  	public SimpleSetTableDataModel getDataModel()
  	{
***************
*** 105,110 ****
  
  	/**
! 	 * Returns the currentLocale.
! 	 * @return Locale
  	 */
  	public int getCurrentLocaleVerbosity()
--- 151,157 ----
  
  	/**
! 	 * Returns the verbosity of the current locale. 
! 	 * This is used by the Block rendering the 'Verbosity' column
! 	 * @return int the current locale verbosity
  	 */
  	public int getCurrentLocaleVerbosity()
***************
*** 122,164 ****
  	}
  
! 	public void deleteLocale(IRequestCycle objCycle)
  	{
! 		Object[] arrParams = objCycle.getServiceParameters();
! 		Locale objLocale = (Locale) arrParams[0];
! 		getDataModel().removeRow(objLocale);
  	}
  
! 
!     // Column definitions follow
! 	private static class DateFormatColumn extends SimpleTableColumn
  	{
! 		private Date m_objDate;
! 
! 		public DateFormatColumn(Date objDate)
! 		{
! 			super("Date Format", true);
! 			m_objDate = objDate;
! 		}
! 
! 		public Object getColumnValue(Object objRow)
! 		{
! 			Locale objLocale = (Locale) objRow;
! 			DateFormat objFormat =
! 				DateFormat.getDateTimeInstance(
! 					DateFormat.LONG,
! 					DateFormat.LONG,
! 					objLocale);
! 			return objFormat.format(m_objDate);
! 		}
  	}
  
! 	private static class CurrencyColumn extends SimpleTableColumn
  	{
! 		public CurrencyColumn()
! 		{
! 			super("Currency", true);
! 		}
! 
! 		public Object getColumnValue(Object objRow)
  		{
  			Locale objLocale = (Locale) objRow;
--- 169,215 ----
  	}
  
! 	/**
! 	 * Generates the context that will be passed to the deleteLocale() listener 
! 	 * if a "remove" link is selected. <p>
! 	 * 
! 	 * This is used by the Block rendering the 'Remove' column.
! 	 * 
! 	 * @return String[] the context for the deleteLocale() listener
! 	 */
! 	public String[] getDeleteLocaleContext()
  	{
! 		Locale objLocale = getCurrentLocale();
! 		return new String[] {
! 			objLocale.getLanguage(),
! 			objLocale.getCountry(),
! 			objLocale.getVariant()};
  	}
  
! 	/**
! 	 * A listener invoked when a "remove" link is selected. 
! 	 * It removes from the data model the locale corresponding to the link. <p>
! 	 * 
! 	 * @param objCycle the request cycle
! 	 */
! 	public void deleteLocale(IRequestCycle objCycle)
  	{
! 		Object[] arrParams = objCycle.getServiceParameters();
! 		Locale objLocale =
! 			new Locale(
! 				arrParams[0].toString(),
! 				arrParams[1].toString(),
! 				arrParams[2].toString());
! 		getDataModel().removeRow(objLocale);
  	}
  
! 	/**
! 	 * A class defining the logic for getting the currency symbol from a locale
! 	 */
! 	private static class CurrencyEvaluator implements ITableColumnEvaluator
  	{
! 		/**
! 		 * @see net.sf.tapestry.contrib.table.model.simple.ITableColumnEvaluator#getColumnValue(ITableColumn, Object)
! 		 */
! 		public Object getColumnValue(ITableColumn objColumn, Object objRow)
  		{
  			Locale objLocale = (Locale) objRow;
***************
*** 169,188 ****
  			DecimalFormatSymbols objSymbols =
  				new DecimalFormatSymbols(objLocale);
!             return objSymbols.getCurrencySymbol();
  		}
  	}
  
! 	private static class VerbosityColumn extends SimpleTableColumn
  	{
! 		private VerbosityRating m_objVerbosityRating;
! 		private ComponentAddress m_objComponentAddress;
  
! 		public VerbosityColumn(
! 			VerbosityRating objVerbosityRating,
! 			ComponentAddress objComponentAddress)
  		{
! 			super("Verbosity", true);
! 			m_objVerbosityRating = objVerbosityRating;
! 			m_objComponentAddress = objComponentAddress;
  		}
  
--- 220,238 ----
  			DecimalFormatSymbols objSymbols =
  				new DecimalFormatSymbols(objLocale);
! 			return objSymbols.getCurrencySymbol();
  		}
  	}
  
! 	/**
! 	 * A class defining a column for displaying the date format
! 	 */
! 	private static class DateFormatColumn extends SimpleTableColumn
  	{
! 		private Date m_objDate;
  
! 		public DateFormatColumn(Date objDate)
  		{
! 			super("Date Format", true);
! 			m_objDate = objDate;
  		}
  
***************
*** 190,231 ****
  		{
  			Locale objLocale = (Locale) objRow;
! 			return new Integer(
! 				m_objVerbosityRating.calculateVerbosity(objLocale));
! 		}
! 
! 		public IRender getValueRenderer(
! 			IRequestCycle objCycle,
! 			ITableModelSource objSource,
! 			Object objRow)
! 		{
! 			LocaleSelection objSelection =
! 				(LocaleSelection) m_objComponentAddress.findComponent(objCycle);
! 			objSelection.setCurrentLocale((Locale) objRow);
! 			Block objBlock =
! 				(Block) objSelection.getComponent("blockVerbosity");
! 			return new BlockRenderer(objBlock);
! 		}
! 	}
! 
! 	private static class DeleteColumn extends SimpleTableColumn
! 	{
! 		private ComponentAddress m_objComponentAddress;
! 
! 		public DeleteColumn(ComponentAddress objComponentAddress)
! 		{
! 			super("");
! 			m_objComponentAddress = objComponentAddress;
! 		}
! 
! 		public IRender getValueRenderer(
! 			IRequestCycle objCycle,
! 			ITableModelSource objSource,
! 			Object objRow)
! 		{
! 			LocaleSelection objSelection =
! 				(LocaleSelection) m_objComponentAddress.findComponent(objCycle);
! 			objSelection.setCurrentLocale((Locale) objRow);
! 			Block objBlock = (Block) objSelection.getComponent("blockDelete");
! 			return new BlockRenderer(objBlock);
  		}
  	}
--- 240,249 ----
  		{
  			Locale objLocale = (Locale) objRow;
! 			DateFormat objFormat =
! 				DateFormat.getDateTimeInstance(
! 					DateFormat.LONG,
! 					DateFormat.LONG,
! 					objLocale);
! 			return objFormat.format(m_objDate);
  		}
  	}

Index: LocaleList.jwc
===================================================================
RCS file: /cvsroot/tapestry/Tapestry/examples/Tutorial/src/tutorial/workbench/table/LocaleList.jwc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** LocaleList.jwc	24 Sep 2002 10:54:11 -0000	1.1
--- LocaleList.jwc	23 Dec 2002 12:44:07 -0000	1.2
***************
*** 37,41 ****
  
  	<component id="tableRows" type="contrib:TableRows">
! 		<binding name="value" expression="currentLocale"/>
  		<binding name="class" expression="beans.rowClass.next"/>
  	</component>
--- 37,41 ----
  
  	<component id="tableRows" type="contrib:TableRows">
! 		<binding name="row" expression="currentLocale"/>
  		<binding name="class" expression="beans.rowClass.next"/>
  	</component>



-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.