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 LocaleSelection.java
Date Mon, 29 Dec 2003 00:30:17 GMT
mindbridge    2003/12/28 16:30:17

  Modified:    examples/Workbench/context/WEB-INF LocaleSelection.html
                        LocaleSelection.jwc
               examples/Workbench/src/org/apache/tapestry/workbench/table
                        LocaleSelection.java
  Added:       examples/Workbench/context/WEB-INF
                        LocaleSelection.properties
  Log:
  Modifying the LocaleSelection example component to use the new 
  Table features.
  
  Revision  Changes    Path
  1.2       +4 -4      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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- LocaleSelection.html	5 Mar 2003 23:08:20 -0000	1.1
  +++ LocaleSelection.html	29 Dec 2003 00:30:17 -0000	1.2
  @@ -10,7 +10,7 @@
   <span jwcid="condTable">
   	<hr>
   
  -	<!-- This is the simplest way to insert a table -- a single line in the template.
  +	<!-- This is the simplest way to insert a table - a single line in the template.
       	 Unlike the LocaleList component, in this case all special features are 
       	 enabled in the TableColumnModel, and rendering of the table itself is left 
       	 to the Table component -->
  @@ -21,7 +21,7 @@
   
   
   <!-- This is a block defining how the verbosity column should look like -->
  -<span jwcid="blockVerbosity@Block">
  +<span jwcid="verbosityValueRenderer@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="blockDelete@Block">
  +<span jwcid="deleteValueRenderer@Block">
   	<a jwcid="directDelete">remove</a>
   </span>
   
  
  
  
  1.5       +50 -9     jakarta-tapestry/examples/Workbench/context/WEB-INF/LocaleSelection.jwc
  
  Index: LocaleSelection.jwc
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/examples/Workbench/context/WEB-INF/LocaleSelection.jwc,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- LocaleSelection.jwc	1 Jun 2003 05:05:03 -0000	1.4
  +++ LocaleSelection.jwc	29 Dec 2003 00:30:17 -0000	1.5
  @@ -5,23 +5,64 @@
     "http://jakarta.apache.org/tapestry/dtd/Tapestry_3_0.dtd">
   <component-specification class="org.apache.tapestry.workbench.table.LocaleSelection"
   	allow-body="no" allow-informal-parameters="yes">
  -	<component id="condTable" type="Conditional">
  -		<binding name="condition" expression="dataModel.rowCount > 0"/>
  +	
  +    <component id="condTable" type="Conditional">
  +		<binding name="condition" expression="localeSet.size > 0"/>
   	</component>
  -	<component id="table" type="contrib:Table">
  -		<binding name="tableModel" expression="initialTableModel"/>
  -		<binding name="row" expression="currentLocale"/>
  +	
  +    <!-- Define the Table component that will be used. 
  +         This example demonstrates various techniques for configuring the component. -->
  +    <component id="table" type="contrib:Table">
  +        
  +        <!-- The source of the data for the table will be the localeSet property
  +             defined further down in this file -->
  +        <binding name="source" expression="localeSet"/>
  +        
  +        <!-- The columns of the table -->
  +        <binding name="columns">
  +            <!-- The first column is the representation of the locale returned when
invoking toString() on it.
  +                 Its name will be displayed according to the translation value
  +                 of this component with key 'verbosity' (see LocaleSelection.properties)
-->
  +            'locale:toString(), ' +
  +            
  +            <!-- The next two columns are returned by the Java code as ITableColumn
-->
  +            '=currencyColumn, =dateFormatColumn, ' +
  +            
  +            <!-- The next column is named 'verbosity' and thus will use the 
  +                 verbosityValueRenderer block in this component to render the row values.

  +                 If no translation key 'verbosity' is found, the column will be displayed
as 'Verbosity' -->
  +            'verbosity:Verbosity:@org.apache.tapestry.workbench.table.VerbosityRating@calculateVerbosity(#this),
