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.core.utils.db.Note; |
20 | |
import org.jtheque.films.controllers.able.IFilmController; |
21 | |
import org.jtheque.films.persistence.od.able.Film; |
22 | |
import org.jtheque.films.services.able.IRealizersService; |
23 | |
import org.jtheque.primary.view.impl.models.tree.Category; |
24 | |
import org.jtheque.primary.view.impl.models.tree.JThequeTreeModel; |
25 | |
import org.jtheque.primary.view.impl.models.tree.TreeElement; |
26 | |
import org.jtheque.primary.view.impl.sort.Sorter; |
27 | |
|
28 | |
import javax.annotation.Resource; |
29 | |
import java.util.ArrayList; |
30 | |
import java.util.List; |
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | 0 | public final class ByRealizerSorter implements Sorter { |
38 | |
@Resource |
39 | |
private IFilmController filmController; |
40 | |
|
41 | |
@Override |
42 | |
public boolean canSort(String content, String sortType) { |
43 | 0 | return content.equals(filmController.getDataType()) && sortType.equals(IRealizersService.DATA_TYPE); |
44 | |
} |
45 | |
|
46 | |
@Override |
47 | |
public void sort(JThequeTreeModel model) { |
48 | 0 | TreeElement root = model.getRoot(); |
49 | |
|
50 | 0 | List<Note> groups = new ArrayList<Note>(filmController.getDisplayList().size() / 4); |
51 | |
|
52 | 0 | for (Film film : filmController.getDisplayList()) { |
53 | 0 | Note note = film.getNote(); |
54 | |
|
55 | 0 | if (!groups.contains(note)) { |
56 | 0 | groups.add(note); |
57 | 0 | root.add(new Category(note.getElementName())); |
58 | |
} |
59 | |
|
60 | 0 | root.getChild(groups.indexOf(note)).add(film); |
61 | 0 | } |
62 | |
|
63 | 0 | model.setRootElement(root); |
64 | 0 | } |
65 | |
} |