1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| package org.apache.tapestry.coerce; |
16 |
| |
17 |
| import java.util.ArrayList; |
18 |
| import java.util.List; |
19 |
| |
20 |
| import org.apache.hivemind.util.Defense; |
21 |
| import org.apache.tapestry.form.IPropertySelectionModel; |
22 |
| |
23 |
| |
24 |
| |
25 |
| |
26 |
| |
27 |
| |
28 |
| |
29 |
| |
30 |
| public final class StringConvertedPropertySelectionModel implements IPropertySelectionModel |
31 |
| { |
32 |
| private static class Entry |
33 |
| { |
34 |
| String _label; |
35 |
| |
36 |
| String _value; |
37 |
| |
38 |
14
| Entry(String term)
|
39 |
| { |
40 |
14
| Defense.notNull(term, "term");
|
41 |
| |
42 |
14
| int equalx = term.indexOf('=');
|
43 |
| |
44 |
14
| if (equalx < 0)
|
45 |
| { |
46 |
3
| _label = term.trim();
|
47 |
3
| _value = _label;
|
48 |
| } |
49 |
| else |
50 |
| { |
51 |
11
| _label = term.substring(0, equalx).trim();
|
52 |
11
| _value = term.substring(equalx + 1).trim();
|
53 |
| } |
54 |
| } |
55 |
| } |
56 |
| |
57 |
| private final List _entries; |
58 |
| |
59 |
4
| public StringConvertedPropertySelectionModel(String[] terms)
|
60 |
| { |
61 |
4
| Defense.notNull(terms, "terms");
|
62 |
| |
63 |
4
| _entries = new ArrayList(terms.length);
|
64 |
| |
65 |
4
| for (int i = 0; i < terms.length; i++)
|
66 |
| { |
67 |
14
| _entries.add(new Entry(terms[i]));
|
68 |
| } |
69 |
| } |
70 |
| |
71 |
8
| public int getOptionCount()
|
72 |
| { |
73 |
8
| return _entries.size();
|
74 |
| } |
75 |
| |
76 |
42
| private Entry getEntry(int index)
|
77 |
| { |
78 |
42
| return (Entry) _entries.get(index);
|
79 |
| } |
80 |
| |
81 |
14
| public Object getOption(int index)
|
82 |
| { |
83 |
14
| return getValue(index);
|
84 |
| } |
85 |
| |
86 |
14
| public String getLabel(int index)
|
87 |
| { |
88 |
| |
89 |
14
| return getEntry(index)._label;
|
90 |
| } |
91 |
| |
92 |
28
| public String getValue(int index)
|
93 |
| { |
94 |
28
| return getEntry(index)._value;
|
95 |
| } |
96 |
| |
97 |
0
| public Object translateValue(String value)
|
98 |
| { |
99 |
| |
100 |
0
| return value;
|
101 |
| } |
102 |
| |
103 |
| } |