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

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Wed Jan 16 08:50:03 EST 2008


Author: andrei_exadel
Date: 2008-01-16 08:50:02 -0500 (Wed, 16 Jan 2008)
New Revision: 5414

Modified:
   trunk/sandbox/ui/progressBAR/src/main/config/component/progressBar.xml
   trunk/sandbox/ui/progressBAR/src/main/java/org/richfaces/renderkit/AbstractProgressBarRenderer.java
   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
   trunk/sandbox/ui/progressBAR/src/test/java/org/richfaces/sandbox/ProgressBarComponentTest.java
Log:
Implementing changes made in component spec.

Modified: trunk/sandbox/ui/progressBAR/src/main/config/component/progressBar.xml
===================================================================
--- trunk/sandbox/ui/progressBAR/src/main/config/component/progressBar.xml	2008-01-16 13:39:33 UTC (rev 5413)
+++ trunk/sandbox/ui/progressBAR/src/main/config/component/progressBar.xml	2008-01-16 13:50:02 UTC (rev 5414)
@@ -34,6 +34,23 @@
 			<description>Attributes defines AJAX or CLIENT modes for component</description>
 			<defaultvalue><![CDATA["ajax"]]></defaultvalue>
 		</property>
+		<property>
+			<name>minValue</name>
+			<classname>java.lang.Object</classname>
+			<description>Min value when initial state should be rendered</description>
+			<defaultvalue>0</defaultvalue>
+		</property>
+		<property>
+			<name>maxValue</name>
+			<classname>java.lang.Object</classname>
+			<description>Max value after whose complete state should be rendered</description>
+			<defaultvalue>100</defaultvalue>
+		</property>
+		<property>
+			<name>progressVar</name>
+			<classname>java.lang.String</classname>
+			<description>Attribute which should provide access to value of the component on the client</description>
+		</property>
 		<property>	
 			<name>styleClass</name>
 			<classname>java.lang.String</classname>
@@ -50,6 +67,16 @@
 			<description>CSS class that defines style for remained part of progress bar</description>
 		</property>
 		<property>
+			<name>initialClass</name>
+			<classname>java.lang.String</classname>
+			<description>CSS class that defines style for initial state of the component</description>
+		</property>
+		<property>
+			<name>finishClass</name>
+			<classname>java.lang.String</classname>
+			<description>CSS class that defines style for complete state of the component</description>
+		</property>
+		<property>
 			<name>determined</name>
 			<classname>boolean</classname>
 			<description>Attribute defines if component should render percent value</description>

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-01-16 13:39:33 UTC (rev 5413)
+++ trunk/sandbox/ui/progressBAR/src/main/java/org/richfaces/renderkit/AbstractProgressBarRenderer.java	2008-01-16 13:50:02 UTC (rev 5414)
@@ -12,6 +12,9 @@
 import java.util.Map;
 import java.util.Set;
 
+import javax.el.ELContext;
+import javax.el.ValueExpression;
+import javax.el.VariableMapper;
 import javax.faces.component.UIComponent;
 import javax.faces.context.FacesContext;
 import javax.faces.context.ResponseWriter;
@@ -26,6 +29,8 @@
 import org.ajax4jsf.renderkit.RendererUtils.HTML;
 import org.richfaces.component.UIProgressBar;
 