' +
  +            
  +            <!-- The last column is named 'delete' and is not sortable. Please see the

  +                 deleteValueRenderer block for the definition of how it should look -->

  +            '!delete'
  +        </binding>
  +
  +        <!-- The row object (locale) that is currently being rendered 
  +             will be stored in the currentLocale property (defined further down) -->
  +        <binding name="row" expression="currentLocale"/>
  +        
  +        <!-- Each rendered row will be given the CSS class of 'tableRowsClass' -->
   		<static-binding name="rowsClass" value="tableRowsClass"/>
  +        
   	</component>
  -	<component id="directDelete" type="DirectLink">
  +	
  +    <component id="directDelete" type="DirectLink">
   		<binding name="listener" expression="listeners.deleteLocale"/>
   		<binding name="parameters" expression="deleteLocaleContext"/>
   	</component>
  -	<component id="verbosity" type="Any">
  +	
  +    <component id="verbosity" type="Any">
   		<static-binding name="element" value="td"/>
   		<binding name="style">
   			"background-color:blue; width:"
  -			+ ( currentLocaleVerbosity / 2)
  +			+ (currentLocaleVerbosity / 2) + "px"
   		</binding>
   	</component>
  +    
  +    <property-specification name="localeSet" type="java.util.Set" persistent="yes" 
  +    	initial-value="new java.util.HashSet()"/>
  +
  +    <property-specification name="currentLocale" type="java.util.Locale"/>
  +    
   </component-specification>
  
  
  
  1.1                  jakarta-tapestry/examples/Workbench/context/WEB-INF/LocaleSelection.properties
  
  Index: LocaleSelection.properties
  ===================================================================
  # $Id: LocaleSelection.properties,v 1.1 2003/12/29 00:30:17 mindbridge Exp $
  
  # Column display names
  locale=Locale
  verbosity=Verbosity
  delete=
  
  
  
  1.4       +22 -107   jakarta-tapestry/examples/Workbench/src/org/apache/tapestry/workbench/table/LocaleSelection.java
  
  Index: LocaleSelection.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/examples/Workbench/src/org/apache/tapestry/workbench/table/LocaleSelection.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- LocaleSelection.java	21 May 2003 23:39:14 -0000	1.3
  +++ LocaleSelection.java	29 Dec 2003 00:30:17 -0000	1.4
  @@ -57,32 +57,23 @@
   
   import java.text.DateFormat;
   import java.text.DecimalFormatSymbols;
  -import java.util.Arrays;
   import java.util.Date;
  -import java.util.HashSet;
   import java.util.Locale;
  +import java.util.Set;
   
  +import org.apache.commons.collections.CollectionUtils;
   import org.apache.tapestry.BaseComponent;
   import org.apache.tapestry.IRequestCycle;
  -import org.apache.tapestry.components.Block;
   import org.apache.tapestry.contrib.table.model.ITableColumn;
   import org.apache.tapestry.contrib.table.model.ITableColumnModel;
  -import org.apache.tapestry.contrib.table.model.ITableModel;
  -import org.apache.tapestry.contrib.table.model.ITableModelSource;
  -import org.apache.tapestry.contrib.table.model.ITableRendererSource;
  -import org.apache.tapestry.contrib.table.model.common.BlockTableRendererSource;
  -import org.apache.tapestry.contrib.table.model.ognl.ExpressionTableColumn;
   import org.apache.tapestry.contrib.table.model.simple.ITableColumnEvaluator;
  -import org.apache.tapestry.contrib.table.model.simple.SimpleSetTableDataModel;
   import org.apache.tapestry.contrib.table.model.simple.SimpleTableColumn;
  -import org.apache.tapestry.contrib.table.model.simple.SimpleTableColumnModel;
  -import org.apache.tapestry.contrib.table.model.simple.SimpleTableModel;
   
   /**
    * @author mindbridge
    *
    */
  -public class LocaleSelection extends BaseComponent implements ILocaleSelectionListener
  +public abstract class LocaleSelection extends BaseComponent implements ILocaleSelectionListener
   {
       // immutable
       private ITableColumnModel m_objTableColumnModel;
  @@ -91,6 +82,11 @@
       // temporary
       private Locale m_objCurrentLocale;
   
  +    // properties
  +    public abstract Locale getCurrentLocale();
  +    public abstract Set getLocaleSet();
  +    public abstract void setLocaleSet(Set objLocaleSet);
  +
       /**
        * Creates a new LocaleSelection component
        */
  @@ -100,99 +96,26 @@
       }
   
       /**
  -     * @see org.apache.tapestry.AbstractComponent#finishLoad()
  +     * @see org.apache.tapestry.workbench.table.ILocaleSelectionListener#localesSelected(Locale[])
        */
  -    protected void finishLoad()
  +    public void localesSelected(Locale[] arrLocales)
       {
  -        // We delay the initialization until now, since some columns
  -        // rely on the completed page structure
  -        m_objTableColumnModel = createColumnModel();
  +        Set objLocaleSet = getLocaleSet();
  +        CollectionUtils.addAll(objLocaleSet, arrLocales);
  +        // ensure that the framework knows about the change and the set is persisted
  +        setLocaleSet(objLocaleSet);
       }
   
  -    /**
  -     * 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()
  +    public ITableColumn getCurrencyColumn()
       {
  -        // 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",
  -                "@org.apache.tapestry.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()
  -    {
  -        SimpleSetTableDataModel objLocaleDataModel = new SimpleSetTableDataModel(new HashSet());
  -        return new SimpleTableModel(objLocaleDataModel, m_objTableColumnModel);
  -    }
  -
  -    /**
  -     * Returns the data model used by the displayed table
  -     * @return SimpleSetTableDataModel the data model
  -     */
  -    public SimpleSetTableDataModel getDataModel()
  -    {
  -        ITableModel objTableModel = ((ITableModelSource) getComponent("table")).getTableModel();
  -        SimpleTableModel objSimpleTableModel = (SimpleTableModel) objTableModel;
  -        return (SimpleSetTableDataModel) objSimpleTableModel.getDataModel();
  +        return new SimpleTableColumn("Currency", new CurrencyEvaluator(), true);
       }
   
  -    /**
  -     * Returns the currentLocale.
  -     * @return Locale
  -     */
  -    public Locale getCurrentLocale()
  -    {
  -        return m_objCurrentLocale;
  -    }
  -
  -    /**
  -     * Sets the currentLocale.
  -     * @param currentLocale The currentLocale to set
  -     */
  -    public void setCurrentLocale(Locale currentLocale)
  +    public ITableColumn getDateFormatColumn()
       {
  -        m_objCurrentLocale = currentLocale;
  +        // The entire column is defined using a custom column class
  +        return new DateFormatColumn(new Date());
       }
   
       /**
  @@ -202,16 +125,8 @@
        */
       public int getCurrentLocaleVerbosity()
       {
  -        return VerbosityRating.calculateVerbosity(getCurrentLocale());
  -    }
  -
  -    /**
  -     * @see org.apache.tapestry.workbench.table.ILocaleSelectionListener#localesSelected(Locale[])
  -     */
  -    public void localesSelected(Locale[] arrLocales)
  -    {
  -        SimpleSetTableDataModel objDataModel = getDataModel();
  -        objDataModel.addRows(Arrays.asList(arrLocales));
  +        int nVerbosity = VerbosityRating.calculateVerbosity(getCurrentLocale());
  +        return nVerbosity;
       }
   
       /**
  @@ -242,7 +157,7 @@
           Object[] arrParams = objCycle.getServiceParameters();
           Locale objLocale =
               new Locale(arrParams[0].toString(), arrParams[1].toString(), arrParams[2].toString());
  -        getDataModel().removeRow(objLocale);
  +        getLocaleSet().remove(objLocale);
       }
   
       /**
  
  
  

---------------------------------------------------------------------
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