PDA

View Full Version : Display a waiting image during a long action ...



Nico33
27 Jan 2010, 1:02 PM
Hi all,

I have a long action (in my case, it's a grid.reconfigure(...)). But tommorow, it can be another thing.

What I would like is to display a waiting message during the long time. But I don't know what is the best way, as GXT is a mono-thread environment.

I've tried to do this (inside a click button event) :



final Window window = new Window();
window.setSize(200, 80);
window.setPlain(true);
window.setModal(true);
window.setBlinkModal(true);
window.setLayout(new FitLayout());

Status status = new Status();
window.add(status);
status.setBusy("Please wait ...");
status.setWidth(150);

window.show();

Timer t = new Timer()
{
@Override
public void run()
{
grid.reconfigure(grid.getStore(), cm);
grid.getView().refresh(true);
window.hide();
}
};
t.schedule(100);
using a Timer is not maybe a good solution, in addition the animated image isn't moving ...

What is the best way to do that ?

Thanks in advance for any help.

Love Yao
28 Jan 2010, 12:06 AM
yes i meet the same situation

my gif image isn't moving!!!!!!!

micgala
28 Jan 2010, 2:48 AM
Hi.

The image does not move because, as pointed, the browsers does not handle multi thread javascript... there is no such a thing.

So, for client operations, the browser hangs, and then, the gif images won't move.

Nico33
28 Jan 2010, 2:50 AM
Thanks for your answer, but what is the best way to do such a thing ?

sven
28 Jan 2010, 2:51 AM
Thanks for your answer, but what is the best way to do such a thing ?

Only dispaly a message without an animated icon.

Nico33
28 Jan 2010, 2:52 AM
ok.
And the use of timer is what you advice ?

sven
28 Jan 2010, 2:55 AM
No, that will block the UI longer than needed. If the action is syncron, what reconfigure of a grid is, than you can simle show the message before calling that method and hide it again afterwards. With your code now,you just delay everything with 100ms.

Nico33
28 Jan 2010, 3:09 AM
that's was I first try, but the message isn't displayed ...
I think this is because no render is called ...




window.show();

grid.reconfigure(grid.getStore(), cm);
grid.getView().refresh(true);

window.hide();

me2
28 Jan 2010, 7:43 AM
You can perform your long running action on a DeferredCommand, for example:


protected void onReconfigure()
{
// tell the grid to mask itself first
grid.mask("Please Wait", "x-mask-loading");

DeferredCommand.addCommand(new Command() {
public void execute() {
doGridReconfigure(); // do your long running action
grid.unmask(); // now take the mask down
}
});
}

Nico33
28 Jan 2010, 12:39 PM
oh great, this is exactly what I need :D. Something new learned !

Thanks for your answer.
Best regards

jadrake75
1 Feb 2010, 10:29 AM
If you are doing something like refreshing a grid content, while the data is being processed on the server you will get gif animation, but as soon as it starts streaming into the browser the browser thread will be blocked processing the return data (such as JSON->model datas). One thing I find interesting is the differences in browsers in this regard.... ie. building the grid store for 150 items in IE might take 2 seconds in my system which is noticable with the icon, whereas in G-Chrome is instantaneous.

Has anyone thought about using something like a flash plugin for this? I don't know if flash is constrained by the browser threads or not. The disadvantage here of course is the "bootstrap" time of the plugin.

Does anyone know of a way to "yield" the thread in GXT? in my case I have a custom structure-processing JSON reader (really a refactored subclass) and it'd be nice to be able to "yield" after processing N objects to allow something like the gif to refresh.

Arno.Nyhm
3 Feb 2010, 9:25 AM
Does anyone know of a way to "yield" the thread in GXT? in my case I have a custom structure-processing JSON reader (really a refactored subclass) and it'd be nice to be able to "yield" after processing N objects to allow something like the gif to refresh.

if i look at the GXT JSON reader this is synchronus (no callbacks are used) so you can not split it with a "DeferredCommand.addCommand(new Command() { ..." :-(

so i dont have an idea how to do this.