1 |
| package photospace.beans; |
2 |
| |
3 |
| import java.beans.*; |
4 |
| import java.util.*; |
5 |
| import org.apache.commons.lang.*; |
6 |
| |
7 |
| public class CollectionEditor extends PropertyEditorSupport |
8 |
| { |
9 |
| |
10 |
| private Class collectionImpl; |
11 |
| private String split; |
12 |
| private String join; |
13 |
| |
14 |
0
| public CollectionEditor(Class collectionImpl, String split, String join)
|
15 |
| { |
16 |
0
| this.collectionImpl = collectionImpl;
|
17 |
0
| this.split = split;
|
18 |
0
| this.join = join;
|
19 |
| } |
20 |
| |
21 |
0
| public void setAsText(String text) throws IllegalArgumentException
|
22 |
| { |
23 |
0
| try
|
24 |
| { |
25 |
0
| Collection c = (Collection) collectionImpl.newInstance();
|
26 |
0
| if (text != null || !"".equals(text.trim()))
|
27 |
0
| c.addAll(Arrays.asList(StringUtils.split(text, split)));
|
28 |
0
| setValue(c);
|
29 |
| } |
30 |
| catch (Exception e) |
31 |
| { |
32 |
0
| throw new IllegalArgumentException("Error converting " + text + " to a " + collectionImpl.getName());
|
33 |
| } |
34 |
| } |
35 |
| |
36 |
0
| public String getAsText()
|
37 |
| { |
38 |
0
| return StringUtils.join(((Collection) getValue()).iterator(), join);
|
39 |
| } |
40 |
| |
41 |
| } |