1 11 package org.eclipse.compare.internal; 12 13 import java.util.ArrayList ; 14 import java.util.List ; 15 16 import org.eclipse.core.runtime.*; 17 import org.eclipse.core.runtime.jobs.Job; 18 import org.eclipse.jface.operation.IRunnableWithProgress; 19 20 public class WorkerJob extends Job { 21 22 private final Worker worker; 23 24 public WorkerJob(String name) { 25 super(name); 26 worker = new Worker(name); 27 } 28 29 protected IStatus run(IProgressMonitor monitor) { 30 worker.run(monitor); 31 IStatus result = getResult(worker); 33 schedule(); 34 return result; 35 } 36 37 private IStatus getResult(Worker w) { 38 Throwable [] errors = w.getErrors(); 39 if (errors.length == 0) 40 return Status.OK_STATUS; 41 if (errors.length == 1) 42 return new Status(IStatus.ERROR, CompareUIPlugin.PLUGIN_ID, 0, errors[0].getMessage(), errors[0]); 43 List statii = new ArrayList (); 44 for (int i = 0; i < errors.length; i++) { 45 Throwable throwable = errors[i]; 46 statii.add(new Status(IStatus.ERROR, CompareUIPlugin.PLUGIN_ID, 0, errors[0].getMessage(), throwable)); 47 } 48 return new MultiStatus(CompareUIPlugin.PLUGIN_ID, 0, (IStatus[]) statii.toArray(new IStatus[statii.size()]), CompareMessages.WorkerJob_0, null); 49 } 50 51 public boolean shouldRun() { 52 return worker.hasWork(); 53 } 54 55 public void add(IRunnableWithProgress runnable) { 56 worker.add(runnable); 57 schedule(); 58 } 59 60 } 61 | Popular Tags |