+import sun.management.counter.Variability;
+
 /**
  * Abstract progress bar renderer
  * 
@@ -84,37 +89,11 @@
 		    component.getClientId(context)).append("')");
 	}
 	script.append(";\n");
-	// script.append(getPercentValueScript(component));
 	writer.writeText(script.toString(), null);
 	writer.endElement(HTML.SCRIPT_ELEM);
 	writer.endElement(HTML.SPAN_ELEM);
     }
 
-    // private StringBuffer getPercentValueScript(UIComponent component)
-    // throws IOException {
-    // StringBuffer script = new StringBuffer();
-    // ComponentVariables variables = ComponentsVariableResolver.getVariables(
-    // this, component);
-    // String percent = getPercent(component);
-    // return script;
-    //
-    // }
-
-    // TODO do not encode content twice, use node cloning on client
-    // TODO provide client script with percent value
-    public String encodePersent(FacesContext context, UIComponent component)
-	    throws IOException {
-	Boolean determinedAttr = (Boolean) component.getAttributes().get(
-		"determined");
-	if (determinedAttr != null && determinedAttr.booleanValue()) {
-	    String percent = getPercent(component);
-	    if (percent != null) {
-		return percent + "%";
-	    }
-	}
-	return "";
-    }
-
     /**
      * Methods encodes start facet of progress bar component
      * 
@@ -129,8 +108,13 @@
 	    Object data) throws IOException {
 	Boolean isAjax = Boolean.parseBoolean((String) data);
 	String clientId = component.getClientId(context);
+	String initialClass = (String) component.getAttributes().get(
+		"initialClass");
+	String style = (String) component.getAttributes().get("style");
 	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, (isAjax ? clientId : clientId
 		+ ":initialState"), null);
 
@@ -145,6 +129,27 @@
 
     }
 
+    /**
+     * Sets up the progressVar page attribute
+     * @param context   - facesContext
+     * @param component - component instance
+     * @param value     - percent value 
+     */
+    public void setProgressVar(FacesContext context, UIComponent component,
+	    Object value) {
+	Number persent = getNumber(value);
+	String progresssVar = (String) component.getAttributes().get(
+		"progressVar");
+	Map attrs = context.getExternalContext().getRequestMap();
+	attrs.put(progresssVar, persent);
+    }
+
+    /**
+     * Encodes progress state of component
+     * @param context      - faces context
+     * @param component    - component instance
+     * @throws IOException 
+     */
     public void encodeProgressState(FacesContext context, UIComponent component)
 	    throws IOException {
 	ResponseWriter writer = context.getResponseWriter();
@@ -153,9 +158,11 @@
 		this, component);
 	Number value = (Number) variables.getVariable("percent");
 	String width = String.valueOf(value.intValue());
-	String percent = encodePersent(context, component);
 	String style = (String) component.getAttributes().get("style");
-	Boolean permanent = (Boolean) component.getAttributes().get("permanent");
+	Boolean permanent = (Boolean) component.getAttributes()
+		.get("permanent");
+	Boolean determined = (Boolean) component.getAttributes().get(
+		"determined");
 
 	if (!(permanent != null && permanent.booleanValue())) {
 
@@ -174,7 +181,9 @@
 	    getUtils().writeAttribute(writer, "id", clientId + ":remain");
 	    getUtils().writeAttribute(writer, "style", style);
 
-	    writer.write(percent);
+	    if (determined.booleanValue()) {
+		renderChildren(context, component);
+	    }
 
 	    writer.endElement("div");
 	    writer.startElement("div", component);
@@ -190,17 +199,24 @@
 	    getUtils().writeAttribute(writer, "id", clientId + ":complete");
 	    getUtils().writeAttribute(writer, "style", style);
 
-	    writer.write(percent);
+	    if (determined.booleanValue()) {
+		renderChildren(context, component);
+	    }
 
 	    writer.endElement("div");
 	    writer.endElement("div");
 	} else {
 	    writer.startElement("div", component);
-	    getUtils().writeAttribute(writer, "class","rich-progress-bar-permanent");
+	    getUtils().writeAttribute(writer, "class",
+		    "rich-progress-bar-permanent");
 	    getUtils().writeAttribute(writer, "style", style + " width: 100%");
 	    writer.endElement("div");
 	}
     }
