1
|
package eu.etaxonomy.cdm.remote.editor;
|
2
|
|
3
|
import java.beans.PropertyEditorSupport;
|
4
|
import java.util.ArrayList;
|
5
|
import java.util.List;
|
6
|
import java.util.UUID;
|
7
|
|
8
|
/**
|
9
|
* @author f.revilla
|
10
|
* @since 09.06.2010
|
11
|
*/
|
12
|
|
13
|
public class UUIDListPropertyEditor extends PropertyEditorSupport {
|
14
|
|
15
|
private String nullRepresentation;
|
16
|
|
17
|
public UUIDListPropertyEditor(){
|
18
|
super();
|
19
|
}
|
20
|
|
21
|
public UUIDListPropertyEditor(String nullRepresentation){
|
22
|
super();
|
23
|
this.nullRepresentation = nullRepresentation;
|
24
|
}
|
25
|
|
26
|
@Override
|
27
|
public void setAsText(String text) {
|
28
|
String separator = ",";
|
29
|
List<UUID> uuidList = new ArrayList<>();
|
30
|
if(nullRepresentation != null && nullRepresentation.equals(text)){
|
31
|
uuidList.add(null);
|
32
|
} else if (text.contains(",")){
|
33
|
//set the value for more than one UUID
|
34
|
String[] uuidStringList = text.split(separator);
|
35
|
for (String element : uuidStringList) {
|
36
|
if(nullRepresentation != null && nullRepresentation.equals(element) && !uuidList.contains(null)){
|
37
|
uuidList.add(null);
|
38
|
} else {
|
39
|
uuidList.add(UUID.fromString(element));
|
40
|
}
|
41
|
}
|
42
|
} else if(text.length() > 0){
|
43
|
uuidList.add(UUID.fromString(text));
|
44
|
}
|
45
|
setValue(uuidList);
|
46
|
}
|
47
|
|
48
|
}
|