[richfaces-svn-commits] JBoss Rich Faces SVN: r5911 - in trunk/sandbox/ui/progressBAR/src/main: java/org/richfaces/component and 4 other directories.

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Thu Feb 7 09:41:27 EST 2008


Author: andrei_exadel
Date: 2008-02-07 09:41:27 -0500 (Thu, 07 Feb 2008)
New Revision: 5911

Modified:
   trunk/sandbox/ui/progressBAR/src/main/config/component/progressBar.xml
   trunk/sandbox/ui/progressBAR/src/main/java/org/richfaces/component/UIProgressBar.java
   trunk/sandbox/ui/progressBAR/src/main/java/org/richfaces/renderkit/AbstractProgressBarRenderer.java
   trunk/sandbox/ui/progressBAR/src/main/resources/org/richfaces/renderkit/html/css/progressBar.xcss
   trunk/sandbox/ui/progressBAR/src/main/resources/org/richfaces/renderkit/html/js/progressBar.js
   trunk/sandbox/ui/progressBAR/src/main/templates/org/richfaces/progressBar.jspx
Log:
refactroring of client mode, fix some problems

Modified: trunk/sandbox/ui/progressBAR/src/main/config/component/progressBar.xml
===================================================================
--- trunk/sandbox/ui/progressBAR/src/main/config/component/progressBar.xml	2008-02-07 13:55:03 UTC (rev 5910)
+++ trunk/sandbox/ui/progressBAR/src/main/config/component/progressBar.xml	2008-02-07 14:41:27 UTC (rev 5911)
@@ -26,6 +26,7 @@
 			<classname>org.ajax4jsf.webapp.taglib.AjaxComponentHandler</classname>
 		</taghandler>
 		&ui_component_attributes;
+		&ui_command_attributes;
 		&html_universal_attributes;
 		&html_events;
 		<property>
@@ -40,6 +41,12 @@
 			<description>Parameters for macrosubstitution in label</description>
 		</property>
 		<property>
+			<name>dualColoredLabel</name>
+			<classname>java.lang.Boolean</classname>
+			<description>Defines if component renderes as simple markup</description>
+			<defaultvalue>false</defaultvalue>
+		</property>
+		<property>
 			<name>minValue</name>
 			<classname>java.lang.Object</classname>
 			<description>Min value when initial state should be rendered</description>

Modified: trunk/sandbox/ui/progressBAR/src/main/java/org/richfaces/component/UIProgressBar.java
===================================================================
--- trunk/sandbox/ui/progressBAR/src/main/java/org/richfaces/component/UIProgressBar.java	2008-02-07 13:55:03 UTC (rev 5910)
+++ trunk/sandbox/ui/progressBAR/src/main/java/org/richfaces/component/UIProgressBar.java	2008-02-07 14:41:27 UTC (rev 5911)
@@ -41,13 +41,14 @@
     
     /** Request parameter name containing component state to render */
     public static final String FORCE_PERCENT_PARAM = "forcePercent";
