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.services.able.INotesService; |
21 | |
import org.jtheque.primary.controller.able.IPrincipalController; |
22 | |
import org.jtheque.primary.od.able.Data; |
23 | |
import org.jtheque.primary.od.able.Notable; |
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 java.util.ArrayList; |
30 | |
import java.util.List; |
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
public final class ByNoteSorter implements Sorter { |
38 | |
private final IPrincipalController<? extends Data> controller; |
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | 0 | public ByNoteSorter(IPrincipalController<? extends Data> controller) { |
46 | 0 | this.controller = controller; |
47 | 0 | } |
48 | |
|
49 | |
@Override |
50 | |
public boolean canSort(String content, String sortType) { |
51 | 0 | return content.equals(controller.getDataType()) && sortType.equals(INotesService.DATA_TYPE); |
52 | |
} |
53 | |
|
54 | |
@Override |
55 | |
public void sort(JThequeTreeModel model) { |
56 | 0 | TreeElement root = model.getRoot(); |
57 | |
|
58 | 0 | List<Note> groups = new ArrayList<Note>(7); |
59 | |
|
60 | 0 | for (Data data : controller.getDisplayList()) { |
61 | 0 | Note note = ((Notable) data).getNote(); |
62 | |
|
63 | 0 | if (!groups.contains(note)) { |
64 | 0 | groups.add(note); |
65 | 0 | root.add(new Category(note.getElementName())); |
66 | |
} |
67 | |
|
68 | 0 | root.getChild(groups.indexOf(note)).add(data); |
69 | 0 | } |
70 | |
|
71 | 0 | model.setRootElement(root); |
72 | 0 | } |
73 | |
} |