1 11 package org.eclipse.update.internal.ui.wizards; 12 13 import java.lang.reflect.*; 14 15 import org.eclipse.core.runtime.*; 16 import org.eclipse.jface.dialogs.*; 17 import org.eclipse.jface.operation.*; 18 import org.eclipse.swt.widgets.*; 19 import org.eclipse.update.core.*; 20 import org.eclipse.update.internal.ui.*; 21 import org.eclipse.update.search.*; 22 23 26 public class SearchRunner { 27 private Shell shell; 28 private IRunnableContext context; 29 private ISearchProvider searchProvider; 30 private IUpdateSearchResultCollector collector; 31 private boolean newSearchNeeded; 32 33 public SearchRunner(Shell shell, IRunnableContext context) { 34 this.shell = shell; 35 this.context = context; 36 } 37 38 public void setResultCollector(IUpdateSearchResultCollector collector) { 39 this.collector = collector; 40 } 41 42 public ISearchProvider getSearchProvider() { 43 return searchProvider; 44 } 45 46 public void setSearchProvider(ISearchProvider searchProvider) { 47 if (this.searchProvider!=searchProvider) 48 newSearchNeeded = true; 49 this.searchProvider = searchProvider; 50 } 51 52 public void setNewSearchNeeded(boolean value) { 53 newSearchNeeded = value; 54 } 55 56 public boolean isNewSearchNeeded() { 57 return newSearchNeeded; 58 } 59 60 public void runSearch() { 61 if (searchProvider==null) return; 62 try { 63 context.run(true, true, getSearchOperation(collector)); 64 newSearchNeeded=false; 65 } catch (InterruptedException e) { 66 if (!"cancel".equals(e.getMessage())) 67 UpdateUI.logException(e); 68 newSearchNeeded=true; 69 return; 70 } catch (InvocationTargetException e) { 71 Throwable t = e.getTargetException(); 72 if (t instanceof CoreException) { 73 CoreException ce = (CoreException)t; 74 IStatus status = ce.getStatus(); 75 if (status!=null && 76 status.getCode()==ISite.SITE_ACCESS_EXCEPTION) { 77 ErrorDialog.openError(shell,UpdateUI.getString("SearchRunner.connectionError"), null, 81 status); 82 return; 83 } 84 } 85 UpdateUI.logException(e); 86 return; 87 } 88 } 89 90 private IRunnableWithProgress getSearchOperation(final IUpdateSearchResultCollector collector) { 91 final UpdateSearchRequest request = searchProvider.getSearchRequest(); 92 93 IRunnableWithProgress op = new IRunnableWithProgress () { 94 public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { 95 try { 96 request.performSearch(collector, monitor); 97 } catch (CoreException e) { 98 throw new InvocationTargetException(e); 99 } finally { 100 monitor.done(); 101 if (monitor.isCanceled()) { 102 newSearchNeeded = true; 103 throw new InterruptedException ("cancel"); 104 } 105 } 106 } 107 }; 108 return op; 109 } 110 } 111 | Popular Tags |