1 11 package org.eclipse.search.internal.ui; 12 13 import java.util.ArrayList ; 14 import java.util.Arrays ; 15 import java.util.Iterator ; 16 import java.util.List ; 17 18 import org.eclipse.swt.graphics.Image; 19 20 import org.eclipse.jface.action.Action; 21 import org.eclipse.jface.resource.ImageDescriptor; 22 import org.eclipse.jface.viewers.LabelProvider; 23 import org.eclipse.jface.window.Window; 24 25 import org.eclipse.search.internal.ui.util.ListDialog; 26 27 32 class ShowSearchesAction extends Action { 33 34 private static final class SearchesLabelProvider extends LabelProvider { 35 36 private ArrayList fImages= new ArrayList (); 37 38 public String getText(Object element) { 39 if (!(element instanceof ShowSearchAction)) 40 return ""; return ((ShowSearchAction)element).getText(); 42 } 43 public Image getImage(Object element) { 44 if (!(element instanceof ShowSearchAction)) 45 return null; 46 47 ImageDescriptor imageDescriptor= ((ShowSearchAction)element).getImageDescriptor(); 48 if (imageDescriptor == null) 49 return null; 50 51 Image image= imageDescriptor.createImage(); 52 fImages.add(image); 53 54 return image; 55 } 56 57 public void dispose() { 58 Iterator iter= fImages.iterator(); 59 while (iter.hasNext()) 60 ((Image)iter.next()).dispose(); 61 62 fImages= null; 63 } 64 } 65 66 69 public ShowSearchesAction() { 70 super(SearchMessages.ShowOtherSearchesAction_label); 71 setToolTipText(SearchMessages.ShowOtherSearchesAction_tooltip); 72 } 73 76 public void run() { 77 run(false); 78 } 79 80 public void run(boolean showAll) { 81 Iterator iter= SearchManager.getDefault().getPreviousSearches().iterator(); 82 int cutOffSize; 83 if (showAll) 84 cutOffSize= 0; 85 else 86 cutOffSize= SearchDropDownAction.RESULTS_IN_DROP_DOWN; 87 int size= SearchManager.getDefault().getPreviousSearches().size() - cutOffSize; 88 Search selectedSearch= SearchManager.getDefault().getCurrentSearch(); 89 Action selectedAction = null; 90 ArrayList input= new ArrayList (size); 91 int i= 0; 92 while (iter.hasNext()) { 93 Search search= (Search)iter.next(); 94 if (i++ < cutOffSize) 95 continue; 96 Action action= new ShowSearchAction(search); 97 input.add(action); 98 if (selectedSearch == search) 99 selectedAction= action; 100 } 101 102 String title; 104 String message; 105 if (showAll) { 106 title= SearchMessages.PreviousSearchesDialog_title; 107 message= SearchMessages.PreviousSearchesDialog_message; 108 } 109 else { 110 title= SearchMessages.OtherSearchesDialog_title; 111 message= SearchMessages.OtherSearchesDialog_message; 112 } 113 114 LabelProvider labelProvider=new SearchesLabelProvider(); 115 116 ListDialog dlg= new ListDialog(SearchPlugin.getActiveWorkbenchShell(),input, title, message, new SearchResultContentProvider(), labelProvider); 117 if (selectedAction != null) { 118 Object [] selected= new Object [1]; 119 selected[0]= selectedAction; 120 dlg.setInitialSelections(selected); 121 } 122 if (dlg.open() == Window.OK) { 123 List result= Arrays.asList(dlg.getResult()); 124 if (result != null && result.size() == 1) { 125 ((ShowSearchAction)result.get(0)).run(); 126 } 127 } 128 } 129 } 130 | Popular Tags |