1 11 package org.eclipse.ui.internal.progress; 12 13 import org.eclipse.core.runtime.IProgressMonitor; 14 import org.eclipse.osgi.util.NLS; 15 16 21 public class TaskInfo extends SubTaskInfo { 22 double preWork = 0; 23 24 int totalWork = 0; 25 26 34 TaskInfo(JobInfo parentJobInfo, String infoName, int total) { 35 super(parentJobInfo, infoName); 36 totalWork = total; 37 } 38 39 44 void addWork(double workIncrement) { 45 46 if (totalWork == IProgressMonitor.UNKNOWN) { 48 return; 49 } 50 preWork += workIncrement; 51 52 } 53 54 65 void addWork(double workIncrement, IProgressMonitor parentMonitor, 66 int parentTicks) { 67 if (totalWork == IProgressMonitor.UNKNOWN) { 69 return; 70 } 71 72 addWork(workIncrement); 73 parentMonitor.internalWorked(workIncrement * parentTicks / totalWork); 74 } 75 76 81 String getDisplayString(boolean showProgress) { 82 83 if (totalWork == IProgressMonitor.UNKNOWN) { 84 return unknownProgress(); 85 } 86 87 if (taskName == null) { 88 return getDisplayStringWithoutTask(showProgress); 89 } 90 91 if (showProgress) { 92 String [] messageValues = new String [3]; 93 messageValues[0] = String.valueOf(getPercentDone()); 94 messageValues[1] = jobInfo.getJob().getName(); 95 messageValues[2] = taskName; 96 97 return NLS 98 .bind(ProgressMessages.JobInfo_DoneMessage, messageValues); 99 } 100 String [] messageValues = new String [2]; 101 messageValues[0] = jobInfo.getJob().getName(); 102 messageValues[1] = taskName; 103 104 return NLS.bind(ProgressMessages.JobInfo_DoneNoProgressMessage, 105 messageValues); 106 107 } 108 109 117 String getDisplayStringWithoutTask(boolean showProgress) { 118 119 if (!showProgress || totalWork == IProgressMonitor.UNKNOWN) { 120 return jobInfo.getJob().getName(); 121 } 122 123 return NLS.bind(ProgressMessages.JobInfo_NoTaskNameDoneMessage, jobInfo 124 .getJob().getName(), String.valueOf(getPercentDone())); 125 } 126 127 133 int getPercentDone() { 134 if (totalWork == IProgressMonitor.UNKNOWN) { 135 return IProgressMonitor.UNKNOWN; 136 } 137 138 return Math.min((int) (preWork * 100 / totalWork), 100); 139 } 140 141 147 private String unknownProgress() { 148 if (taskName == null) { 149 return jobInfo.getJob().getName(); 150 } 151 String [] messageValues = new String [2]; 152 messageValues[0] = jobInfo.getJob().getName(); 153 messageValues[1] = taskName; 154 return NLS 155 .bind(ProgressMessages.JobInfo_UnknownProgress, messageValues); 156 157 } 158 } 159 | Popular Tags |