1 11 package org.eclipse.help.internal.search; 12 13 import java.util.ArrayList ; 14 import java.util.Collection ; 15 import java.util.Iterator ; 16 17 import org.eclipse.core.runtime.*; 18 19 22 public class ProgressDistributor implements IProgressMonitor { 23 private int totalWork = -1; 24 private double worked = 0; 25 private boolean done = false; 26 String taskName; 27 String subTaskName; 28 31 private Collection monitors = new ArrayList (); 32 33 36 public synchronized void beginTask(String name, int totalWork) { 37 this.totalWork = totalWork; 38 this.worked = 0; 39 this.done = false; 40 for (Iterator it = monitors.iterator(); it.hasNext();) { 41 IProgressMonitor m = (IProgressMonitor) it.next(); 42 m.beginTask(name, totalWork); 43 } 44 } 45 46 49 public synchronized void done() { 50 done = true; 51 for (Iterator it = monitors.iterator(); it.hasNext();) { 52 IProgressMonitor m = (IProgressMonitor) it.next(); 53 m.done(); 54 } 55 } 56 57 60 public void internalWorked(double work) { 61 worked += work; 62 for (Iterator it = monitors.iterator(); it.hasNext();) { 63 IProgressMonitor m = (IProgressMonitor) it.next(); 64 m.internalWorked(work); 65 } 66 } 67 68 71 public synchronized boolean isCanceled() { 72 for (Iterator it = monitors.iterator(); it.hasNext();) { 73 IProgressMonitor m = (IProgressMonitor) it.next(); 74 if (m.isCanceled()) { 75 return true; 76 } 77 } 78 return false; 79 } 80 81 84 public void setCanceled(boolean value) { 85 } 86 87 90 public synchronized void setTaskName(String name) { 91 taskName = name; 92 for (Iterator it = monitors.iterator(); it.hasNext();) { 93 IProgressMonitor m = (IProgressMonitor) it.next(); 94 m.setTaskName(name); 95 } 96 } 97 98 101 public synchronized void subTask(String name) { 102 subTaskName = name; 103 for (Iterator it = monitors.iterator(); it.hasNext();) { 104 IProgressMonitor m = (IProgressMonitor) it.next(); 105 m.subTask(name); 106 } 107 } 108 109 112 public synchronized void worked(int work) { 113 internalWorked(work); 114 } 115 116 public synchronized void addMonitor(IProgressMonitor m) { 117 if (totalWork > -1) 118 m.beginTask(taskName, totalWork); 119 if (subTaskName != null) 120 m.subTask(subTaskName); 121 if (worked > 0) 122 m.internalWorked(worked); 123 if (done) 124 m.done(); 125 monitors.add(m); 126 } 127 public synchronized void removeMonitor(IProgressMonitor m) { 128 monitors.remove(m); 129 } 130 public synchronized void operationCanceled() { 131 totalWork = -1; 132 worked = 0; 133 done = false; 134 } 135 } 136 | Popular Tags |