eclipse rcp:如何在后台运行作业时阻止ui [英] eclipse rcp : how to block ui while running a job in background

查看:109
本文介绍了eclipse rcp:如何在后台运行作业时阻止ui的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在对话框中有一个测试按钮,当用户单击该按钮时,我的应用程序将尝试通过JDBC连接到数据库。

I have a test button in a Dialog, when user click that button, my application will try to connect to a database via JDBC.

在某些测试情况下,此工作将花费很长时间而为了响应用户,例如网络连接超时。我通过将侦听器附加到该按钮并在该侦听器中连接到数据库来实现此目的。连接时,直到完成连接作业,用户界面才会响应。连接时发生的任何用户操作都将在完成连接作业后生效。

For some testing cases this job will take a long while to give response to user, network connection timeout for instance. I do this by attaching a listener to that button and connect to database in that listener. when connecting, the user interface will not response until the connecting job is finished. Any user action ocurrs while connecting will take effect after connecting job done.

例如:该对话框中还有另一个取消按钮,单击此按钮将关闭对话框。如果在运行连接作业时单击取消按钮,则在完成连接作业之前将不会关闭对话框!

For example: there is another "cancel" button in that dialog, click this button will close the dialog. if you click "cancel" button while a connecting job is running, the dialog will not be closed until connecting job is done!

我希望发生用户操作当我的连接作业正在运行时,将删除,而不保存并稍后生效。

I hope user actions happened while my connecting job is running will be droped, not stored and take effect later.

我正在Windows 7上使用eclipse indigo

I am using eclipse indigo on windows 7

我的问题应该是:
如何忽略在后台运行作业时发生的任何用户操作。

My question should be this :
How to ignore any user's action happened while running a job in background.

推荐答案

到目前为止,我发现有两种方法可以忽略作业在后台运行时的任何用户操作:

The two ways I found to ignore any user actions while a job runs in the background so far:

第一个是在操作开始之前调用 shell.setEnabled(false) shell.setEnabled(true)操作完成后。
(可选)与 BusyIndi​​cator 结合使用,为用户提供一些反馈。

The first one is to call shell.setEnabled(false) before the operation starts and shell.setEnabled(true) after the operation is done. (optional) combined with the BusyIndicator to give the user some feedback.

第二个是使用没有按钮的模式对话框,因此用户无法关闭它(样式例如 SWT.APPLICATION_MODAL | SWT.SHEET | SWT.NO_TRIM )。该对话框包含一个标签,例如正在加载...或 ProgressBar 。使用RCP时,可以选择 ProgressMonitorDialog

The second one is using a modal dialog with no Buttons so the user cannot close it (styles e.g SWT.APPLICATION_MODAL | SWT.SHEET | SWT.NO_TRIM). The dialog holds a Label e.g "Loading ..." or a ProgressBar. When using RCP the ProgressMonitorDialog is an option.

在我的情况下,我不想使用第二种解决方案,因为我不知道后台作业要运行多长时间。如果工作很短,我希望避免在ProgressMonitorDialog快速连续打开和关闭时出现闪烁。

In my case I dont want to use the second solution because I dont know how long the background job runs. If the job is very short I want to avoid some flickering when the ProgressMonitorDialog open and close in rapid succession.

@ screentiger.com在共享的文章中我没有看到如何在后台运行作业时忽略任何用户操作。
如果您可以更具体一些,并给出示例代码,我将不胜感激。

@screentiger.com I did not see in the article you shared how you ignore any user actions while a job runs in the background. I would appreciate if you could be more specific and maybe give a code example.

这篇关于eclipse rcp:如何在后台运行作业时阻止ui的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