1 20 21 package org.apache.directory.ldapstudio.browser.core.jobs; 22 23 24 import java.util.ArrayList ; 25 import java.util.Arrays ; 26 import java.util.List ; 27 28 import org.apache.directory.ldapstudio.browser.core.BrowserCoreMessages; 29 import org.apache.directory.ldapstudio.browser.core.events.EventRegistry; 30 import org.apache.directory.ldapstudio.browser.core.events.SearchUpdateEvent; 31 import org.apache.directory.ldapstudio.browser.core.model.IConnection; 32 import org.apache.directory.ldapstudio.browser.core.model.ISearch; 33 34 35 public class SearchJob extends AbstractAsyncBulkJob 36 { 37 38 private ISearch[] searches; 39 40 41 public SearchJob( ISearch[] searches ) 42 { 43 this.searches = searches; 44 setName( BrowserCoreMessages.jobs__search_name ); 45 } 46 47 48 protected IConnection[] getConnections() 49 { 50 IConnection[] connections = new IConnection[searches.length]; 51 for ( int i = 0; i < connections.length; i++ ) 52 { 53 connections[i] = searches[i].getConnection(); 54 } 55 return connections; 56 } 57 58 59 protected Object [] getLockedObjects() 60 { 61 List l = new ArrayList (); 62 l.addAll( Arrays.asList( searches ) ); 63 return l.toArray(); 64 } 65 66 67 protected void executeBulkJob( ExtendedProgressMonitor monitor ) 68 { 69 70 monitor.beginTask( " ", searches.length + 1 ); monitor.reportProgress( " " ); 73 for ( int pi = 0; pi < searches.length; pi++ ) 74 { 75 ISearch search = searches[pi]; 76 77 monitor.setTaskName( BrowserCoreMessages.bind( BrowserCoreMessages.jobs__search_task, new String [] 78 { search.getName() } ) ); 79 monitor.worked( 1 ); 80 81 if ( search.getConnection() != null && search.getConnection().isOpened() ) 82 { 83 84 93 search.getConnection().search( search, monitor ); 94 } 95 } 96 } 97 98 99 protected void runNotification() 100 { 101 for ( int pi = 0; pi < searches.length; pi++ ) 102 { 103 EventRegistry.fireSearchUpdated( new SearchUpdateEvent( searches[pi], SearchUpdateEvent.EventDetail.SEARCH_PERFORMED ), 104 this ); 105 } 106 } 107 108 109 protected String getErrorMessage() 110 { 111 return searches.length == 1 ? BrowserCoreMessages.jobs__search_error_1 112 : BrowserCoreMessages.jobs__search_error_n; 113 } 114 115 } 116 | Popular Tags |