ZK 팝 업 진도 바

2794 단어 threadUIxmlextzk
진도 조 는 우리 가 자주 사용 하 는 기능 이 어야 한다. 특히 빅 데이터 양 처리, 고강도 계산 을 할 때 다음은 작은 예 이다.
pg. zul 페이지 코드
<?page title="Auto Generated index.zul"?>
<window id="tt1" title="Hello World!!" border="normal">
	<label value="  ,        " />
	<button id="b1" label="  " onClick="pop()"></button>
	<zscript>
		public void pop() throws Exception{
			//        
			//win.setVisible(true);
			//       
			win.doModal();
		}
	</zscript>
	<window id="win" visible="false" border="normal" title="   "
		width="300px" height="60px" mode="popup" apply="test.Test1">
		<vbox>
			<progressmeter id="info" value="0" width="290px" />
		</vbox>
	</window>
	<zscript><![CDATA[
		//    ,      
		win.setVisible(false);
	]]></zscript>
</window>

배경 JAVA 관련 코드
package test;

import org.zkoss.lang.Threads;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Desktop;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.util.GenericForwardComposer;
import org.zkoss.zul.Progressmeter;

public class Test1 extends GenericForwardComposer {
	Progressmeter info;

	//     public    
	public Test1() {
	}

	public void doAfterCompose(Component comp) throws Exception {
		super.doAfterCompose(comp);
		comp.setVariable(comp.getId() + "Ctrl", this, true);
		
		//     
		// enable server push
		desktop.enableServerPush(true);
		// invoke working thread and passing required component as parameter
		new Thread(new WorkingThread(info)).start();
	}

	public class WorkingThread implements Runnable {
		private final Desktop dt;
		private final Progressmeter pg;

		public WorkingThread(Progressmeter info) {
			dt = info.getDesktop();
			pg = info;
		}

		public void run() {
			try {
				for (int i = 0; i <= 100; i++) {
					// Update each 5   
					Threads.sleep(5);
					// get full control of desktop
					Executions.activate(dt);
					pg.setValue(i);
					Executions.deactivate(dt);
				}
				dt.enableServerPush(false);
			} catch (Exception ex) {
			}
		}
	}

	public Progressmeter getInfo() {
		return info;
	}

	public void setInfo(Progressmeter info) {
		this.info = info;
	}
}

좋은 웹페이지 즐겨찾기