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 public class RecentlyViewedHelper{ 9 10 public static List<RecentDocInfo> recentlyViewedDocs = new ArrayList<RecentDocInfo>(); 11 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 RecentDocInfo info = new RecentDocInfo(name, HistoryManager.collectHistoryStack()); 16 for(int i=0; i < recentlyViewedDocs.size(); i++){ 17 if(info.getLocation().equals(recentlyViewedDocs.get(i).getLocation())){ 18 recentlyViewedDocs.remove(i); 19 break; 20 } 21 } 22 recentlyViewedDocs.add(0, info); 23 if(recentlyViewedDocs.size() > MAX_RECENT_HISTORY){ 24 recentlyViewedDocs.remove(MAX_RECENT_HISTORY); 25 } 26 for(int i =0; i < dependants.size(); i++){ 27 dependants.get(i).update(); 28 } 29 } 30 31 public static void addDocument(String name, String specificLocation){ 32 RecentDocInfo info = new RecentDocInfo(name, specificLocation); 33 for(int i=0; i < recentlyViewedDocs.size(); i++){ 34 if(info.getLocation().equals(recentlyViewedDocs.get(i).getLocation())){ 35 recentlyViewedDocs.remove(i); 36 break; 37 } 38 } 39 recentlyViewedDocs.add(0, info); 40 if(recentlyViewedDocs.size() > MAX_RECENT_HISTORY){ 41 recentlyViewedDocs.remove(MAX_RECENT_HISTORY + 1); 42 } 43 for(int i =0; i < dependants.size(); i++){ 44 dependants.get(i).update(); 45 } 46 } 47 48 public static List<RecentDocInfo> getRecentlyViewed(){ 49 return recentlyViewedDocs; 50 } 51 52 public static void addDependant(HasRecentlyViewedData object){ 53 dependants.add(object); 54 } 55 56 public static void updateTitle(String oldTitle, String newTitle, String docId) { 57 for(int i=0; i < recentlyViewedDocs.size(); i++){ 58 if(oldTitle.equals(recentlyViewedDocs.get(i).getName()) 59 && recentlyViewedDocs.get(i).getLocation().contains(docId)){ 60 recentlyViewedDocs.get(i).setName(newTitle); 61 break; 62 } 63 } 64 for(int i =0; i < dependants.size(); i++){ 65 dependants.get(i).update(); 66 } 67 } 68 69 }