1 33 34 package com.icesoft.icefaces.samples.showcase.components.progressBar; 35 36 import javax.faces.event.ActionEvent; 37 38 import com.icesoft.faces.async.render.RenderManager; 39 import com.icesoft.faces.async.render.Renderable; 40 import com.icesoft.faces.component.outputprogress.OutputProgress; 41 import com.icesoft.faces.webapp.xmlhttp.PersistentFacesState; 42 import com.icesoft.faces.webapp.xmlhttp.RenderingException; 43 44 51 public class OutputProgressRenderBean implements Renderable { 52 53 56 private PersistentFacesState state; 57 private RenderManager renderManager; 58 59 64 public PersistentFacesState getState() { 65 66 return state; 67 } 68 69 74 public void renderingException(RenderingException renderingException) { 75 renderingException.printStackTrace(); 76 } 77 78 83 public void setRenderManager(RenderManager renderManager) { 84 85 this.renderManager = renderManager; 86 } 87 88 93 public RenderManager getRenderManager() { 94 return null; 95 } 96 97 private boolean disableStartButton = false; 99 100 private OutputProgress progressBar; 102 103 private int percent = 0; 105 106 109 public OutputProgressRenderBean() { 110 state = PersistentFacesState.getInstance(); 111 } 112 113 118 public boolean isDisableStartButton() { 119 return disableStartButton; 120 } 121 122 125 public void start(ActionEvent event) { 126 Thread testThread = new Thread (new LongOperationRunner(this)); 127 testThread.start(); 128 } 129 130 135 public int getPercent() { 136 return percent; 137 } 138 139 144 public void setPercent(int percent) { 145 this.percent = percent; 146 } 147 148 153 public OutputProgress getProgressBar() { 154 return progressBar; 155 } 156 157 162 public void setProgressBar(OutputProgress progressBar) { 163 this.progressBar = progressBar; 164 } 165 166 170 protected class LongOperationRunner implements Runnable { 171 172 PersistentFacesState state = null; 173 OutputProgressRenderBean outputBean; 174 175 public LongOperationRunner(OutputProgressRenderBean outputBean) { 176 disableStartButton = true; 177 percent = 0; 178 this.outputBean = outputBean; 179 } 180 181 public void run() { 182 try { 183 for (int i = 0; i <= 100; i += 10) { 184 Thread.sleep(300); 186 percent = i; 188 try { 190 renderManager.requestRender(outputBean); 191 } catch (IllegalStateException e) { 192 e.printStackTrace(); 193 } 194 } 195 disableStartButton = false; 197 198 renderManager.requestRender(outputBean); 200 } 201 catch (InterruptedException e) { 202 e.printStackTrace(); 203 } 204 } 205 } 206 207 212 public boolean isRunningTask() { 213 return disableStartButton; 214 } 215 216 221 public void setRunningTask(boolean runningTask) { 222 disableStartButton = runningTask; 223 } 224 225 } | Popular Tags |