Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
RecentlyViewedHelper |
|
| 3.4;3.4 |
1 | package org.kuali.student.lum.common.client.helpers; | |
2 | ||
3 | import java.util.ArrayList; | |
4 | import java.util.List; | |
5 | ||
6 | import org.kuali.student.common.ui.client.mvc.history.HistoryManager; | |
7 | ||
8 | 0 | public class RecentlyViewedHelper{ |
9 | ||
10 | 0 | public static List<RecentDocInfo> recentlyViewedDocs = new ArrayList<RecentDocInfo>(); |
11 | 0 | public static List<HasRecentlyViewedData> dependants = new ArrayList<HasRecentlyViewedData>(); |
12 | public static final int MAX_RECENT_HISTORY = 8; | |
13 | ||
14 | public static void addCurrentDocument(String name){ | |
15 | 0 | RecentDocInfo info = new RecentDocInfo(name, HistoryManager.collectHistoryStack()); |
16 | 0 | for(int i=0; i < recentlyViewedDocs.size(); i++){ |
17 | 0 | if(info.getLocation().equals(recentlyViewedDocs.get(i).getLocation())){ |
18 | 0 | recentlyViewedDocs.remove(i); |
19 | 0 | break; |
20 | } | |
21 | } | |
22 | 0 | recentlyViewedDocs.add(0, info); |
23 | 0 | if(recentlyViewedDocs.size() > MAX_RECENT_HISTORY){ |
24 | 0 | recentlyViewedDocs.remove(MAX_RECENT_HISTORY); |
25 | } | |
26 | 0 | for(int i =0; i < dependants.size(); i++){ |
27 | 0 | dependants.get(i).update(); |
28 | } | |
29 | 0 | } |
30 | ||
31 | public static void addDocument(String name, String specificLocation){ | |
32 | 0 | RecentDocInfo info = new RecentDocInfo(name, specificLocation); |
33 | 0 | for(int i=0; i < recentlyViewedDocs.size(); i++){ |
34 | 0 | if(info.getLocation().equals(recentlyViewedDocs.get(i).getLocation())){ |
35 | 0 | recentlyViewedDocs.remove(i); |
36 | 0 | break; |
37 | } | |
38 | } | |
39 | 0 | recentlyViewedDocs.add(0, info); |
40 | 0 | if(recentlyViewedDocs.size() > MAX_RECENT_HISTORY){ |
41 | 0 | recentlyViewedDocs.remove(MAX_RECENT_HISTORY + 1); |
42 | } | |
43 | 0 | for(int i =0; i < dependants.size(); i++){ |
44 | 0 | dependants.get(i).update(); |
45 | } | |
46 | 0 | } |
47 | ||
48 | public static List<RecentDocInfo> getRecentlyViewed(){ | |
49 | 0 | return recentlyViewedDocs; |
50 | } | |
51 | ||
52 | public static void addDependant(HasRecentlyViewedData object){ | |
53 | 0 | dependants.add(object); |
54 | 0 | } |
55 | ||
56 | public static void updateTitle(String oldTitle, String newTitle, String docId) { | |
57 | 0 | for(int i=0; i < recentlyViewedDocs.size(); i++){ |
58 | 0 | if(oldTitle.equals(recentlyViewedDocs.get(i).getName()) |
59 | && recentlyViewedDocs.get(i).getLocation().contains(docId)){ | |
60 | 0 | recentlyViewedDocs.get(i).setName(newTitle); |
61 | 0 | break; |
62 | } | |
63 | } | |
64 | 0 | for(int i =0; i < dependants.size(); i++){ |
65 | 0 | dependants.get(i).update(); |
66 | } | |
67 | 0 | } |
68 | ||
69 | } |