SWT ProgressMonitorDialog vs Job(SWT ProgressMonitorDialog 与 Job)
问题描述
我想使用一个非模态的进度监视器,可以缩小到状态栏的右下角.
I would like to use a progress monitor that is non-modal and can be shrunk to the bottom-right of the status bar.
据我测试,ProgressMonitorDialog 可以正确地向用户显示进度条,并且可以使用下面的代码将其设为模态.但是,没有钩子可以将其缩小到状态栏的右下角.代码如下所示:
As far as I can tell from testing, ProgressMonitorDialog correctly displays the progress bar to the user, and can be made modal using the following code below. However there are no hooks to shrink it to the bottom-right of the status bar. The code kind of looks like this:
try {
ProgressMonitorDialog pmd = new ProgressMonitorDialog(shell){
@Override
protected void setShellStyle(int newShellStyle) {
super.setShellStyle(SWT.CLOSE | SWT.MODELESS|
SWT.BORDER | SWT.TITLE);
setBlockOnOpen(false);
}
};
pmd.run(true, true, new MyOperation());
} catch (final InvocationTargetException e) {
MessageDialog.openError(shell, "Error", e.getMessage());
} catch (final InterruptedException e) {
MessageDialog.openInformation(shell, "Cancelled", e.getMessage());
}
class MyOperation implements IRunnableWithProgress {
@Override
public void run(final IProgressMonitor monitor) throws
InvocationTargetException, InterruptedException {
monitor.beginTask("start task", 10);
// time consuming work here
doExpensiveWork(monitor);
monitor.done();
}
当我使用 Job 进行测试时,作业按预期运行,但我没有得到视觉反馈.我的代码是这样的:
When I test with Job, the jobs run as expected but I get no visual feedback. My code is similar to this:
final ProgressBar progressBar = new ProgressBar(shell, SWT.SMOOTH);
progressBar.setBounds(100, 10, 200, 20);
// Setting the progress monitor
final IJobManager manager = Job.getJobManager();
final IProgressMonitor p = new IProgressMonitor() {
@Override
public void worked(final int work) {
sync.syncExec(new Runnable() {
@Override
public void run() {
progressBar.setSelection(progressBar.getSelection() + work);
}
});
//....
}
Job job = new Job("test") {
@Override
protected IStatus run(IProgressMonitor monitor) {
monitor.beginTask("start task", 10);
// time consuming work here
doExpensiveWork(monitor);
// sync with UI
syncWithUI();
return Status.OK_STATUS;
}
};
job.setUser(true);
job.schedule();
当用户最小化选项卡时,我缺少什么能够获得可以缩小到状态栏右下角的 ProgressMonitorDialog 版本?
What am I missing to be able to get a version of the ProgressMonitorDialog that can shrink to the bottom-right of the status bar when the user minimizes the tab?
推荐答案
不知道ProgressDialog怎么样,但是在使用jobs时显示进度,你必须设置
No idea how about ProgressDialog, but show progress while using jobs, you have to set
IWorkbenchWindowConfigurer configurer = getWindowConfigurer();
setShowProgressIndicator(true);
在org.eclipse.ui.application.WorkbenchWindowAdvisor.preWindowOpen()
这篇关于SWT ProgressMonitorDialog 与 Job的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:SWT ProgressMonitorDialog 与 Job


基础教程推荐
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- 降序排序:Java Map 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01