1 11 package org.eclipse.search.internal.ui; 12 13 import java.lang.reflect.InvocationTargetException ; 14 import java.util.ArrayList ; 15 import java.util.Iterator ; 16 import java.util.List ; 17 18 import org.eclipse.core.runtime.Assert; 19 20 import org.eclipse.swt.widgets.Shell; 21 22 import org.eclipse.jface.action.IAction; 23 import org.eclipse.jface.dialogs.ProgressMonitorDialog; 24 import org.eclipse.jface.operation.IRunnableWithProgress; 25 import org.eclipse.jface.resource.ImageDescriptor; 26 import org.eclipse.jface.viewers.ILabelProvider; 27 import org.eclipse.jface.viewers.ISelection; 28 29 import org.eclipse.search.ui.IActionGroupFactory; 30 import org.eclipse.search.ui.IContextMenuContributor; 31 import org.eclipse.search.ui.IGroupByKeyComputer; 32 import org.eclipse.search.ui.ISearchResultViewEntry; 33 34 import org.eclipse.search.internal.ui.util.ExceptionHandler; 35 38 public class Search extends Object { 39 private String fPageId; 40 private String fSingularLabel; 41 private String fPluralLabelPattern; 42 private ImageDescriptor fImageDescriptor; 43 private ILabelProvider fLabelProvider; 44 private ISelection fSelection; 45 private ArrayList fResults; 46 private IAction fGotoMarkerAction; 47 private IContextMenuContributor fContextMenuContributor; 48 private IActionGroupFactory fActionGroupFactory; 49 private IGroupByKeyComputer fGroupByKeyComputer; 50 private IRunnableWithProgress fOperation; 51 52 53 public Search(String pageId, String singularLabel, String pluralLabelPattern, ILabelProvider labelProvider, ImageDescriptor imageDescriptor, IAction gotoMarkerAction, IActionGroupFactory groupFactory, IGroupByKeyComputer groupByKeyComputer, IRunnableWithProgress operation) { 54 fPageId= pageId; 55 fSingularLabel= singularLabel; 56 fPluralLabelPattern= pluralLabelPattern; 57 fImageDescriptor= imageDescriptor; 58 fLabelProvider= labelProvider; 59 fGotoMarkerAction= gotoMarkerAction; 60 fActionGroupFactory= groupFactory; 61 fGroupByKeyComputer= groupByKeyComputer; 62 fOperation= operation; 63 64 if (fPluralLabelPattern == null) 65 fPluralLabelPattern= ""; } 67 68 public Search(String pageId, String singularLabel, String pluralLabelPattern, ILabelProvider labelProvider, ImageDescriptor imageDescriptor, IAction gotoMarkerAction, IContextMenuContributor contextMenuContributor, IGroupByKeyComputer groupByKeyComputer, IRunnableWithProgress operation) { 69 fPageId= pageId; 70 fSingularLabel= singularLabel; 71 fPluralLabelPattern= pluralLabelPattern; 72 fImageDescriptor= imageDescriptor; 73 fLabelProvider= labelProvider; 74 fGotoMarkerAction= gotoMarkerAction; 75 fContextMenuContributor= contextMenuContributor; 76 fGroupByKeyComputer= groupByKeyComputer; 77 fOperation= operation; 78 79 if (fPluralLabelPattern == null) 80 fPluralLabelPattern= ""; } 82 83 88 String getFullDescription() { 89 if (fSingularLabel != null && getItemCount() == 1) 90 return fSingularLabel; 91 92 int i= fPluralLabelPattern.lastIndexOf("{0}"); if (i < 0) 95 return fPluralLabelPattern; 96 return fPluralLabelPattern.substring(0, i) + getItemCount()+ fPluralLabelPattern.substring(Math.min(i + 3, fPluralLabelPattern.length())); 97 } 98 99 105 String getShortDescription() { 106 String text= getFullDescription(); 107 int separatorPos= text.indexOf(" - "); if (separatorPos < 1) 109 return text.substring(0, Math.min(50, text.length())) + "..."; if (separatorPos < 30) 111 return text; if (text.charAt(0) == '"') 113 return text.substring(0, Math.min(30, text.length())) + "...\" - " + text.substring(Math.min(separatorPos + 3, text.length())); return text.substring(0, Math.min(30, text.length())) + "... - " + text.substring(Math.min(separatorPos + 3, text.length())); } 116 117 ImageDescriptor getImageDescriptor() { 118 return fImageDescriptor; 119 } 120 121 int getItemCount() { 122 int count= 0; 123 Iterator iter= getResults().iterator(); 124 while (iter.hasNext()) 125 count += ((ISearchResultViewEntry)iter.next()).getMatchCount(); 126 return count; 127 } 128 129 List getResults() { 130 if (fResults == null) 131 return new ArrayList (); 132 return fResults; 133 } 134 135 ILabelProvider getLabelProvider() { 136 return fLabelProvider; 137 } 138 139 void searchAgain() { 140 if (fOperation == null) 141 return; 142 Shell shell= SearchPlugin.getActiveWorkbenchShell(); 143 boolean isAutoBuilding= SearchPlugin.setAutoBuilding(false); 144 try { 145 new ProgressMonitorDialog(shell).run(true, true, fOperation); 146 } catch (InvocationTargetException ex) { 147 ExceptionHandler.handle(ex, shell, SearchMessages.Search_Error_search_title, SearchMessages.Search_Error_search_message); 148 } catch(InterruptedException e) { 149 } finally { 150 SearchPlugin.setAutoBuilding(isAutoBuilding); 151 } 152 } 153 154 boolean isSameSearch(Search search) { 155 return search != null && search.getOperation() == fOperation && fOperation != null; 156 } 157 158 void backupMarkers() { 159 Iterator iter= getResults().iterator(); 160 while (iter.hasNext()) { 161 ((SearchResultViewEntry)iter.next()).backupMarkers(); 162 } 163 } 164 165 String getPageId() { 166 return fPageId; 167 } 168 169 IGroupByKeyComputer getGroupByKeyComputer() { 170 return fGroupByKeyComputer; 171 } 172 173 public IRunnableWithProgress getOperation() { 174 return fOperation; 175 } 176 177 IAction getGotoMarkerAction() { 178 return fGotoMarkerAction; 179 } 180 181 IContextMenuContributor getContextMenuContributor() { 182 return fContextMenuContributor; 183 } 184 185 IActionGroupFactory getActionGroupFactory() { 186 return fActionGroupFactory; 187 } 188 189 public void removeResults() { 190 fResults= null; 191 } 192 193 void setResults(ArrayList results) { 194 Assert.isNotNull(results); 195 fResults= results; 196 } 197 198 ISelection getSelection() { 199 return fSelection; 200 } 201 202 void setSelection(ISelection selection) { 203 fSelection= selection; 204 } 205 } 206 207 | Popular Tags |