1 13 package org.eclipse.ui.internal.progress; 14 15 import java.util.ArrayList ; 16 import java.util.List ; 17 18 import org.eclipse.core.runtime.IProgressMonitor; 19 import org.eclipse.osgi.util.NLS; 20 21 24 25 class GroupInfo extends JobTreeElement implements IProgressMonitor { 26 27 private List infos = new ArrayList (); 28 29 private Object lock = new Object (); 30 31 private String taskName; 32 33 boolean isActive = false; 34 35 double total = -1; 36 37 double currentWork; 38 39 44 Object getParent() { 45 return null; 46 } 47 48 53 boolean hasChildren() { 54 synchronized (lock) { 55 return !infos.isEmpty(); 56 } 57 58 } 59 60 65 Object [] getChildren() { 66 synchronized (lock) { 67 return infos.toArray(); 68 } 69 } 70 71 76 String getDisplayString() { 77 if (total < 0) { 78 return taskName; 79 } 80 String [] messageValues = new String [2]; 81 messageValues[0] = taskName; 82 messageValues[1] = String.valueOf(getPercentDone()); 83 return NLS.bind(ProgressMessages.JobInfo_NoTaskNameDoneMessage, messageValues); 84 85 } 86 87 92 int getPercentDone() { 93 return (int) (currentWork * 100 / total); 94 } 95 96 101 boolean isJobInfo() { 102 return false; 103 } 104 105 110 public int compareTo(Object arg0) { 111 return getDisplayString().compareTo( 112 ((JobTreeElement) arg0).getDisplayString()); 113 } 114 115 121 public void beginTask(String name, int totalWork) { 122 taskName = name; 123 total = totalWork; 124 synchronized (lock) { 125 isActive = true; 126 } 127 ProgressManager.getInstance().refreshGroup(this); 128 129 } 130 131 136 public void done() { 137 synchronized (lock) { 138 isActive = false; 139 } 140 ProgressManager.getInstance().removeGroup(this); 141 142 } 143 144 149 public void internalWorked(double work) { 150 synchronized (lock) { 151 currentWork += work; 152 } 153 154 } 155 156 161 public boolean isCanceled() { 162 return false; 164 } 165 166 171 public void setCanceled(boolean value) { 172 cancel(); 173 } 174 175 180 public void setTaskName(String name) { 181 synchronized (this) { 182 isActive = true; 183 } 184 taskName = name; 185 186 } 187 188 193 public void subTask(String name) { 194 } 196 197 202 public void worked(int work) { 203 internalWorked(work); 204 } 205 206 211 void removeJobInfo(final JobInfo job) { 212 synchronized (lock) { 213 infos.remove(job); 214 if (infos.isEmpty()) { 215 done(); 216 } 217 } 218 } 219 220 225 void addJobInfo(final JobInfo job) { 226 synchronized (lock) { 227 infos.add(job); 228 } 229 } 230 231 236 boolean isActive() { 237 return isActive; 238 } 239 240 245 public void cancel() { 246 Object [] jobInfos = getChildren(); 247 for (int i = 0; i < jobInfos.length; i++) { 248 ((JobInfo) jobInfos[i]).cancel(); 249 } 250 } 251 252 257 public boolean isCancellable() { 258 return true; 259 } 260 261 265 String getTaskName() { 266 return taskName; 267 } 268 269 } 270 | Popular Tags |