eclipse rcp:如何在后台运行作业时阻止 ui
我在对话框中有一个测试按钮,当用户单击该按钮时,我的应用程序将尝试通过 JDBC 连接到数据库。
对于某些测试用例,此作业将需要很长时间才能响应用户,例如网络连接超时。我通过将侦听器附加到该按钮并连接到该侦听器中的数据库来完成此操作。连接时,直到连接作业完成后,用户界面才会响应。连接时发生的任何用户操作将在连接作业完成后生效。
例如:该对话框中还有一个“取消”按钮,单击该按钮将关闭该对话框。如果在连接作业运行时单击“取消”按钮,则在连接作业完成之前该对话框不会关闭!
我希望在我的连接作业运行时发生的用户操作将被删除,而不是存储并稍后生效。
我在 windows 7 上使用 eclipse indigo
我的问题应该是这样的:
如何忽略在后台运行作业时发生的任何用户操作。
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.
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
到目前为止,我发现作业在后台运行时忽略任何用户操作的两种方法:
第一种是在操作开始之前调用 shell.setEnabled(false) ,然后调用 shell.setEnabled (true) 操作完成后。
(可选)结合
BusyIndicator
为用户提供一些反馈。第二个是使用没有按钮的模式对话框,因此用户无法关闭它(样式例如
SWT.APPLICATION_MODAL | SWT.SHEET | SWT.NO_TRIM
)。该对话框包含一个标签,例如“正在加载...”或一个ProgressBar
。使用 RCP 时,ProgressMonitorDialog
是一个选项。就我而言,我不想使用第二个解决方案,因为我不知道后台作业运行多长时间。如果工作很短,我想避免在 ProgressMonitorDialog 快速连续打开和关闭时出现一些闪烁。
@screentiger.com 我没有在您分享的文章中看到如何在作业在后台运行时忽略任何用户操作。
如果您能更具体并给出代码示例,我将不胜感激。
The two ways I found to ignore any user actions while a job runs in the background so far:
The first one is to call
shell.setEnabled(false)
before the operation starts andshell.setEnabled(true)
after the operation is done.(optional) combined with the
BusyIndicator
to give the user some feedback.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 aProgressBar
. When using RCP theProgressMonitorDialog
is an option.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 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.
swt 中只有一个 UI 线程(大多数其他线程也是如此),您的编程方式会阻塞 UI。
对于您的工作,您需要创建一个新线程来完成它,并且不要在 UI 线程中进行如此长期的工作,请使用 1.5 中引入的执行器。
最好的方法是使用eclipse的Job机制。您可以从以下位置开始学习: http://www.eclipse.org/articles /Article-Concurrency/jobs-api.html 我
there is only one UI thread in swt (also most others), your programming way blocks the UI.
For your job, you need to create a new thread to do it and don't so such long term job in UI thread, use the executor introduce in 1.5.
the best way is to use the eclipse Job mechanism. You can start learn from: http://www.eclipse.org/articles/Article-Concurrency/jobs-api.html I