带有进度条的模态窗口,用于长任务 [英] Modal window with progressbar for long tasks

查看:136
本文介绍了带有进度条的模态窗口,用于长任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在某些情况下,我希望在长时间运行的查询时向用户显示带有进度条的模态窗口。 (对于单个UI项目,我使用方法 setEnabled(true / false)但我想要更优雅的解决方案。)

In some cases, I want show to user a modal window with a progress bar when the long running query. (For individual UI items, I use the method setEnabled (true/ false) but I want more elegant solution.)

例如,在入口点,直到所有元素都未初始化 -

For example, in the entry point, until all elements not initialized -

public void onModuleLoad() {
   // initialization of the interface here
}

还有,例如,当完成依赖列表框(关系一对多)

And also, for example, when completing the dependent list box (relationship one to many)

@UiHandler("listBox")
public void onListBoxChange(ChangeEvent event) {
   someService.findDependencies(id, new AsyncCallback<List<DependencyDTO>>() {
      public void onFailure(Throwable caught) {
         // exception handling here
      }
      public void onSuccess(List<DependencyDTO> data) {
         // listBox filling here
      }
   });
}

Vaadin 应用程序我可以将以下代码添加到监听器中,例如 -

In Vaadin applications I can added to the listener the following code, for example -

...
Thread thread = new Thread() {
    @Override
    public void run() {                 
       // some initialization here 
       window.removeWindow(blockerWindow);
    }
};  

thread.start();             
blockerWindow = new BlockerWindow();
window.addWindow(blockerWindow);
...

在我的情况下,我可以使用以下方法显示一个窗口带进度条 -

In my case, I can use the following method to display a window with a progress bar -

private void freezeInterface() {
   blockerWindow = new BlockerWindow()
   blockerWindow.setGlassEnabled(true);
   blockerWindow.setAnimationEnabled(true);
   blockerWindow.setModal(true);
   blockerWindow.center();
   blockerWindow.show();
}

隐藏窗口的方法 -

And the method to hide window -

private void unfreezeInterface() {
   blockerWindow.hide();
}

问题是,何时隐藏窗口。

例如,在入境点有一系列查询 -

For example, at the entry point there are series of queries -

...
service1.findDependenciesForListBox1(id1, new AsyncCallback<List<Dependency1DTO>>() {
   public void onFailure(Throwable caught) {
      // exception handling here
   }
   public void onSuccess(List<Dependency1DTO> data) {
      // listBox1 filling here
   }
});

service2.findDependenciesForListBox2(id2, new AsyncCallback<List<Dependency2DTO>>() {
   public void onFailure(Throwable caught) {
      // exception handling here
   }
   public void onSuccess(List<Dependency2DTO> data) {
      // listBox2 filling here
   }
});

serviceN.findDependenciesForListBoxN(idN, new AsyncCallback<List<DependencyNDTO>>() {
   public void onFailure(Throwable caught) {
      // exception handling here
   }
   public void onSuccess(List<DependencyNDTO> data) {
      // listBoxN filling here
   }
});     

依此类推。

答案以先前未知的顺序出现,并以其中一种方法隐藏窗口 onSuccess 我不能。

The answers come in a previously unknown sequence and hide the window in one of the methods onSuccess I can not.

我可以使用计时器,但我事先并不知道传递的时间时间表

I can use a timer, but I do not know beforehand the time which to pass in schedule.

...
blockerWindow.show();   
private void unfreezeInterface() {
   timer = new Timer() {
      public void run() {
         blockerWindow.hide();
      }
   };
   timer.schedule(15000);
}
...

如何在<$ c中正确实现$ c> GWT ?

推荐答案

如果你知道要获得的回复数量,你可以使用这样的方法:

If you know the number of responses to get, you can use such approach:

class TaskCompletedHandler{ // inner class
    private static final int NUMBER_OF_RESPONSES = 4;//just example

    private int tasksCompleted;

    public void notifyOfCompletedTask(){
        tasksCompleted++;
        if (tasksCompleted == NUMBER_OF_RESPONSES){
            blockerWindow.hide(); 
        }
    }
}

之前创建此类的实例显示模态窗口,然后在AsyncCallback中通知此处理程序

create instance of this class before showing modal window and then notify this handler in AsyncCallback

service1.findDependenciesForListBox1(id1, new AsyncCallback<List<Dependency1DTO>>() {
   public void onFailure(Throwable caught) {
      taskCompletedHandler.notifyOfCompletedTask();
      // exception handling here
   }
   public void onSuccess(List<Dependency1DTO> data) {
      taskCompletedHandler.notifyOfCompletedTask();
      // listBox1 filling here
   }
});

这篇关于带有进度条的模态窗口,用于长任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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