+    
+    private static final String PERCENT_PARAM  = "percent";
 
  
     /* (non-Javadoc)
      * @see org.ajax4jsf.component.AjaxActionComponent#broadcast(javax.faces.event.FacesEvent)
      */
     public void broadcast(FacesEvent event) throws AbortProcessingException {
-	// TODO Auto-generated method stub
 	if (event instanceof AjaxEvent) {
 	    FacesContext facesContext = FacesContext.getCurrentInstance();
 	    AjaxContext ajaxContext = AjaxContextImpl
@@ -55,18 +56,10 @@
 
 	    HttpServletRequest request = (HttpServletRequest) facesContext
 		    .getExternalContext().getRequest();
-
+	    Map params = request.getParameterMap();
+	    if (!params.containsKey(FORCE_PERCENT_PARAM) 
+		    && params.containsKey(PERCENT_PARAM)) {
 	    Number percent = getNumber(this.getAttributes().get("value"));
-	    Number maxValue = getNumber(this.getAttributes().get("maxValue"));
-	    Map params = request.getParameterMap();
-	    if (params.containsKey(FORCE_PERCENT_PARAM)) {
-		ajaxContext.addComponentToAjaxRender(this);
-		String[] str = (String[]) params.get(FORCE_PERCENT_PARAM);
-		for (String s : str) {
-		    this.getAttributes().put(FORCE_PERCENT_PARAM, s);
-		}
-	    } else if (percent.doubleValue() < maxValue.doubleValue()
-		    && params.containsKey("percent")) {
 		ajaxContext.removeRenderedArea(this.getClientId(facesContext));
 		ajaxContext.setResponseData(getResponseData(percent,
 			facesContext));
@@ -113,10 +106,11 @@
 	boolean enabled = (Boolean) this.getAttributes().get("enabled");
 	map.put("enabled", Boolean.toString(enabled));
 
-	map.put("markup", getMarkup(facesContext, renderer));
+	if (!isSimple()) {
+	    map.put("markup", getMarkup(facesContext, renderer));
+	    map.put("context", getContext(renderer, percent));
+	}
 
-	map.put("context", getContext(renderer, percent));
-
 	addStyles2Responce(map, "completeClass", this.getAttributes().get(
 		"completeClass"));
 	addStyles2Responce(map, "remainClass", this.getAttributes().get(
@@ -149,6 +143,14 @@
 	buffer.append("}");
 	return new JSLiteral(buffer.toString());
     }
+    
+    /**
+     * Return true if markup is simple
+     * @return
+     */
+    private boolean isSimple() {
+	return this.getChildCount() == 0;
+    }
 
     /**
      * Returns label markup 

Modified: trunk/sandbox/ui/progressBAR/src/main/java/org/richfaces/renderkit/AbstractProgressBarRenderer.java
===================================================================
--- trunk/sandbox/ui/progressBAR/src/main/java/org/richfaces/renderkit/AbstractProgressBarRenderer.java	2008-02-07 13:55:03 UTC (rev 5910)
+++ trunk/sandbox/ui/progressBAR/src/main/java/org/richfaces/renderkit/AbstractProgressBarRenderer.java	2008-02-07 14:41:27 UTC (rev 5911)
@@ -18,6 +18,7 @@
 import javax.faces.context.ResponseWriter;
 import javax.faces.render.RenderKit;
 import javax.faces.render.RenderKitFactory;
+import javax.servlet.http.HttpServletRequest;
 
 import org.ajax4jsf.context.AjaxContext;
 import org.ajax4jsf.event.AjaxEvent;
@@ -64,12 +65,12 @@
      */
     public void renderForcedState(String state, FacesContext context,
 	    UIComponent component) throws IOException {
-	if ("initial".equals(state)) {
-	    encodeInitialState(context, component);
-	} else if ("progress".equals(state)) {
-	    encodeProgressState(context, component);
-	} else if ("complete".equals(state)) {
-	    encodeCompletedState(context, component);
+	if ("initialState".equals(state)) {
+	    encodeInitialState(context, component, true);
+	} else if ("progressState".equals(state)) {
+	    encodeProgressState(context, component, true);
+	} else if ("completeState".equals(state)) {
+	    encodeCompletedState(context, component, true);
 	}
 	component.getAttributes().remove(UIProgressBar.FORCE_PERCENT_PARAM);
     }
@@ -80,31 +81,13 @@
      * @param component
      * @return
      */
-    public String getForcedState(UIComponent component) {
+    public String getForcedState(FacesContext context, UIComponent component) {
 	String forcedState = null;
-	if (component.getAttributes().containsKey(UIProgressBar.FORCE_PERCENT_PARAM)) {
-	    ComponentVariables variables = ComponentsVariableResolver
-		    .getVariables(this, component);
-	    Number maxValue = getNumber(component.getAttributes().get(
-		    "maxValue"));
-	    Number minValue = getNumber(component.getAttributes().get(
-		    "minValue"));
-	    String percent = (String) component.getAttributes().get(
-		    UIProgressBar.FORCE_PERCENT_PARAM);
-	    Number p = null;
-	    try {
-		p = getNumber(percent);
-		if (p.doubleValue() < minValue.doubleValue()) {
-		    forcedState = "initial";
-		} else if (p.doubleValue() > maxValue.doubleValue()) {
-		    forcedState = "complete";
-		} else {
-		    forcedState = "progress";
-		}
-		variables.setVariable("percent", p);
-	    } catch (Exception e) {
-		e.getMessage();
-	    }
+	HttpServletRequest request = (HttpServletRequest)context.getExternalContext().getRequest();
+	Map params = request.getParameterMap();
+	if (params.containsKey(UIProgressBar.FORCE_PERCENT_PARAM)) {
+	    String[] str = (String[]) params.get(UIProgressBar.FORCE_PERCENT_PARAM);
+	    forcedState = str[0];
 	}
 	return forcedState;
     }
@@ -164,10 +147,6 @@
 	ResponseWriter writer = context.getResponseWriter();
 	UIProgressBar progressBar = (UIProgressBar) component;
 	String clientId = component.getClientId(context);
-	writer.startElement(HTML.SPAN_ELEM, component);
-	writer.writeAttribute(HTML.style_ATTRIBUTE, "display:none;", null);
-	writer.startElement(HTML.SCRIPT_ELEM, component);
-	writer.writeAttribute(HTML.TYPE_ATTR, "text/javascript", null);
 	StringBuffer pollScript = new StringBuffer("\n");
 	StringBuffer script = new StringBuffer("\n");
 	if (isAjaxMode(component) && progressBar.isEnabled()) {
@@ -184,9 +163,24 @@
 	}
 	pollScript.append(";\n");
 	writer.writeText(pollScript.toString(), null);
-	writer.endElement(HTML.SCRIPT_ELEM);
-	writer.endElement(HTML.SPAN_ELEM);
     }
+    
+    
+    /**
+     * Encodes script for state rendering in client mode
+     * @param context
+     * @param component
+     * @param state
+     * @throws IOException
+     */
+    public void encodeRenderStateScript (FacesContext context, UIComponent component, String state) throws IOException {
+	ResponseWriter writer = context.getResponseWriter();
+	StringBuffer script = new StringBuffer("\n");
+	script.append(
+		"$('" + component.getClientId(context)
+			+ "').component.renderState('").append(state).append("');");
+	writer.write(script.toString());
+    }
 
     /**
      * Encodes script for label rendering in client
@@ -198,16 +192,12 @@
     public void encodeLabelScript(FacesContext context, UIComponent component)
 	    throws IOException {
 	ResponseWriter writer = context.getResponseWriter();
-	StringBuffer script = new StringBuffer();
-	writer.startElement(HTML.SPAN_ELEM, component);
-	writer.startElement(HTML.SCRIPT_ELEM, component);
+	StringBuffer script = new StringBuffer("\n");
 	script.append(
 		"$('" + component.getClientId(context)
 			+ "').component.renderLabel(").append(
 		getMarkup(context, component)).append(",null);\n");
 	writer.append(script.toString());
-	writer.endElement(HTML.SCRIPT_ELEM);
-	writer.endElement(HTML.SPAN_ELEM);
 
     }
 
@@ -223,10 +213,6 @@
 	ResponseWriter writer = context.getResponseWriter();
 	UIProgressBar progressBar = (UIProgressBar) component;
 	ComponentVariables variables = ComponentsVariableResolver.getVariables(this, component);
-	writer.startElement(HTML.SPAN_ELEM, component);
-	writer.writeAttribute(HTML.style_ATTRIBUTE, "display: none;", null);
-	writer.startElement(HTML.SCRIPT_ELEM, component);
-
 	StringBuffer script = new StringBuffer();
 	String clientId = component.getClientId(context);
 	String containerId = ((UIComponent) AjaxRendererUtils
@@ -266,9 +252,6 @@
 	script.append(value.toString());
 	script.append(");\n");
 	writer.write(script.toString());
-
-	writer.endElement(HTML.SCRIPT_ELEM);
-	writer.endElement(HTML.SPAN_ELEM);
     }
 
     /**
@@ -302,6 +285,32 @@
 	String mode = (String) component.getAttributes().get("mode");
 	return "ajax".equalsIgnoreCase(mode);
     }
+    
+    /**
+     * Encodes client mode
+     * @param context
+     * @param component
+     * @param value
+     * @param min
+     * @param max
+     * @throws IOException
+     */
+    public void encodeClientMode (FacesContext context, UIComponent component, Number value, Number min, Number max) throws IOException {
+	ResponseWriter writer = context.getResponseWriter();
+	String clientId = component.getClientId(context);
+	String state = (value.doubleValue() <= min.doubleValue()) ? "initialState" : ((value.doubleValue() >= max.doubleValue()) ? "completeState" : "progressState");
+	writer.startElement(HTML.DIV_ELEM, component);
+	writer.writeAttribute(HTML.id_ATTRIBUTE, clientId , null);
+	encodeInitialState(context, component, false);
+	encodeProgressState(context, component, false);
+	encodeCompletedState(context, component, false);
+		startScript(writer, component);
+			encodeInitialScript(context, component, state);
+			encodeLabelScript(context, component);
+			encodeRenderStateScript(context, component, state);
+		endScript(writer, component);
+	writer.endElement(HTML.DIV_ELEM);
+    }
 
     /**
      * Methods encodes start facet of progress bar component
@@ -313,7 +322,7 @@
      * @throws IOException -
      *                 IOException
      */
-    public void encodeInitialState(FacesContext context, UIComponent component)
+    public void encodeInitialState(FacesContext context, UIComponent component, boolean isAjaxMode)
 	    throws IOException {
 	String clientId = component.getClientId(context);
 	String initialClass = (String) component.getAttributes().get(
@@ -322,15 +331,17 @@
 	ResponseWriter writer = context.getResponseWriter();
 	writer.startElement(HTML.DIV_ELEM, component);
 	getUtils().writeAttribute(writer, HTML.class_ATTRIBUTE, initialClass);
-	getUtils().writeAttribute(writer, "style", style);
-	writer.writeAttribute(HTML.id_ATTRIBUTE, clientId, null);
+	getUtils().writeAttribute(writer, "style", style + (!isAjaxMode ? "display: none" : ""));
+	writer.writeAttribute(HTML.id_ATTRIBUTE, (isAjaxMode) ? clientId : clientId + ":initialState", null);
 	UIComponent initial = component.getFacet("initial");
 	if (initial != null) {
 	    renderChild(context, initial);
 	}
-	encodeInitialScript(context, component,"initial");
-	if (isAjaxMode(component)) {
+	if (isAjaxMode) {
+	    startScript(writer, component);
+	    encodeInitialScript(context, component,"initialState");
 	    encodePollScript(context, component);
+	    endScript(writer, component);
 	}
 	writer.endElement(HTML.DIV_ELEM);
 
@@ -343,25 +354,32 @@
      * @param component
      * @throws IOException
      */
-    public void encodeProgressState(FacesContext context, UIComponent component)
+    public void encodeProgressState(FacesContext context, UIComponent component, boolean isAjaxMode)
 	    throws IOException {
 	ResponseWriter writer = context.getResponseWriter();
 	ComponentVariables variables = ComponentsVariableResolver.getVariables(
 		this, component);
 	String clientId = component.getClientId(context);
 	String styleClass = (String) variables.getVariable("styleClass");
+	boolean isSimple = isSimpleMarkup(component);
+	String shellClass = (!isSimple) ? "rich-progress-bar-shell-dig " : "rich-progress-bar-shell ";
 	writer.startElement("div", component);
 	getUtils().writeAttribute(
 		writer,
 		"class",
-		"rich-progress-bar-block rich-progress-bar-width rich-progress-bar-shell"
+		"rich-progress-bar-block rich-progress-bar-width " + shellClass
 			+ (styleClass != null ? styleClass : ""));
-	getUtils().writeAttribute(writer, "id", clientId);
+	getUtils().writeAttribute(writer, HTML.id_ATTRIBUTE, (isAjaxMode) ? clientId : clientId + ":progressState");
 	getUtils().writeAttribute(writer, "style",
-		variables.getVariable("style"));
-	encodeInitialScript(context, component,"progress");
-	encodeProgressBar(context, component);
-	encodeLabelScript(context, component);
+		variables.getVariable("style") + (!isAjaxMode ? "display: none" : ""));
+	encodeProgressBar(context, component, isSimple);
+	if (isAjaxMode) {
+	    startScript(writer, component);
+	    encodeInitialScript(context, component,"progressState");
+	    encodeLabelScript(context, component);
+	    encodePollScript(context, component);
+	    endScript(writer, component);
+	}
 	writer.endElement("div");
     }
 
@@ -374,7 +392,7 @@
      *                component instance
      * @throws IOException
      */
-    public void encodeProgressBar(FacesContext context, UIComponent component)
+    public void encodeProgressBar(FacesContext context, UIComponent component, boolean isSimple)
 	    throws IOException {
 	ResponseWriter writer = context.getResponseWriter();
 	String clientId = component.getClientId(context);
@@ -390,36 +408,42 @@
 
 	String remainClass = (String) component.getAttributes().get(
 		"remainClass");
-
-	// <div class='remainClass'  id='clientId:remain'  style='style'></div>
-	writer.startElement("div", component);
-	getUtils().writeAttribute(writer, "class",
-		"rich-progress-bar-width rich-progress-bar-remained rich-progress-bar-padding " + remainClass);
-	getUtils().writeAttribute(writer, "id", clientId + ":remain");
-	getUtils().writeAttribute(writer, "style", style);
-	writer.endElement("div");
 	
-	// <div class='rich-progress-bar-uploaded'  id='clientId:upload'  style='style'>
-	writer.startElement("div", component);
-	getUtils()
-		.writeAttribute(writer, "class", "rich-progress-bar-uploaded");
-	getUtils().writeAttribute(writer, "id", clientId + ":upload");
-	getUtils().writeAttribute(writer, "style",
-		(style != null ? style + ";" : "") + " width: " + width + "%;");
-
-	// <div class='completeClass' id='clientId:complete' style='style'></div>
-	writer.startElement("div", component);
-	getUtils().writeAttribute(writer, "class",
-		"rich-progress-bar-height rich-progress-bar-width rich-progress-bar-completed rich-progress-bar-padding " + completeClass);
-	getUtils().writeAttribute(writer, "id", clientId + ":complete");
-	getUtils().writeAttribute(writer, "style", style);
-	writer.endElement("div");
-
-	// </div>
-	writer.endElement("div"); 
-
-	if (isAjaxMode(component)) {
-	    encodePollScript(context, component);
+	if (!isSimple) {
+        	// <div class='remainClass'  id='clientId:remain'  style='style'></div>
+        	writer.startElement("div", component);
+        	getUtils().writeAttribute(writer, "class",
+        		"rich-progress-bar-width rich-progress-bar-remained rich-progress-bar-padding " + remainClass);
+        	getUtils().writeAttribute(writer, "id", clientId + ":remain");
+        	getUtils().writeAttribute(writer, "style", style);
+        	writer.endElement("div");
+        	
+        	// <div class='rich-progress-bar-uploaded-dig'  id='clientId:upload'  style='style'>
+        	writer.startElement("div", component);
+        	getUtils()
+        		.writeAttribute(writer, "class", "rich-progress-bar-uploaded-dig");
+        	getUtils().writeAttribute(writer, "id", clientId + ":upload");
+        	getUtils().writeAttribute(writer, "style",
+        		(style != null ? style + ";" : "") + " width: " + width + "%;");
+        
+        	// <div class='completeClass' id='clientId:complete' style='style'></div>
+        	writer.startElement("div", component);
+        	getUtils().writeAttribute(writer, "class",
+        		"rich-progress-bar-height rich-progress-bar-width rich-progress-bar-completed rich-progress-bar-padding " + completeClass);
+        	getUtils().writeAttribute(writer, "id", clientId + ":complete");
+        	getUtils().writeAttribute(writer, "style", style);
+        	writer.endElement("div");
+        
+        	// </div>
+        	writer.endElement("div");
+	} else {
+		writer.startElement("div", component);
+        	getUtils().writeAttribute(writer, "class",
+        		"rich-progress-bar-height rich-progress-bar-uploaded " + completeClass);
+        	getUtils().writeAttribute(writer, "id", clientId + ":upload");
+        	getUtils().writeAttribute(writer, "style",
+        		(style != null ? style + ";" : "") + " width: " + width + "%;");
+        	writer.endElement("div");
 	}
 
     }
@@ -440,6 +464,30 @@
     
     
     /**
+     * Writes start script element
+     * @param writer
+     * @param component
+     * @throws IOException
+     */
+    private void startScript(ResponseWriter writer, UIComponent component)throws IOException {
+	writer.startElement(HTML.SPAN_ELEM, component);
+	writer.writeAttribute(HTML.style_ATTRIBUTE, "display: none;", null);
+	writer.startElement(HTML.SCRIPT_ELEM, component);
+    }
+    
+    /**
+     * Writes end script element
+     * @param writer
+     * @param component
+     * @throws IOException
+     */
+    private void endScript(ResponseWriter writer, UIComponent component)throws IOException {
+	writer.endElement(HTML.SCRIPT_ELEM);
+	writer.endElement(HTML.SPAN_ELEM);
+    }
+    
+    
+    /**
      * Returns context for macrosubstitution
      * @param component
      * @return
@@ -456,6 +504,15 @@
 	}
 	return literal;
     }
+    
+    /**
+     * Returns true if markup should rendered as simple 2 divs
+     * @param component
+     * @return
+     */
+    private boolean isSimpleMarkup(UIComponent component) {
+	return (component.getChildCount() == 0);
+    }
 
     /**
      * Methods encodes finish facet of progress bar component
@@ -467,44 +524,41 @@
      * @throws IOException -
      *                 IOException
      */
-    public void encodeCompletedState(FacesContext context, UIComponent component)
+    public void encodeCompletedState(FacesContext context, UIComponent component, boolean isAjaxMode)
 	    throws IOException {
-	boolean isAjax = isAjaxMode(component);
-	Object rerenderAfterComplete = component.getAttributes().get(
-		"reRenderAfterComplete");
-	Set ajaxRegions = AjaxRendererUtils.asSet(rerenderAfterComplete);
+	if (isAjaxMode) {
+	    Object rerenderAfterComplete = component.getAttributes().get(
+		    "reRenderAfterComplete");
+	    Set ajaxRegions = AjaxRendererUtils.asSet(rerenderAfterComplete);
 
-	if (ajaxRegions != null) {
-	    for (Iterator iter = ajaxRegions.iterator(); iter.hasNext();) {
-		String id = iter.next().toString();
-		AjaxContext ajaxContext = AjaxContext
-			.getCurrentInstance(context);
-		ajaxContext.addComponentToAjaxRender(component, id);
+	    if (ajaxRegions != null) {
+		for (Iterator iter = ajaxRegions.iterator(); iter.hasNext();) {
+		    String id = iter.next().toString();
+		    AjaxContext ajaxContext = AjaxContext
+			    .getCurrentInstance(context);
+		    ajaxContext.addComponentToAjaxRender(component, id);
+		}
 	    }
 	}
-
 	String clientId = component.getClientId(context);
 	String finishClass = (String) component.getAttributes().get(
 		"finishClass");
 	String style = (String) component.getAttributes().get("style");
 	ResponseWriter writer = context.getResponseWriter();
 	writer.startElement(HTML.DIV_ELEM, component);
-	writer.writeAttribute(HTML.id_ATTRIBUTE, clientId, null);
+	writer.writeAttribute(HTML.id_ATTRIBUTE, (isAjaxMode) ? clientId : clientId + ":completeState", null);
 	getUtils().writeAttribute(writer, HTML.class_ATTRIBUTE, finishClass);
-	getUtils().writeAttribute(writer, "style", style);
+	getUtils().writeAttribute(writer, "style", style + (!isAjaxMode ? "display: none" : ""));
 
 	UIComponent completed = component.getFacet("complete");
 	if (completed != null) {
 	    renderChild(context, completed);
 	}
-	encodeInitialScript(context, component,"completed");
-	if (isAjax) {
-	    writer.startElement(HTML.SPAN_ELEM, component);
-		writer.writeAttribute(HTML.style_ATTRIBUTE, "display: none;", null);
-	    writer.startElement(HTML.SCRIPT_ELEM, component);
+	if (isAjaxMode) {
+	    startScript(writer, component);
+	    encodeInitialScript(context, component,"completeState");
 	    writer.write(getStopPollScript(clientId).toString());
-	    writer.endElement(HTML.SCRIPT_ELEM);
-	    writer.endElement(HTML.SPAN_ELEM);
+	    endScript(writer, component);
 	}
 	writer.endElement(HTML.DIV_ELEM);
 

Modified: trunk/sandbox/ui/progressBAR/src/main/resources/org/richfaces/renderkit/html/css/progressBar.xcss
===================================================================
--- trunk/sandbox/ui/progressBAR/src/main/resources/org/richfaces/renderkit/html/css/progressBar.xcss	2008-02-07 13:55:03 UTC (rev 5910)
+++ trunk/sandbox/ui/progressBAR/src/main/resources/org/richfaces/renderkit/html/css/progressBar.xcss	2008-02-07 14:41:27 UTC (rev 5911)
@@ -13,24 +13,39 @@
 .rich-progress-bar-height{height : 13px;}
 .rich-progress-bar-width{width : 200px}	
 .rich-progress-bar-block{white-space : nowrap;}		
-.rich-progress-bar-uploaded{overflow : hidden; position : absolute; top : 0px; left : 0px;}
-.rich-progress-bar-shell{position : relative; margin-bottom : 2px; border : 1px solid;}
+.rich-progress-bar-uploaded{background-repeat : repeat-x;}
+.rich-progress-bar-uploaded-dig{overflow : hidden; position : absolute; top : 0px; left : 0px;}
+.rich-progress-bar-shell{margin-bottom : 2px; border : 1px solid;}
+.rich-progress-bar-shell-dig{position : relative; margin-bottom : 2px; border : 1px solid;}
 .rich-progress-bar-remained{text-align : center; font-weight : bold; position : relative;}
 .rich-progress-bar-completed{text-align : center; font-weight : bold; background-repeat : repeat-x;}
 .rich-progress-bar-padding{padding: 0px}
 		
 	</f:verbatim>
 	
-	<u:selector name=".rich-progress-bar-shell">
+	<u:selector name=".rich-progress-bar-shell-dig">
+	<u:style name="background-color" skin="controlBackgroundColor" />
     <u:style name="border-color" skin="panelBorderColor" />
 	</u:selector>
 	
+	<u:selector name=".rich-progress-bar-shell-dig">
+    <u:style name="border-color" skin="panelBorderColor" />
+	</u:selector>
+	
 	<u:selector name=".rich-progress-bar-remained">
     <u:style name="background-color" skin="controlBackgroundColor" />
     <u:style name="text-color" skin="controlTextColor" />
 	</u:selector>
 	
 	<u:selector name=".rich-progress-bar-uploaded">
+	<u:style name="background-image">
+  		<f:resource f:key="org.richfaces.renderkit.html.images.ProgressBarAnimatedBg" />
+	</u:style>
+	<u:style name="background-color" skin="selectControlColor" />
+    <u:style name="border-color" skin="panelBorderColor" />
+ 	</u:selector>
+	
+	<u:selector name=".rich-progress-bar-uploaded-dig">
      <u:style name="border-color" skin="panelBorderColor" />
  	</u:selector>
  	

Modified: trunk/sandbox/ui/progressBAR/src/main/resources/org/richfaces/renderkit/html/js/progressBar.js
===================================================================
--- trunk/sandbox/ui/progressBAR/src/main/resources/org/richfaces/renderkit/html/js/progressBar.js	2008-02-07 13:55:03 UTC (rev 5910)
+++ trunk/sandbox/ui/progressBAR/src/main/resources/org/richfaces/renderkit/html/js/progressBar.js	2008-02-07 14:41:27 UTC (rev 5911)
@@ -31,14 +31,19 @@
 	  	if (!$(this.id)) { return; } 
 		if (data) {
 			this.value = data['percent'];
-			if (this.state == "progress") {
+			if (this.state == "progressState") {
 				this.updateComponent(data);
 				this.renderLabel(data['markup'], data['context']);
-			} else if (this.state == "initial" && this.value >= this.getMinValue()) {
-				this.state = "progress";
-				this.forceState(this.value, function () { this.poll() }.bind(this));
+				if (this.value >= this.getMaxValue()) {
+					this.forceState("complete",null);
+					return;
+				}
+			} else if (this.state == "initialState" && this.value >= this.getMinValue()) {
+				this.state = "progressState";
+				this.forceState("progressState", function () { this.poll() }.bind(this));
+				return;
 			}
-			this.poll();
+			this.poll(); 
 		}
 		
 	},
@@ -99,7 +104,7 @@
 		return context;
 	},
 	renderLabel: function (markup, context) {
-		if (!markup || this.state != "progress") {
+		if (!markup || this.state != "progressState") {
 			return;
 		}
 		if (!context) {
@@ -117,11 +122,13 @@
 		return placeholders;
 	},
 	setLabel: function (str) {
-	if (this.state != "progress") { return; }
+		if (this.state != "progressState") { return; }
+		var d = $(this.id + ":remain");
+		if (!d) { return; } 
 		var lbl = this.interpolate(str, this.getContext());
 		if (lbl)
-			$(this.id + ":remain").innerHTML = $(this.id + ":complete").innerHTML = lbl;
-	this.markup = null;
+			d.innerHTML = $(this.id + ":complete").innerHTML = lbl;
+		this.markup = null;
 	},
 	getMode: function () {
 		return this.mode;
@@ -143,17 +150,17 @@
 			if (val.indexOf("%") < 0)
 				val = val + "%";
 		}
-		if ( parseFloat(p) <  parseFloat(this.getMinValue())) {
-			if (!this.isAjaxMode()) { 
-				this.forceState(p, null);
-				return;
+		
+		if (!this.isAjaxMode()) {
+			if ( parseFloat(p) <=  parseFloat(this.getMinValue())) {
+				this.switchState("initialState");
+			}else if ( parseFloat(p) >= parseFloat(this.getMaxValue())) {
+				this.switchState("completeState");
+			}else {
+				this.switchState("progressState");
 			}
-		} else if ( parseFloat(p) > parseFloat(this.getMaxValue()))  {
-			if (!this.isAjaxMode()) { 
-				this.forceState(p, null);
-				return;
-			} 
 		}
+		if (!this.isAjaxMode() && this.state != "progressState") return;
 		
 		if (this.markup) {
 			this.renderLabel(this.markup, this.getContext());
@@ -161,13 +168,14 @@
 			//this.setLabel("{value}%");
 		}
 	
-		d = $(this.id + ":upload");
+		var d = $(this.id + ":upload");
 		if (d != null) d.style.width = val;
 	
 	},
 	enable: function (ev) {
 		if (!this.isAjaxMode()) {
-			this.forceState("0", null);
+			this.switchState("progressState");
+			this.setValue(0);
 		}else {
 			this.disable();
 			this.poll();			
@@ -179,11 +187,25 @@
 	finish: function () {
 		//this.switchMode("completed");
 	},
-	forceState: function (percent, oncomplete) {
+	hideAll: function () {
+		Element.hide($(this.id + ":progressState"));
+		Element.hide($(this.id + ":completeState"));
+		Element.hide($(this.id + ":initialState"));
+	},
+	switchState: function (state) {
+		this.state = state;
+		this.hideAll();
+		Element.show($(this.id + ":" + state));
+	},
+	renderState: function (state) {
+		this.state = state;
+		Element.show($(this.id + ":" + state));
+	},
+	forceState: function (state, oncomplete) {
 		var options = {};
 		options['parameters'] = {};
 		options['parameters'][this.id] = this.id;
-		options['parameters']['forcePercent'] = percent;
+		options['parameters']['forcePercent'] = state;
 		options['actionUrl'] = this.options.actionUrl;
 		if (oncomplete) {
 			options['oncomplete'] = oncomplete;

Modified: trunk/sandbox/ui/progressBAR/src/main/templates/org/richfaces/progressBar.jspx
===================================================================
--- trunk/sandbox/ui/progressBAR/src/main/templates/org/richfaces/progressBar.jspx	2008-02-07 13:55:03 UTC (rev 5910)
+++ trunk/sandbox/ui/progressBAR/src/main/templates/org/richfaces/progressBar.jspx	2008-02-07 14:41:27 UTC (rev 5911)
@@ -31,7 +31,7 @@
     variables.setVariable("percent",value);
     variables.setVariable("style",(String)component.getAttributes().get("style"));
     variables.setVariable("styleClass",(String)component.getAttributes().get("styleClass"));
-	String forcedState = getForcedState(component);
+	String forcedState = getForcedState(context,component);
     
  ]]>
 </jsp:scriptlet>
@@ -40,12 +40,14 @@
 <![CDATA[
 if (forcedState != null) {
     renderForcedState(forcedState,context,component);
-}else if (value.doubleValue() <= minValue.doubleValue()) { 
-    encodeInitialState(context, component);
+} if (!isAjax) {
+    encodeClientMode(context,component,value,minValue,maxValue);
+} else if (value.doubleValue() <= minValue.doubleValue()) {
+    encodeInitialState(context, component, true);
 } else if (value.doubleValue() >= maxValue.doubleValue()) {
-    encodeCompletedState(context, component);
+    encodeCompletedState(context, component, true);
 } else  {
-    encodeProgressState(context, component);
+    encodeProgressState(context, component, true);
 }
  ]]>
 </jsp:scriptlet>




More information about the richfaces-svn-commits mailing list