Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
SortManager |
|
| 1.3333333333333333;1.333 |
1 | package org.jtheque.primary.view.impl.sort; | |
2 | ||
3 | /* | |
4 | * This file is part of JTheque. | |
5 | * | |
6 | * JTheque is free software: you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License as published by | |
8 | * the Free Software Foundation, either version 3 of the License. | |
9 | * | |
10 | * JTheque is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | * GNU General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License | |
16 | * along with JTheque. If not, see <http://www.gnu.org/licenses/>. | |
17 | */ | |
18 | ||
19 | import org.jtheque.primary.utils.DataTypeManager; | |
20 | import org.jtheque.primary.view.impl.models.tree.JThequeTreeModel; | |
21 | import org.jtheque.primary.view.impl.models.tree.RootElement; | |
22 | import org.jtheque.primary.view.impl.models.tree.TreeElement; | |
23 | ||
24 | /** | |
25 | * Manage the sort of the tree model. | |
26 | * | |
27 | * @author Baptiste Wicht | |
28 | */ | |
29 | public final class SortManager { | |
30 | private final SorterFactory factory; | |
31 | ||
32 | /** | |
33 | * Construct a new <code>SortManager</code>. | |
34 | */ | |
35 | public SortManager(){ | |
36 | 0 | super(); |
37 | ||
38 | 0 | factory = SorterFactory.getInstance(); |
39 | 0 | } |
40 | ||
41 | /** | |
42 | * Sort the model with specific content and type of sort. | |
43 | * | |
44 | * @param model The model of the JTree | |
45 | * @param content The content of the model | |
46 | * @param sortType The type of sort | |
47 | */ | |
48 | public void sort(JThequeTreeModel model, String content, String sortType){ | |
49 | 0 | TreeElement root = model.getRoot(); |
50 | ||
51 | 0 | root.clear(); |
52 | ||
53 | 0 | Sorter sorter = factory.getSorter(content, sortType); |
54 | ||
55 | 0 | if (sorter != null){ |
56 | 0 | sorter.sort(model); |
57 | } | |
58 | 0 | } |
59 | ||
60 | /** | |
61 | * Create a model with initial content. | |
62 | * | |
63 | * @param type The type of content | |
64 | * | |
65 | * @return The model initiated | |
66 | */ | |
67 | public JThequeTreeModel createInitialModel(String type){ | |
68 | 0 | TreeElement root = new RootElement(DataTypeManager.getTextForDataType(type)); |
69 | ||
70 | 0 | JThequeTreeModel model = new JThequeTreeModel(root); |
71 | ||
72 | 0 | sort(model, type, "None"); |
73 | ||
74 | 0 | return model; |
75 | } | |
76 | } |