我正在尝试使用ProgressMonitorDialog执行(长)任务,但是我希望用户能够“在后台运行”。
不幸的是,此按钮没有出现,我无法找到此问题的原因。
这是我的代码:
ProgressMonitorDialog pmd = new ProgressMonitorDialog(shell);
try {
pmd.run(true, true, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException,
InterruptedException {
monitor.beginTask("Refactoring in progress", IProgressMonitor.UNKNOWN);
File root = new File(file.getProject().getLocation().toOSString()); //The root is here
browseAndProcess(root, file.getName(), newFileName, monitor);
monitor.done();
}
});
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
这是我当前结果的示例:http://imgur.com/ChHGzz3
有什么想法我做错了吗?
谢谢阅读。
最佳答案
标准ProgressMonitorDialog
不支持在后台运行选项。
具有此选项的对话框是ProgressMonitorFocusJobDialog
,它不是公共的。只能使用Job
进行访问。
在安排作业之前使用setUser(true)
的Job
方法将告诉作业管理器在短暂的延迟后显示此进度对话框。
您还可以使用以下命令立即显示对话框:
PlatformUI.getWorkbench().getProgressService().showInDialog(shell, job);