0

Progressmeter change while a process is running

asked 2012-09-27 14:56:46 +0800

Neus gravatar image Neus
1415 14

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!

delete flag offensive retag edit

7 Replies

Sort by ยป oldest newest

answered 2012-10-09 08:41:50 +0800

vincentjian gravatar image vincentjian
2245 6

updated 2012-10-09 08:49:18 +0800

Hi Neus,

You can modify the sample from zkdemo.
Here is the demo I modified: http://zkfiddle.org/sample/2ue3vcb/6-progressmeter-sample

link publish delete flag offensive edit

answered 2012-10-09 10:22:30 +0800

Neus gravatar image Neus
1415 14

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

link publish delete flag offensive edit

answered 2012-10-11 02:31:36 +0800

vincentjian gravatar image vincentjian
2245 6

Hi Neus,

I have modified the code, take a look on the zk fiddle. Not sure if it is the best implementation.

link publish delete flag offensive edit

answered 2012-12-04 17:11:05 +0800

Neus gravatar image Neus
1415 14

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

link publish delete flag offensive edit

answered 2012-12-05 08:24:54 +0800

vincentjian gravatar image vincentjian
2245 6

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);
	}
}

Hope it solve your problem.

link publish delete flag offensive edit

answered 2012-12-05 08:40:37 +0800

vincentjian gravatar image vincentjian
2245 6

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);
	}
}

link publish delete flag offensive edit

answered 2014-06-10 16:05:10 +0800

Senthilchettyin gravatar image Senthilchettyin flag of India
2623 3 8
http://emrpms.blogspot.in...

Hi vincentjian

Can you give me the same in MVVM ?

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
2 followers

RSS

Stats

Asked: 2012-09-27 14:56:46 +0800

Seen: 230 times

Last updated: Jun 10 '14

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More