我正在尝试开发一个插件,该插件在安排任何形式的日食工作时都会做一些工作。
基本上,我希望能够知道进度对话框中何时有作业并对其进行监视。
是否可以设置一个侦听器来捕获此类工作的乞讨和结束?
最佳答案
当您考虑时,ProgressView
会这样做:每当作业启动时,它都会在其视图中显示它。
请注意,如该线程中所述,ProgressView
is tightly coupled with the eclipse Jobs API(即,它可能不监视任何普通的香草线程)
(摘自文章On the Job: The Eclipse Jobs API)
因此,可能您可以从org.eclipse.ui.internal.progress.ProgressView
中的代码开始,该代码需要基于ProgressViewerContentProvider
的ProgressContentProvider
(实现IProgressUpdateCollector
)
一切似乎都基于ProgressViewUpdater
单例,它创建了一个UI线程来监视那些Jobs:
/**
* Create the update job that handles the updatesInfo.
*/
private void createUpdateJob() {
updateJob = new WorkbenchJob(ProgressMessages.ProgressContentProvider_UpdateProgressJob) {
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.progress.UIJob#runInUIThread(org.eclipse.core.runtime.IProgressMonitor)
*/
public IStatus runInUIThread(IProgressMonitor monitor) {
//Abort the job if there isn't anything
if (collectors.length == 0) {
return Status.CANCEL_STATUS;
}
if (currentInfo.updateAll) {
synchronized (updateLock) {
currentInfo.reset();
}
for (int i = 0; i < collectors.length; i++) {
collectors[i].refresh();
}
} else {
//Lock while getting local copies of the caches.
Object[] updateItems;
Object[] additionItems;
Object[] deletionItems;
synchronized (updateLock) {
currentInfo.processForUpdate();
updateItems = currentInfo.refreshes.toArray();
additionItems = currentInfo.additions.toArray();
deletionItems = currentInfo.deletions.toArray();
currentInfo.reset();
}
for (int v = 0; v < collectors.length; v++) {
IProgressUpdateCollector collector = collectors[v];
if (updateItems.length > 0) {
collector.refresh(updateItems);
}
if (additionItems.length > 0) {
collector.add(additionItems);
}
if (deletionItems.length > 0) {
collector.remove(deletionItems);
}
}
}
return Status.OK_STATUS;
}
};
updateJob.setSystem(true);
updateJob.setPriority(Job.DECORATE);
updateJob.setProperty(ProgressManagerUtil.INFRASTRUCTURE_PROPERTY, new Object());
}