My favorites
▼
|
Sign in
jmesa
Table Rendering API
Project Home
Downloads
Wiki
Issues
Source
Export to GitHub
READ-ONLY: This project has been
archived
. For more information see
this post
.
Search
Search within:
All issues
Open issues
New issues
Issues to verify
for
Advanced search
Search tips
Subscriptions
Issue
185
attachment: patch.txt
(6.8 KB)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
### Eclipse Workspace Patch 1.0
#P jmesa-trunk
Index: test/org/jmesa/view/html/editor/DroplistFilterEditorTest.java
===================================================================
--- test/org/jmesa/view/html/editor/DroplistFilterEditorTest.java (revision 2227)
+++ test/org/jmesa/view/html/editor/DroplistFilterEditorTest.java (working copy)
@@ -19,8 +19,12 @@
import static org.junit.Assert.assertTrue;
import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
import org.jmesa.core.CoreContext;
+import org.jmesa.core.President;
+import org.jmesa.core.PresidentDao;
import org.jmesa.test.AbstractTestCase;
import org.jmesa.view.component.Column;
import org.jmesa.view.html.component.HtmlColumnImpl;
@@ -51,6 +55,56 @@
assertNotNull("The options are null.", options);
assertTrue("Do not have the correct options size.", options.size() == 35);
- options.iterator().next().getLabel().equals("Abraham");
+ assertTrue(options.iterator().next().getLabel().equals("Abraham"));
}
+
+ @Test
+ public void getPresetOption() {
+ WebContext webContext = createWebContext();
+ CoreContext coreContext = createCoreContext(webContext);
+
+ DroplistFilterEditor editor = new DroplistFilterEditor();
+ editor.setCoreContext(coreContext);
+ editor.setWebContext(webContext);
+
+ Column column = new HtmlColumnImpl("name.firstName");
+
+ editor.setColumn(column);
+
+ Map<String, String> testBean = new HashMap<String, String>();
+ testBean.put("name.firstName", "Abraham");
+ editor.addOption(testBean, "name.firstName", "name.firstName");
+
+ Collection<Option> options = editor.getOptions();
+
+ assertNotNull("The options are null.", options);
+ assertTrue("Do not have the correct options size.", options.size() == 1);
+ assertTrue(options.iterator().next().getLabel().equals("Abraham"));
+ }
+
+ @Test
+ public void getPresetOptions() {
+ WebContext webContext = createWebContext();
+ CoreContext coreContext = createCoreContext(webContext);
+
+ DroplistFilterEditor editor = new DroplistFilterEditor();
+ editor.setCoreContext(coreContext);
+ editor.setWebContext(webContext);
+
+ Column column = new HtmlColumnImpl("name.firstName");
+
+ editor.setColumn(column);
+
+ Collection<President> presidents = PresidentDao.getPresidents();
+ editor.addOptions(presidents, "name.firstName", "name.firstName");
+
+ Collection<Option> options = editor.getOptions();
+
+ assertNotNull("The options are null.", options);
+ assertTrue("Do not have the correct options size: " + options.size(), options.size() == 35);
+
+ Option option = options.iterator().next();
+ assertTrue(option.getLabel().equals("Abraham"));
+
+ }
}
Index: src/org/jmesa/view/html/editor/DroplistFilterEditor.java
===================================================================
--- src/org/jmesa/view/html/editor/DroplistFilterEditor.java (revision 2283)
+++ src/org/jmesa/view/html/editor/DroplistFilterEditor.java (working copy)
@@ -15,6 +15,7 @@
*/
package org.jmesa.view.html.editor;
+import static org.apache.commons.lang.StringEscapeUtils.escapeHtml;
import static org.apache.commons.lang.StringEscapeUtils.escapeJavaScript;
import java.util.ArrayList;
@@ -25,7 +26,6 @@
import java.util.List;
import java.util.Set;
-import static org.apache.commons.lang.StringEscapeUtils.escapeHtml;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.jmesa.limit.Filter;
import org.jmesa.limit.Limit;
@@ -42,6 +42,8 @@
*/
public class DroplistFilterEditor extends AbstractFilterEditor {
+ private Set<Option> options;
+
public Object getValue() {
HtmlBuilder html = new HtmlBuilder();
@@ -79,38 +81,71 @@
return html.toString();
}
+
+ public void addOptions(Collection<?> beans, String valueProperty, String labelProperty) {
+ for (Object bean : beans) {
+ addOption(bean, valueProperty, labelProperty);
+ }
+ }
+ public void addOption(Object bean, String valueProperty, String labelProperty) {
+ Object value = ItemUtils.getItemValue(bean, valueProperty);
+ Object label = ItemUtils.getItemValue(bean, labelProperty);
+ addOption(
+ value == null ? null : String.valueOf(value),
+ label == null ? null : String.valueOf(label)
+ );
+ }
+
+ public void addOption(String value, String label) {
+ if (value == null) {
+ return;
+ } else if (value.length() == 0) {
+ return;
+ }
+ if (label == null || label.length() == 0) {
+ label = value;
+ }
+ this.addOption(new Option(value, label));
+ }
+
+ protected void addOption(Option option) {
+ if (options == null) {
+ options = new HashSet<Option>();
+ }
+ options.add(option);
+ }
+
/**
* @return The unique list of options for the droplist values.
*/
- protected List<Option> getOptions() {
- Set<String> values = new HashSet<String>();
+ protected Collection<Option> getOptions() {
- String property = getColumn().getProperty();
+ final List<Option> options;
- for (Object item : getCoreContext().getAllItems()) {
- Object value = ItemUtils.getItemValue(item, property);
-
- if (value == null) {
- continue;
+ if (this.options == null) {
+ Set<String> values = new HashSet<String>();
+ String property = getColumn().getProperty();
+ for (Object item : getCoreContext().getAllItems()) {
+ Object value = ItemUtils.getItemValue(item, property);
+ if (value == null) {
+ continue;
+ }
+ String valueStr = String.valueOf(value);
+ if (valueStr.length() == 0) {
+ continue;
+ }
+ values.add(valueStr);
}
-
- String valueStr = String.valueOf(value);
-
- if (valueStr.length() == 0) {
- continue;
+ options = new ArrayList<Option>();
+ for (String value : values) {
+ Option option = new Option(value, value);
+ options.add(option);
}
-
- values.add(valueStr);
+ } else {
+ options = new ArrayList<Option>(this.options);
}
-
- List<Option> options = new ArrayList<Option>();
- for (String value : values) {
- Option option = new Option(value, value);
- options.add(option);
- }
-
Collections.sort(options, null);
return options;
Powered by
Google Project Hosting