1 20 21 package org.apache.directory.ldapstudio.browser.common.jobs; 22 23 24 import org.apache.directory.ldapstudio.browser.common.BrowserCommonActivator; 25 import org.apache.directory.ldapstudio.browser.core.jobs.AbstractEclipseJob; 26 import org.eclipse.core.runtime.IProgressMonitor; 27 import org.eclipse.core.runtime.IStatus; 28 import org.eclipse.core.runtime.Status; 29 import org.eclipse.jface.dialogs.ProgressMonitorDialog; 30 import org.eclipse.jface.operation.IRunnableContext; 31 import org.eclipse.jface.operation.IRunnableWithProgress; 32 import org.eclipse.swt.widgets.Display; 33 34 35 42 public class RunnableContextJobAdapter 43 { 44 45 50 public static void execute( final AbstractEclipseJob job ) 51 { 52 execute( job, null ); 53 } 54 55 56 62 public static void execute( final AbstractEclipseJob job, IRunnableContext runnableContext ) 63 { 64 execute( job, runnableContext, true ); 65 } 66 67 68 75 public static void execute( final AbstractEclipseJob job, IRunnableContext runnableContext, boolean handleError ) 76 { 77 78 if ( runnableContext == null ) 79 { 80 runnableContext = new ProgressMonitorDialog( Display.getDefault().getActiveShell() ); 81 } 82 83 IRunnableWithProgress runnable = new IRunnableWithProgress() 84 { 85 public void run( IProgressMonitor ipm ) throws InterruptedException 86 { 87 job.setExternalProgressMonitor( ipm ); 88 job.execute(); 89 job.join(); 90 } 91 }; 92 93 try 94 { 95 runnableContext.run( true, true, runnable ); 96 } 97 catch ( Exception ex ) 98 { 99 BrowserCommonActivator.getDefault().getExceptionHandler().handleException( 100 new Status( IStatus.ERROR, BrowserCommonActivator.PLUGIN_ID, IStatus.ERROR, ex.getMessage(), ex ) ); 101 } 102 103 if ( handleError && !job.getExternalResult().isOK() ) 104 { 105 IStatus status = job.getExternalResult(); 106 BrowserCommonActivator.getDefault().getExceptionHandler().handleException( status ); 107 } 108 109 } 110 111 } 112 | Popular Tags |