Skip to content

Commit

Permalink
Remove animations from the process widget in the status bar
Browse files Browse the repository at this point in the history
During startup StandardTrim creates an instance of
TaskBarProgressManager in line 52.

Before this change TaskBarProgressManager supports animation, which
seems useless / overkill
for progress reporting. This animation code also causes exception if you
execute unit tests, as I discovered during a test run of the resource
test suite.

This commit removes the animation logic but keeps the update logic of
updating the progress state of the item. I personal cannot note any
difference in the resulting runtime Eclipse.
  • Loading branch information
vogella committed Jun 17, 2022
1 parent 9e7ffac commit 60c3728
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public class ProgressMessages extends NLS {
public static String ProgressManager_rejectedRefreshException;
public static String ProgressMonitorJobsDialog_DetailsTitle;
public static String ProgressMonitorJobsDialog_HideTitle;
public static String ProgressToolItem_Update;
public static String AnimationManager_AnimationStart;
public static String ProgressFloatingWindow_EllipsisValue;
public static String BlockedJobsDialog_BlockedTitle;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
Expand All @@ -45,9 +44,7 @@ public class TaskBarProgressManager {

private IJobProgressManagerListener listener;

private WorkbenchJob animationUpdateJob;

private boolean isAnimated = false;
private WorkbenchJob updateJob;

private List<Job> jobs = Collections.synchronizedList(new ArrayList<Job>());

Expand All @@ -67,8 +64,8 @@ public class TaskBarProgressManager {
public TaskBarProgressManager(TaskItem taskItem) {
Assert.isNotNull(taskItem);
this.taskItem = taskItem;
animationUpdateJob = getAnimationUpdateJob();
animationUpdateJob.setSystem(true);
updateJob = getUpdateJob();
updateJob.setSystem(true);
listener = getProgressListener();

// Register the IJobProgressManagerListener so we can display progress
Expand All @@ -83,46 +80,17 @@ public TaskBarProgressManager(TaskItem taskItem) {
*/
public void dispose() {
ProgressManager.getInstance().removeListener(listener);
setAnimated(false);
disposeOverlay();
}

private WorkbenchJob getAnimationUpdateJob() {
return new WorkbenchJob(ProgressMessages.AnimationManager_AnimationStart) {
private WorkbenchJob getUpdateJob() {
return new WorkbenchJob(ProgressMessages.ProgressToolItem_Update) {

@Override
public IStatus runInUIThread(IProgressMonitor monitor) {
if (isAnimated) {
if (!taskItem.isDisposed() && !jobs.isEmpty()) {
Job job = jobs.get(0);
JobInfo jobInfo = jobInfoMap.get(job);
if (job != null && jobInfo != null) {
int percentDone = getPercentDone(jobInfo);
Optional<TaskInfo> optionalInfo = jobInfo.getTaskInfo();
if (percentDone == IProgressMonitor.UNKNOWN
|| (optionalInfo.isPresent() && optionalInfo.get().totalWork == IProgressMonitor.UNKNOWN)) {
setProgressState(SWT.INDETERMINATE);
} else {
setProgressState(SWT.NORMAL);
if (!taskItem.isDisposed()) {
taskItem.setProgress(percentDone);
}
}
} else {
setProgressState(SWT.DEFAULT);
}
updateImage(job);
} else {
updateImage(null);
}
} else {
setProgressState(SWT.DEFAULT);
updateImage(null);
}
setProgressState(SWT.DEFAULT);
updateImage(null);

if (isAnimated && taskItem != null && !taskItem.isDisposed()) {
schedule(400);
}
return Status.OK_STATUS;
}

Expand All @@ -132,24 +100,6 @@ private void setProgressState(int state) {
taskItem.setProgressState(state);
}
}

private int getPercentDone(JobTreeElement info) {
if (info.isJobInfo()) {
return ((JobInfo) info).getPercentDone();
}

if (info.hasChildren()) {
Object[] roots = ((GroupInfo) info).getChildren();
if (roots.length == 1 && roots[0] instanceof JobTreeElement) {
Optional<TaskInfo> optionalInfo = ((JobInfo) roots[0]).getTaskInfo();
if (optionalInfo.isPresent()) {
return optionalInfo.get().getPercentDone();
}
}
return ((GroupInfo) info).getPercentDone();
}
return 0;
}
};
}

Expand Down Expand Up @@ -207,9 +157,6 @@ public void addJob(JobInfo info) {
if (isNotTracked(info)) {
return;
}
if (jobs.isEmpty()) {
setAnimated(true);
}
if (!jobs.contains(info.getJob())) {
jobs.add(info.getJob());
}
Expand All @@ -231,7 +178,6 @@ public void refreshAll() {
ProgressManager manager = ProgressManager.getInstance();
jobs.clear();
jobInfoMap.clear();
setAnimated(false);
for (JobInfo currentInfo : manager.getJobInfos(showsDebug())) {
addJob(currentInfo);
}
Expand All @@ -241,9 +187,6 @@ public void refreshAll() {
public void removeJob(JobInfo info) {
jobs.remove(info.getJob());
jobInfoMap.remove(info.getJob());
if (jobs.isEmpty()) {
setAnimated(false);
}
}

@Override
Expand Down Expand Up @@ -289,8 +232,4 @@ public void refreshGroup(GroupInfo info) {
};
}

private synchronized void setAnimated(boolean animated) {
isAnimated = animated;
animationUpdateJob.schedule();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ ProgressManager_rejectedRefreshException=This exception is logged merely as a de

ProgressMonitorJobsDialog_DetailsTitle=&Details >>
ProgressMonitorJobsDialog_HideTitle=<< &Details
ProgressToolItem_Update=Updating progress tool item start
AnimationManager_AnimationStart=Animation start
ProgressFloatingWindow_EllipsisValue=...

Expand Down

0 comments on commit 60c3728

Please sign in to comment.