1 | |
package org.jtheque.films.view.impl.sort; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
import org.jtheque.films.controllers.able.IFilmController; |
20 | |
import org.jtheque.films.persistence.od.able.Film; |
21 | |
import org.jtheque.films.services.able.IFilmsService; |
22 | |
import org.jtheque.primary.od.able.Kind; |
23 | |
import org.jtheque.primary.services.able.IKindsService; |
24 | |
import org.jtheque.primary.view.impl.models.tree.Category; |
25 | |
import org.jtheque.primary.view.impl.models.tree.JThequeTreeModel; |
26 | |
import org.jtheque.primary.view.impl.models.tree.TreeElement; |
27 | |
import org.jtheque.primary.view.impl.sort.Sorter; |
28 | |
|
29 | |
import javax.annotation.Resource; |
30 | |
import java.util.ArrayList; |
31 | |
import java.util.List; |
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | 0 | public final class ByKindSorter implements Sorter { |
39 | |
@Resource |
40 | |
private IFilmController filmController; |
41 | |
|
42 | |
@Override |
43 | |
public boolean canSort(String content, String sortType) { |
44 | 0 | return IFilmsService.DATA_TYPE.equals(content) && sortType.equals(IKindsService.DATA_TYPE); |
45 | |
} |
46 | |
|
47 | |
@Override |
48 | |
public void sort(JThequeTreeModel model) { |
49 | 0 | TreeElement root = model.getRoot(); |
50 | |
|
51 | 0 | List<Kind> groups = new ArrayList<Kind>(10); |
52 | |
|
53 | 0 | for (Film film : filmController.getDisplayList()) { |
54 | 0 | for (Kind kind : film.getKinds()) { |
55 | 0 | if (!groups.contains(kind)) { |
56 | 0 | root.add(new Category(kind.getElementName())); |
57 | 0 | groups.add(kind); |
58 | |
} |
59 | |
|
60 | 0 | int index = groups.indexOf(kind); |
61 | |
|
62 | 0 | root.getChild(index).add(film); |
63 | 0 | } |
64 | |
} |
65 | |
|
66 | 0 | model.setRootElement(root); |
67 | 0 | } |
68 | |
} |