-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi,
I have a long process that goes over a list. To show the user how many items these process have checked I use a progress meter.
Now, it shows it to the user when all items have been scanned.
I want to change the progressmeter item by item. So, one item is scanned -> progressmeter move forward. Other item is scanned -> progressmeter move forward...
How can I do this?
Thank you!
Hi Neus,
You can modify the sample from zkdemo.
Here is the demo I modified: http://zkfiddle.org/sample/2ue3vcb/6-progressmeter-sample
But in the example you provide, the progressmeter increase every 1 second, on the timer tick, isn't it?In my case, I run a server process for every item I need to scan. Maybe when it is runned for 1 item, the process takes 1 second. For another item maybe it takes more. I can't establish 1 second for every item. What I need is to increase the progressmeter when the process has complete.
I tried this:
for(int i=0;i<items;i++){ //Server process for the item Events.echoEvent("onProcesoCompletado", BTNProcesar, null); } public void onProcesoCompletado$BTNProcesar(){ int current = ++percent * 100 / all; progresoAcciones.setValue(current); }
But progressmeter is still painted at the end of all
Hi Neus,
I have modified the code, take a look on the zk fiddle. Not sure if it is the best implementation.
Hi,
It's been a long since I started this thread but I'm with this problem yet.
I studied your example and I realize taht it is increasing using the tick of the timer, too. If I set the timer delay to 5000 the progressmeter is increased every 5 seconds so it is not taking into account when the server process ends.
I saw this post http://www.zkoss.org/forum/listComment/18987-Update-Progressmeter-form-java-controller?lang=en and I tried to get something straight about it but I'm not able to do that yet.
Any other idea to help me?
Thank you
Hi Neus,
I tried to update progress meter by server push and it works. Here is the sample code:
<!-- ZUL page --> <zk> <window apply="test.ProgressComposer"> <progressmeter id="pm" value="0" /> <button id="btn" label="start" /> </window> </zk>
public class ProgressComposer extends SelectorComposer<Window> { private static final long serialVersionUID = -8327879927085566401L; @Wire private Progressmeter pm; @WireVariable private Desktop desktop; private int all = 10; private Thread myThread = new Thread() { public void run() { if(!desktop.isServerPushEnabled()) return; try { for (int i = 1; i <= all; i++) { long ms = (long) (Math.random() * 2000); //simulate long operation Thread.sleep(ms); Executions.activate(desktop); progress(i); Executions.deactivate(desktop); } } catch (InterruptedException e) { e.printStackTrace(); } } }; @Listen("onClick = #btn") public void startProgress(Event event) { desktop.enableServerPush(true); myThread.start(); } private void progress(int current) { pm.setValue(current * 100 /all); if (current == all) desktop.enableServerPush(false); } }
And here is another solution if you would like to use EventQueue instead of ServePush:
public class ProgressComposer extends SelectorComposer<Window> { private static final long serialVersionUID = -8327879927085566401L; @Wire private Progressmeter pm; @WireVariable private Desktop desktop; private int all = 10; private final EventQueue<Event> que = EventQueues.lookup("progress", EventQueues.SESSION, true); private Thread myThread = new Thread() { public void run() { try { for (int i = 1; i <= all; i++) { long ms = (long) (Math.random() * 2000); //simulate long operation Thread.sleep(ms); que.publish(new Event("next", null, new Integer(i))); } } catch (InterruptedException e) { e.printStackTrace(); } } }; @Listen("onClick = #btn") public void startProgress(Event event) { myThread.start(); } @Subscribe(value = "progress", scope = EventQueues.SESSION) public void progress(Event event) { Integer current = (Integer) event.getData(); pm.setValue(current * 100 /all); } }
Hi vincentjian
Can you give me the same in MVVM ?
Asked: 2012-09-27 14:56:46 +0800
Seen: 230 times
Last updated: Jun 10 '14