Clover coverage report - Code Coverage for tapestry-contrib release 4.0.1
Coverage timestamp: Fri Mar 31 2006 09:15:40 EST
file stats: LOC: 126   Methods: 7
NCLOC: 68   Classes: 3
 
 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 available options, the right
 28    * column lists the selected columns.
 29    *
 30    * @author Howard Lewis Ship
 31    */
 32    public class PaletteColumn implements IRender
 33    {
 34    private String _name;
 35   
 36    private String _clientId;
 37   
 38    private int _rows;
 39   
 40    private List _options = new ArrayList();
 41   
 42    private static class ValueComparator implements Comparator
 43    {
 44  0 public int compare(Object o1, Object o2)
 45    {
 46  0 PaletteOption option1 = (PaletteOption) o1;
 47  0 PaletteOption option2 = (PaletteOption) o2;
 48   
 49  0 return option1.getValue().compareTo(option2.getValue());
 50    }
 51    }
 52   
 53    private static class LabelComparator implements Comparator
 54    {
 55  0 public int compare(Object o1, Object o2)
 56    {
 57  0 PaletteOption option1 = (PaletteOption) o1;
 58  0 PaletteOption option2 = (PaletteOption) o2;
 59   
 60  0 return option1.getLabel().compareTo(option2.getLabel());
 61    }
 62    }
 63   
 64    /**
 65    * @param name
 66    * the name of the column (the name attribute of the <select>)
 67    * @param rows
 68    * the number of visible rows (the size attribute of the <select>)
 69    */
 70  0 public PaletteColumn(String name, String clientId, int rows)
 71    {
 72  0 _name = name;
 73  0 _clientId = clientId;
 74  0 _rows = rows;
 75    }
 76   
 77  0 public void addOption(PaletteOption option)
 78    {
 79  0 _options.add(option);
 80    }
 81   
 82    /**
 83    * Sorts the options by value (the hidden value for the option that represents the object
 84    * value). This should be invoked before rendering this PaletteColumn.
 85    */
 86  0 public void sortByValue()
 87    {
 88  0 Collections.sort(_options, new ValueComparator());
 89    }
 90   
 91    /**
 92    * Sorts the options by the label visible to the user. This should be invoked before rendering
 93    * this PaletteColumn.
 94    */
 95  0 public void sortByLabel()
 96    {
 97  0 Collections.sort(_options, new LabelComparator());
 98    }
 99   
 100    /**
 101    * Renders the <select> and <option> tags for this column.
 102    */
 103  0 public void render(IMarkupWriter writer, IRequestCycle cycle)
 104    {
 105  0 writer.begin("select");
 106  0 writer.attribute("multiple", "multiple");
 107  0 writer.attribute("name", _name);
 108   
 109  0 if (_clientId != null)
 110  0 writer.attribute("id", _clientId);
 111   
 112  0 writer.attribute("size", _rows);
 113  0 writer.println();
 114   
 115  0 int count = _options.size();
 116  0 for (int i = 0; i < count; i++)
 117    {
 118  0 PaletteOption o = (PaletteOption) _options.get(i);
 119   
 120  0 o.render(writer, cycle);
 121    }
 122   
 123  0 writer.end();
 124    }
 125   
 126    }