1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
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 |
| |
28 |
| |
29 |
| |
30 |
| |
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 |
| |
66 |
| |
67 |
| |
68 |
| |
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 |
| |
84 |
| |
85 |
| |
86 |
0
| public void sortByValue()
|
87 |
| { |
88 |
0
| Collections.sort(_options, new ValueComparator());
|
89 |
| } |
90 |
| |
91 |
| |
92 |
| |
93 |
| |
94 |
| |
95 |
0
| public void sortByLabel()
|
96 |
| { |
97 |
0
| Collections.sort(_options, new LabelComparator());
|
98 |
| } |
99 |
| |
100 |
| |
101 |
| |
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 |
| } |