1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package de.mindcrimeilab.xsanalyzer.model;
19
20 import java.util.ArrayList;
21 import java.util.Collections;
22 import java.util.List;
23 import java.util.Map;
24 import java.util.TreeMap;
25 import java.util.Map.Entry;
26
27 import javax.swing.AbstractListModel;
28 import javax.swing.ListModel;
29
30 import org.apache.xerces.xs.XSObject;
31 import org.apache.xerces.xs.XSObjectList;
32
33 import de.mindcrimeilab.xsanalyzer.util.NameComparator;
34
35
36
37
38
39
40
41
42
43 public class SimilarTypesListModelAdapter extends AbstractListModel implements ListModel {
44
45
46
47
48 private static final long serialVersionUID = -525227687405772834L;
49
50
51
52
53 private final List<Entry<XSObject, String>> model;
54
55
56
57
58
59 private final Map<String, ? extends XSObjectList> data;
60
61
62
63
64
65
66
67 public SimilarTypesListModelAdapter(final Map<String, ? extends XSObjectList> similarTypes) {
68 data = Collections.unmodifiableMap(similarTypes);
69
70
71 Map<XSObject, String> map = new TreeMap<XSObject, String>(new NameComparator());
72
73
74 for (Entry<String, ? extends XSObjectList> entry : data.entrySet()) {
75 XSObjectList list = entry.getValue();
76 for (int i = 0; null != list && i < list.getLength(); ++i) {
77 map.put(list.item(i), entry.getKey());
78 }
79 }
80 model = new ArrayList<Entry<XSObject, String>>(map.entrySet());
81 }
82
83
84
85
86
87
88 @Override
89 public Object getElementAt(int index) {
90 Entry<XSObject, String> entry = model.get(index);
91 return new SimilarTypeListModelEntry(entry.getKey(), entry.getValue(), this.data.get(entry.getValue()));
92 }
93
94
95
96
97
98
99 @Override
100 public int getSize() {
101 return model.size();
102 }
103 }