1 12 package org.eclipse.jdt.internal.ui.callhierarchy; 13 14 import java.util.Arrays ; 15 import java.util.HashSet ; 16 import java.util.Iterator ; 17 import java.util.Set ; 18 19 import org.eclipse.jface.dialogs.IDialogSettings; 20 21 import org.eclipse.ui.IWorkingSet; 22 import org.eclipse.ui.PlatformUI; 23 24 import org.eclipse.jdt.internal.corext.util.Messages; 25 26 import org.eclipse.jdt.internal.ui.JavaPlugin; 27 import org.eclipse.jdt.internal.ui.search.LRUWorkingSetsList; 28 import org.eclipse.jdt.internal.ui.search.WorkingSetComparator; 29 30 public class SearchUtil { 31 32 public static int LRU_WORKINGSET_LIST_SIZE= 3; 34 private static LRUWorkingSetsList fgLRUWorkingSets; 35 private static final String DIALOG_SETTINGS_KEY= "CallHierarchySearchScope"; private static final String STORE_LRU_WORKING_SET_NAMES= "lastUsedWorkingSetNames"; private static IDialogSettings fgSettingsStore; 39 40 45 public static void updateLRUWorkingSets(IWorkingSet[] workingSets) { 46 if (workingSets == null || workingSets.length < 1) 47 return; 48 49 SearchUtil.getLRUWorkingSets().add(workingSets); 50 SearchUtil.saveState(); 51 } 52 53 private static void saveState() { 54 IWorkingSet[] workingSets; 55 Iterator iter= SearchUtil.fgLRUWorkingSets.iterator(); 56 int i= 0; 57 while (iter.hasNext()) { 58 workingSets= (IWorkingSet[])iter.next(); 59 String [] names= new String [workingSets.length]; 60 for (int j= 0; j < workingSets.length; j++) 61 names[j]= workingSets[j].getName(); 62 SearchUtil.fgSettingsStore.put(SearchUtil.STORE_LRU_WORKING_SET_NAMES + i, names); 63 i++; 64 } 65 } 66 67 public static LRUWorkingSetsList getLRUWorkingSets() { 68 if (SearchUtil.fgLRUWorkingSets == null) { 69 restoreState(); 70 } 71 return SearchUtil.fgLRUWorkingSets; 72 } 73 74 static void restoreState() { 75 SearchUtil.fgLRUWorkingSets= new LRUWorkingSetsList(SearchUtil.LRU_WORKINGSET_LIST_SIZE); 76 SearchUtil.fgSettingsStore= JavaPlugin.getDefault().getDialogSettings().getSection(SearchUtil.DIALOG_SETTINGS_KEY); 77 if (SearchUtil.fgSettingsStore == null) 78 SearchUtil.fgSettingsStore= JavaPlugin.getDefault().getDialogSettings().addNewSection(SearchUtil.DIALOG_SETTINGS_KEY); 79 80 boolean foundLRU= false; 81 for (int i= SearchUtil.LRU_WORKINGSET_LIST_SIZE - 1; i >= 0; i--) { 82 String [] lruWorkingSetNames= SearchUtil.fgSettingsStore.getArray(SearchUtil.STORE_LRU_WORKING_SET_NAMES + i); 83 if (lruWorkingSetNames != null) { 84 Set workingSets= new HashSet (2); 85 for (int j= 0; j < lruWorkingSetNames.length; j++) { 86 IWorkingSet workingSet= PlatformUI.getWorkbench().getWorkingSetManager().getWorkingSet(lruWorkingSetNames[j]); 87 if (workingSet != null) { 88 workingSets.add(workingSet); 89 } 90 } 91 foundLRU= true; 92 if (!workingSets.isEmpty()) 93 SearchUtil.fgLRUWorkingSets.add((IWorkingSet[])workingSets.toArray(new IWorkingSet[workingSets.size()])); 94 } 95 } 96 if (!foundLRU) 97 restoreFromOldFormat(); 99 } 100 101 private static void restoreFromOldFormat() { 102 SearchUtil.fgLRUWorkingSets= new LRUWorkingSetsList(SearchUtil.LRU_WORKINGSET_LIST_SIZE); 103 SearchUtil.fgSettingsStore= JavaPlugin.getDefault().getDialogSettings().getSection(SearchUtil.DIALOG_SETTINGS_KEY); 104 if (SearchUtil.fgSettingsStore == null) 105 SearchUtil.fgSettingsStore= JavaPlugin.getDefault().getDialogSettings().addNewSection(SearchUtil.DIALOG_SETTINGS_KEY); 106 107 boolean foundLRU= false; 108 String [] lruWorkingSetNames= SearchUtil.fgSettingsStore.getArray(SearchUtil.STORE_LRU_WORKING_SET_NAMES); 109 if (lruWorkingSetNames != null) { 110 for (int i= lruWorkingSetNames.length - 1; i >= 0; i--) { 111 IWorkingSet workingSet= PlatformUI.getWorkbench().getWorkingSetManager().getWorkingSet(lruWorkingSetNames[i]); 112 if (workingSet != null) { 113 foundLRU= true; 114 SearchUtil.fgLRUWorkingSets.add(new IWorkingSet[]{workingSet}); 115 } 116 } 117 } 118 if (foundLRU) 119 saveState(); 121 } 122 123 public static String toString(IWorkingSet[] workingSets) { 124 Arrays.sort(workingSets, new WorkingSetComparator()); 125 String result= ""; if (workingSets != null && workingSets.length > 0) { 127 boolean firstFound= false; 128 for (int i= 0; i < workingSets.length; i++) { 129 String workingSetName= workingSets[i].getLabel(); 130 if (firstFound) 131 result= Messages.format(CallHierarchyMessages.SearchUtil_workingSetConcatenation, new String [] {result, workingSetName}); 132 else { 133 result= workingSetName; 134 firstFound= true; 135 } 136 } 137 } 138 return result; 139 } 140 } 141
| Popular Tags
|