Clover coverage report - Code Coverage for tapestry-contrib release 4.0-alpha-3
Coverage timestamp: Mon May 16 2005 09:12:41 EDT
file stats: LOC: 118   Methods: 7
NCLOC: 64   Classes: 3
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
PaletteColumn.java 0% 0% 0% 0%
coverage
 1   
 // Copyright 2004, 2005 The Apache Software Foundation
 2   
 //
 3   
 // Licensed under the Apache License, Version 2.0 (the "License");
 4   
 // you may not use this file except in compliance with the License.
 5   
 // You may obtain a copy of the License at
 6   
 //
 7   
 //     http://www.apache.org/licenses/LICENSE-2.0
 8   
 //
 9   
 // Unless required by applicable law or agreed to in writing, software
 10   
 // distributed under the License is distributed on an "AS IS" BASIS,
 11   
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12   
 // See the License for the specific language governing permissions and
 13   
 // limitations under the License.
 14   
 
 15   
 package org.apache.tapestry.contrib.palette;
 16   
 
 17   
 import java.util.ArrayList;
 18   
 import java.util.Collections;
 19   
 import java.util.Comparator;
 20   
 import java.util.List;
 21   
 
 22   
 import org.apache.tapestry.IMarkupWriter;
 23   
 import org.apache.tapestry.IRender;
 24   
 import org.apache.tapestry.IRequestCycle;
 25   
 
 26   
 /**
 27   
  * One of the two columns in a Palette component: the left column lists
 28   
  * available options, the right column lists the selected columns.
 29   
  *
 30   
  * @author Howard Lewis Ship
 31   
  */
 32   
 public class PaletteColumn implements IRender
 33   
 {
 34   
     private String _name;
 35   
     private int _rows;
 36   
     private List _options = new ArrayList();
 37   
 
 38   
     private static class ValueComparator implements Comparator
 39   
     {
 40  0
         public int compare(Object o1, Object o2)
 41   
         {
 42  0
             PaletteOption option1 = (PaletteOption) o1;
 43  0
             PaletteOption option2 = (PaletteOption) o2;
 44   
 
 45  0
             return option1.getValue().compareTo(option2.getValue());
 46   
         }
 47   
     }
 48   
 
 49   
     private static class LabelComparator implements Comparator
 50   
     {
 51  0
         public int compare(Object o1, Object o2)
 52   
         {
 53  0
             PaletteOption option1 = (PaletteOption) o1;
 54  0
             PaletteOption option2 = (PaletteOption) o2;
 55   
 
 56  0
             return option1.getLabel().compareTo(option2.getLabel());
 57   
         }
 58   
     }
 59   
 
 60   
     /**
 61   
      * @param name the name of the column (the name attribute of the <select>)
 62   
      * @param rows the number of visible rows (the size attribute of the <select>)
 63   
      */
 64  0
     public PaletteColumn(String name, int rows)
 65   
     {
 66  0
         _name = name;
 67  0
         _rows = rows;
 68   
     }
 69   
 
 70  0
     public void addOption(PaletteOption option)
 71   
     {
 72  0
         _options.add(option);
 73   
     }
 74   
 
 75   
     /**
 76   
      * Sorts the options by value (the hidden value for the option
 77   
      * that represents the object value). This should be invoked
 78   
      * before rendering this PaletteColumn.
 79   
      */
 80  0
     public void sortByValue()
 81   
     {
 82  0
         Collections.sort(_options, new ValueComparator());
 83   
     }
 84   
 
 85   
     /**
 86   
      * Sorts the options by the label visible to the user. This should be invoked
 87   
      * before rendering this PaletteColumn.
 88   
      */
 89  0
     public void sortByLabel()
 90   
     {
 91  0
         Collections.sort(_options, new LabelComparator());
 92   
     }
 93   
 
 94   
     /**
 95   
      * Renders the <select> and <option> tags for
 96   
      * this column.
 97   
      */
 98  0
     public void render(IMarkupWriter writer, IRequestCycle cycle)
 99   
     {
 100  0
         writer.begin("select");
 101  0
         writer.attribute("multiple", "multiple");
 102  0
         writer.attribute("name", _name);
 103  0
         writer.attribute("size", _rows);
 104  0
         writer.println();
 105   
 
 106  0
         int count = _options.size();
 107  0
         for (int i = 0; i < count; i++)
 108   
         {
 109  0
             PaletteOption o = (PaletteOption) _options.get(i);
 110   
 
 111  0
             o.render(writer, cycle);
 112   
         }
 113   
 
 114  0
         writer.end();
 115   
     }
 116   
 
 117   
 }
 118