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.ConnectionUpdateEvent; 30 import org.apache.directory.ldapstudio.browser.core.events.EventRegistry; 31 import org.apache.directory.ldapstudio.browser.core.model.IConnection; 32 33 34 public class OpenConnectionsJob extends AbstractAsyncBulkJob 35 { 36 37 private IConnection[] connections; 38 39 40 public OpenConnectionsJob( IConnection connection ) 41 { 42 this( new IConnection[] 43 { connection } ); 44 } 45 46 47 public OpenConnectionsJob( IConnection[] connections ) 48 { 49 this.connections = connections; 50 setName( connections.length == 1 ? BrowserCoreMessages.jobs__open_connections_name_1 51 : BrowserCoreMessages.jobs__open_connections_name_n ); 52 } 53 54 55 protected IConnection[] getConnections() 56 { 57 return new IConnection[0]; 58 } 59 60 61 protected Object [] getLockedObjects() 62 { 63 List l = new ArrayList (); 64 l.addAll( Arrays.asList( connections ) ); 65 return l.toArray(); 66 } 67 68 69 protected String getErrorMessage() 70 { 71 return connections.length == 1 ? BrowserCoreMessages.jobs__open_connections_error_1 72 : BrowserCoreMessages.jobs__open_connections_error_n; 73 } 74 75 76 protected void executeBulkJob( ExtendedProgressMonitor monitor ) 77 { 78 79 monitor.beginTask( " ", connections.length * 6 + 1 ); monitor.reportProgress( " " ); 82 for ( int i = 0; i < connections.length; i++ ) 83 { 84 if ( connections[i].canOpen() ) 85 { 86 87 monitor.setTaskName( BrowserCoreMessages.bind( BrowserCoreMessages.jobs__open_connections_task, 88 new String [] 89 { this.connections[i].getName() } ) ); 90 monitor.worked( 1 ); 91 92 connections[i].open( monitor ); 93 } 94 } 95 } 96 97 98 protected void runNotification() 99 { 100 for ( int i = 0; i < connections.length; i++ ) 101 { 102 if ( connections[i].isOpened() ) 103 { 104 EventRegistry.fireConnectionUpdated( new ConnectionUpdateEvent( connections[i], 105 ConnectionUpdateEvent.EventDetail.CONNECTION_OPENED ), this ); 106 } 107 else 108 { 109 EventRegistry.fireConnectionUpdated( new ConnectionUpdateEvent( connections[i], 110 ConnectionUpdateEvent.EventDetail.CONNECTION_CLOSED ), this ); 111 } 112 } 113 } 114 115 } 116 | Popular Tags |