1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.core.web.namespace; |
17 | |
|
18 | |
import org.kuali.rice.core.impl.namespace.NamespaceBo; |
19 | |
import org.kuali.rice.core.util.ConcreteKeyValue; |
20 | |
import org.kuali.rice.core.util.KeyValue; |
21 | |
import org.kuali.rice.kns.lookup.keyvalues.KeyValuesBase; |
22 | |
import org.kuali.rice.kns.service.KNSServiceLocator; |
23 | |
import org.kuali.rice.kns.service.KeyValuesService; |
24 | |
|
25 | |
import java.util.ArrayList; |
26 | |
import java.util.Collections; |
27 | |
import java.util.Comparator; |
28 | |
import java.util.List; |
29 | |
|
30 | 0 | public class NamespaceValuesFinder extends KeyValuesBase { |
31 | |
|
32 | |
@Override |
33 | |
public List<KeyValue> getKeyValues() { |
34 | |
|
35 | |
|
36 | 0 | KeyValuesService boService = KNSServiceLocator.getKeyValuesService(); |
37 | 0 | List<NamespaceBo> bos = (List<NamespaceBo>) boService.findAll(NamespaceBo.class); |
38 | |
|
39 | 0 | if ( bos == null ) { |
40 | 0 | bos = new ArrayList<NamespaceBo>(0); |
41 | |
} else { |
42 | 0 | bos = new ArrayList<NamespaceBo>( bos ); |
43 | |
} |
44 | |
|
45 | |
|
46 | 0 | Collections.sort(bos, NamespaceComparator.INSTANCE); |
47 | |
|
48 | |
|
49 | 0 | List<KeyValue> labels = new ArrayList<KeyValue>( bos.size() ); |
50 | 0 | labels.add(new ConcreteKeyValue("", "")); |
51 | 0 | for ( NamespaceBo bo : bos ) { |
52 | 0 | labels.add( new ConcreteKeyValue(bo.getCode(), bo.getName() ) ); |
53 | |
} |
54 | 0 | return labels; |
55 | |
} |
56 | |
|
57 | 0 | private static class NamespaceComparator implements Comparator<NamespaceBo> { |
58 | 0 | public static final Comparator<NamespaceBo> INSTANCE = new NamespaceComparator(); |
59 | |
|
60 | |
@Override |
61 | |
public int compare(NamespaceBo o1, NamespaceBo o2) { |
62 | 0 | return o1.getCode().compareTo( o2.getCode() ); |
63 | |
} |
64 | |
} |
65 | |
} |