tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mindbri...@apache.org
Subject cvs commit: jakarta-tapestry/examples/Workbench/src/org/apache/tapestry/workbench/table LocaleList.java
Date Wed, 07 Jan 2004 01:15:30 GMT
mindbridge    2004/01/06 17:15:30

  Modified:    examples/Workbench/context/WEB-INF LocaleSelection.html
                        LocaleList.jwc LocaleList.html
               examples/Workbench/src/org/apache/tapestry/workbench/table
                        LocaleList.java
  Log:
  Updating the Table example in the Workbench
  
  Revision  Changes    Path
  1.3       +3 -3      jakarta-tapestry/examples/Workbench/context/WEB-INF/LocaleSelection.html
  
  Index: LocaleSelection.html
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/examples/Workbench/context/WEB-INF/LocaleSelection.html,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- LocaleSelection.html	29 Dec 2003 00:30:17 -0000	1.2
  +++ LocaleSelection.html	7 Jan 2004 01:15:30 -0000	1.3
  @@ -21,7 +21,7 @@
   
   
   <!-- This is a block defining how the verbosity column should look like -->
  -<span jwcid="verbosityValueRenderer@Block">
  +<span jwcid="verbosityColumnValue@Block">
   	<table style="border: 1px black solid; width: 100px; height: 15px;">
   		<tr style="border: 1px black solid; width: 100px; height: 15px;">
   			<td jwcid="verbosity"></td>
  @@ -32,7 +32,7 @@
   
   
   <!-- This is a block defining how the remove column should look like -->
  -<span jwcid="deleteValueRenderer@Block">
  +<span jwcid="deleteColumnValue@Block">
   	<a jwcid="directDelete">remove</a>
   </span>
   
  
  
  
  1.5       +7 -3      jakarta-tapestry/examples/Workbench/context/WEB-INF/LocaleList.jwc
  
  Index: LocaleList.jwc
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/examples/Workbench/context/WEB-INF/LocaleList.jwc,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- LocaleList.jwc	6 Sep 2003 14:06:51 -0000	1.4
  +++ LocaleList.jwc	7 Jan 2004 01:15:30 -0000	1.5
  @@ -33,14 +33,18 @@
   	</component>
   
   	<component id="tableView" type="contrib:TableView">
  -		<binding name="tableModel" expression="tableModel"/>
  -		<binding name="tableSessionStateManager" expression="tableSessionStateManager"/>
  +        <binding name="source" expression="@java.util.Locale@getAvailableLocales()"/>
  +        <binding name="columns">
  +            '* Locale:toString(), Language:displayLanguage, Country:displayCountry, ' +
  +            'Variant:displayVariant, ISO Language:ISO3Language, ISO Country:ISO3Country'
  +        </binding>
   	</component>
   
   	<component id="tableColumns" type="contrib:TableColumns"/>
   
   	<component id="tableRows" type="contrib:TableFormRows">
   		<binding name="row" expression="currentLocale"/>
  +        <binding name="convertor" expression="localeConvertor"/>
   		<binding name="class" expression="beans.rowClass.next"/>
   	</component>
   
  
  
  
  1.3       +20 -4     jakarta-tapestry/examples/Workbench/context/WEB-INF/LocaleList.html
  
  Index: LocaleList.html
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/examples/Workbench/context/WEB-INF/LocaleList.html,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- LocaleList.html	6 Sep 2003 14:06:51 -0000	1.2
  +++ LocaleList.html	7 Jan 2004 01:15:30 -0000	1.3
  @@ -4,13 +4,29 @@
   
   <form jwcid="form">
   
  -	<!-- In this example we use a custom layout for the table (usually done 
  +	<!-- This component could be implemented using the FormTable component
  +		 in the following way:
  +		 
  +	     <table jwcid="@contrib:FormTable" width="100%"
  +    		source="ognl:@java.util.Locale@getAvailableLocales()"
  +    		columns="!checkbox, Locale:toString(), Language:displayLanguage, Country:displayCountry,

  +            	Variant:displayVariant, ISO Language:ISO3Language, ISO Country:ISO3Country"
  +	    	row="ognl:currentLocale"
  +     		rowsClass="ognl:beans.rowClass.next"/>
  +    	 <span jwcid="checkboxColumnHeader@Block"></span>
  +	     <span jwcid="checkboxColumnValue@Block"><span jwcid="checkbox"/></span>
  +		 
  +		 Instead, in this example we use a custom layout for the table (usually done 
   	     for greater flexibility), rather than the standard one provided 
   	     by the Table component. We use the lower level Table components instead 
   	     and lay them out in our own way. -->
   
   	<table jwcid="tableView" width="100%">
  -		<span jwcid="tablePages@contrib:TableFormPages"/>
  +		<tr>
  +            <td colspan="7">
  +        		<span jwcid="tablePages@contrib:TableFormPages"/>
  +            </td>
  +        </tr>
   		
   		<tr>
   			<td></td>
  @@ -22,7 +38,7 @@
   			<td jwcid="tableValues" align="center"/>
   		</tr>
   	</table>
  -
  +    
   	<span jwcid="submitButton"/>
   
   </form>
  
  
  
  1.3       +36 -99    jakarta-tapestry/examples/Workbench/src/org/apache/tapestry/workbench/table/LocaleList.java
  
  Index: LocaleList.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/examples/Workbench/src/org/apache/tapestry/workbench/table/LocaleList.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- LocaleList.java	6 Sep 2003 14:06:51 -0000	1.2
  +++ LocaleList.java	7 Jan 2004 01:15:30 -0000	1.3
  @@ -56,24 +56,14 @@
   package org.apache.tapestry.workbench.table;
   
   import java.util.HashSet;
  -import java.util.Iterator;
   import java.util.Locale;
   import java.util.Set;
  +import java.util.StringTokenizer;
   
   import org.apache.tapestry.BaseComponent;
   import org.apache.tapestry.IBinding;
   import org.apache.tapestry.IRequestCycle;
  -import org.apache.tapestry.contrib.table.model.ITableColumnModel;
  -import org.apache.tapestry.contrib.table.model.ITableDataModel;
  -import org.apache.tapestry.contrib.table.model.ITableModel;
  -import org.apache.tapestry.contrib.table.model.ITableRendererSource;
  -import org.apache.tapestry.contrib.table.model.ITableSessionStateManager;
  -import org.apache.tapestry.contrib.table.model.ognl.ExpressionTableColumn;
  -import org.apache.tapestry.contrib.table.model.ognl.ExpressionTableColumnModel;
  -import org.apache.tapestry.contrib.table.model.simple.SimpleListTableDataModel;
  -import org.apache.tapestry.contrib.table.model.simple.SimpleTableColumnFormRendererSource;
  -import org.apache.tapestry.contrib.table.model.simple.SimpleTableSessionStateManager;
  -import org.apache.tapestry.contrib.table.model.simple.SimpleTableState;
  +import org.apache.tapestry.contrib.table.model.IPrimaryKeyConvertor;
   
   /**
    * @author mindbridge
  @@ -82,96 +72,43 @@
   public abstract class LocaleList extends BaseComponent
   {
       // immutable values
  -	private ITableSessionStateManager m_objTableSessionStateManager;
  -
  -    /**
  -     * @see org.apache.tapestry.AbstractComponent#finishLoad()
  -     */
  -    protected void finishLoad()
  +	private IPrimaryKeyConvertor m_objLocaleConvertor;
  +    
  +    public LocaleList()
       {
  -        super.finishLoad();
  -        initTableSessionStateManager();
  +        m_objLocaleConvertor = new IPrimaryKeyConvertor()
  +        {
  +            public Object getPrimaryKey(Object objValue)
  +            {
  +                Locale objLocale = (Locale) objValue;
  +                return objValue.toString();
  +            }
  +
  +            public Object getValue(Object objPrimaryKey)
  +            {
  +                StringTokenizer objTokenizer = new StringTokenizer((String) objPrimaryKey,
"_");
  +
  +                String strLanguage = "";
  +                if (objTokenizer.hasMoreTokens())
  +                    strLanguage = objTokenizer.nextToken(); 
  +
  +                String strCountry = "";
  +                if (objTokenizer.hasMoreTokens())
  +                    strCountry = objTokenizer.nextToken(); 
  +
  +                String strVariant = "";
  +                if (objTokenizer.hasMoreTokens())
  +                    strVariant = objTokenizer.nextToken();
  +                
  +                return new Locale(strLanguage, strCountry, strVariant); 
  +            }
  +        };
       }
       
  -	/**
  -	 * Method initTableSessionStateManager.
  -	 * Creates the Table Session State Manager, and thus determines what part
  -	 * of the table model will be saved in the session.
  -     * See comments for details
  -	 */
  -	protected void initTableSessionStateManager()
  -	{
  -		// Use the simple data model using the array of standard Locales
  -		ITableDataModel objDataModel =
  -			new SimpleListTableDataModel(Locale.getAvailableLocales());
  -
  -		// This is a simple to use column model that uses OGNL to access
  -		// the data to be displayed in each column. The first string is
  -		// the name of the column, and the second is the OGNL expression.
  -		// We also enable sorting for all columns by setting the second argument to true
  -		ITableColumnModel objColumnModel =
  -			new ExpressionTableColumnModel(
  -				new String[] {
  -                    "Locale", "toString()",
  -					"Language", "displayLanguage",
  -					"Country", "displayCountry",
  -					"Variant", "displayVariant",
  -                    "ISO Language", "ISO3Language",
  -                    "ISO Country", "ISO3Country", 
  -                    },
  -				true);
  -
  -
  -        // Modify the columns to render headers designed for use in a form. 
  -        // These headers ensure that the form is submitted when clicking on them
  -        // and sorting by the column so that current form selections are preserved.
  -        // Skip this if the table is not used in a form or you do not need 
  -        // that behaviour.  
  -        // This is usually used in conjunction with the TableFormPages and
  -        // the TableFormRows components.
  -        ITableRendererSource objRendererSource = new SimpleTableColumnFormRendererSource();
  -        for (Iterator it = objColumnModel.getColumns(); it.hasNext(); ) {
  -            ExpressionTableColumn objColumn = (ExpressionTableColumn) it.next();
  -            objColumn.setColumnRendererSource(objRendererSource);
  -        }
  -
  -
  -		// Here we make a choice as to how the table would operate: 
  -		//
  -		// We select a session state manager that stores only the table state 
  -		// in the session. This makes the session state very small, but it causes 
  -		// the table model to be recreated every time (note that the data and 
  -		// column models remain the same -- they are created only once here). 
  -		// The recreation of the table model means sorting of the locales 
  -		// according the the state will be invoked every time the page is displayed.
  -		//
  -		// Essentially in this case we sacrfice CPU load for memory, and since 
  -		// the amount of data (the number of locales) may be significant, 
  -		// this approach should behave much better when there are many users.
  -		m_objTableSessionStateManager =
  -			new SimpleTableSessionStateManager(objDataModel, objColumnModel);
  -	}
  -
  -	/**
  -	 * Method getTableModel.
  -	 * @return ITableModel the initial Table Model to use
  -	 */
  -	public ITableModel getTableModel()
  -	{
  -		// Use the Session State Manager to create an initial table model 
  -		// with an initial state (no sorting, show first page)
  -		return m_objTableSessionStateManager.recreateTableModel(
  -			new SimpleTableState());
  -	}
  -
  -	/**
  -	 * Method getTableSessionStateManager.
  -	 * @return ITableSessionStateManager the Table Session State Manager to use
  -	 */
  -	public ITableSessionStateManager getTableSessionStateManager()
  -	{
  -		return m_objTableSessionStateManager;
  -	}
  +    public IPrimaryKeyConvertor getLocaleConvertor()
  +    {
  +        return m_objLocaleConvertor;
  +    }
   
       public boolean getCheckboxSelected() 
       {
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-dev-help@jakarta.apache.org


Mime
View raw message