+    
+    private void encodeChildrenComponents (FacesContext context, UIComponent component) {
+	
+    }
 
     /**
      * Methods encodes finish facet of progress bar component
@@ -232,11 +248,16 @@
 	String clientId = (isAjax) ? component.getClientId(context) : component
 		.getClientId(context)
 		+ ":completedState";
+	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);
+	getUtils().writeAttribute(writer, HTML.class_ATTRIBUTE, finishClass);
+	getUtils().writeAttribute(writer, "style", style);
 
-	UIComponent completed = component.getFacet("completed");
+	UIComponent completed = component.getFacet("complete");
 	if (completed != null) {
 	    renderChild(context, completed);
 	}
@@ -244,19 +265,25 @@
 
     }
 
-    private String getPercent(UIComponent component) {
-	ComponentVariables variables = ComponentsVariableResolver.getVariables(
-		this, component);
-	String result = "0";
-	Object percent = variables.getVariable("percent");
-	if (percent != null) {
+    /**
+     * Converts value attr to number value 
+     * @param v - value attr 
+     * @return result
+     */
+    public Number getNumber(Object v) {
+	Number result = new Integer(0);
+	if (v != null) {
 	    try {
-		Number n = (Number) percent;
-		if (n instanceof BigDecimal || n instanceof Double
-			|| n instanceof Float) {
-		    result = String.valueOf(n.floatValue());
-		} else if (n instanceof Integer) {
-		    result = String.valueOf(n.intValue());
+		if (v instanceof String) {
+		    result = Double.parseDouble((String) v);
+		} else {
+		    Number n = (Number) v;
+		    if (n instanceof BigDecimal || n instanceof Double
+			    || n instanceof Float) {
+			result = n.floatValue();
+		    } else if (n instanceof Integer) {
+			result = n.intValue();
+		    }
 		}
 	    } catch (Exception e) {
 		// TODO: handle exception
@@ -288,5 +315,23 @@
 	poll.setSubmitted(submitted);
 	return submitted;
     }
+    
+    
 
+    /* (non-Javadoc)
+     * @see javax.faces.render.Renderer#getRendersChildren()
+     */
+    @Override
+    public boolean getRendersChildren() {
+	return true;
+    }
+
+    /* (non-Javadoc)
+     * @see org.ajax4jsf.renderkit.AjaxCommandRendererBase#encodeChildren(javax.faces.context.FacesContext, javax.faces.component.UIComponent)
+     */
+    @Override
+    public void encodeChildren(FacesContext context, UIComponent component)
+	    throws IOException {
+	return;  // We don't need to render children ! 
+    }
 }

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-01-16 13:39:33 UTC (rev 5413)
+++ trunk/sandbox/ui/progressBAR/src/main/resources/org/richfaces/renderkit/html/js/progressBar.js	2008-01-16 13:50:02 UTC (rev 5414)
@@ -23,7 +23,8 @@
 			if (val.indexOf("%") < 0)
 				val = val + "%";
 		}
-		if (p > 100)  { this.switchMode("completed"); return; }
+		var max = $(this.id + ":max").value;
+		if ( parseFloat(p) >=  parseFloat(max))  { this.switchMode("completed"); return; }
 		
 		if ($(this.id + ":progressState") != null)
 		{

Modified: trunk/sandbox/ui/progressBAR/src/main/templates/org/richfaces/progressBar.jspx
===================================================================
--- trunk/sandbox/ui/progressBAR/src/main/templates/org/richfaces/progressBar.jspx	2008-01-16 13:39:33 UTC (rev 5413)
+++ trunk/sandbox/ui/progressBAR/src/main/templates/org/richfaces/progressBar.jspx	2008-01-16 13:50:02 UTC (rev 5414)
@@ -21,10 +21,10 @@
     if (!mode.equalsIgnoreCase("client") && !mode.equalsIgnoreCase("ajax")) {
     	throw new IOException("Mode attribute should have 'client' or 'ajax' value");
     }
+    Number minValue = getNumber(component.getAttributes().get("minValue"));
+    Number maxValue = getNumber(component.getAttributes().get("maxValue"));
     boolean isAjax = ("ajax".equalsIgnoreCase(mode));
-    Boolean enabled = (Boolean) component.getAttributes().get("enabled");
-    Number value = (Number)component.getAttributes().get("value");
-    Integer percent = value.intValue();
+    Number value = getNumber(component.getAttributes().get("value"));
     variables.setVariable("percent",value);
     variables.setVariable("style",(String)component.getAttributes().get("style"));
     variables.setVariable("styleClass",(String)component.getAttributes().get("styleClass"));
@@ -36,9 +36,10 @@
 	<jsp:scriptlet>
 <![CDATA[
 if (isAjax) {
-if (!enabled && percent == 0) { 
+setProgressVar(context, component, value);
+if (value.doubleValue() < minValue.doubleValue()) { 
     encodeInitialState(context, component, "true");
-} else if (!enabled && percent >= 100 ) {
+} else if (value.doubleValue() >= maxValue.doubleValue() ) {
     encodeCompletedState(context, component, "true");
 } else {
  ]]>
@@ -53,7 +54,7 @@
 }else {
 ]]>
 </jsp:scriptlet>
-<div id="#{clientId}">
+<div id="#{clientId}" style="#{style}">
 	<div id="#{clientId}:progressState" class="rich-progress-bar #{styleClass}" style="#{style}">
 		<f:call name="encodeProgressState" />
 	</div>
@@ -63,6 +64,8 @@
 	<f:call name="encodeCompletedState">
 		<f:parameter value="false"/>
 	</f:call>
+	<input type="hidden" id="#{clientId}:min" value="#{component.attributes['minValue']}" /> 
+	<input type="hidden" id="#{clientId}:max" value="#{component.attributes['maxValue']}" />
 	<script>
 		var pr = new ProgressBar('#{clientId}');
 		pr.init();

Modified: trunk/sandbox/ui/progressBAR/src/test/java/org/richfaces/sandbox/ProgressBarComponentTest.java
===================================================================
--- trunk/sandbox/ui/progressBAR/src/test/java/org/richfaces/sandbox/ProgressBarComponentTest.java	2008-01-16 13:39:33 UTC (rev 5413)
+++ trunk/sandbox/ui/progressBAR/src/test/java/org/richfaces/sandbox/ProgressBarComponentTest.java	2008-01-16 13:50:02 UTC (rev 5414)
@@ -1,14 +1,18 @@
 package org.richfaces.sandbox;
 
+import javax.el.ValueExpression;
 import javax.faces.component.UIForm;
+import javax.faces.component.UIOutput;
 import javax.faces.component.html.HtmlForm;
 
 import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
+import org.ajax4jsf.tests.MockValueExpression;
 import org.richfaces.component.UIProgressBar;
 
 import com.gargoylesoftware.htmlunit.html.DomText;
 import com.gargoylesoftware.htmlunit.html.HtmlElement;
 import com.gargoylesoftware.htmlunit.html.HtmlPage;
+import com.sun.corba.se.spi.legacy.connection.GetEndPointInfoAgainException;
 
 /**
  * Unit test for Progress bar component.
@@ -20,6 +24,9 @@
 
     /** Progress bar component */
     private UIProgressBar progressBar = null;
+    
+    /** Child component for progres bar  */
+    private UIOutput output = null;
 
     /**
      * TODO Description goes here.
@@ -49,7 +56,16 @@
 	progressBar.setId("prgs");
 	progressBar.setValue(50);
 	progressBar.setInterval(1000);
+	progressBar.getAttributes().put("progressVar", "persent");
 	
+	MockValueExpression expression = new MockValueExpression("50%");
+	ValueExpression exp = application.getExpressionFactory()
+		.createValueExpression(facesContext.getELContext(), "#{persent}", Object.class);
+	output = (UIOutput)application.createComponent("javax.faces.Output");
+	output.setValueExpression("value", expression);
+	
+	progressBar.getChildren().add(output);
+	
 	form.getChildren().add(progressBar);
 
     }




More information about the richfaces-svn-commits mailing list