Author: andrei_exadel
Date: 2008-02-19 06:43:43 -0500 (Tue, 19 Feb 2008)
New Revision: 6156
Modified:
trunk/ui/progressBAR/src/main/config/component/progressBar.xml
trunk/ui/progressBAR/src/main/java/org/richfaces/component/UIProgressBar.java
trunk/ui/progressBAR/src/main/java/org/richfaces/renderkit/AbstractProgressBarRenderer.java
trunk/ui/progressBAR/src/main/resources/org/richfaces/renderkit/html/js/progressBar.js
trunk/ui/progressBAR/src/main/templates/org/richfaces/progressBar.jspx
Log:
RF-2270, RF-2283, RF-2290, RF-2291
Modified: trunk/ui/progressBAR/src/main/config/component/progressBar.xml
===================================================================
--- trunk/ui/progressBAR/src/main/config/component/progressBar.xml 2008-02-19 11:42:38 UTC
(rev 6155)
+++ trunk/ui/progressBAR/src/main/config/component/progressBar.xml 2008-02-19 11:43:43 UTC
(rev 6156)
@@ -41,6 +41,11 @@
<description>Parameters for macrosubstitution in label</description>
</property>
<property>
+ <name>label</name>
+ <classname>java.lang.String</classname>
+ <description>Attribute defines simple label instead of children component
rendering</description>
+ </property>
+ <property>
<name>dualColoredLabel</name>
<classname>java.lang.Boolean</classname>
<description>Defines if component renderes as simple markup</description>
@@ -142,6 +147,14 @@
but just allows to avoid unnecessary updates on the client side if the response isn't
actual now
</description>
</property>
+ <property hidden="true">
+ <name>lang</name>
+ <classname>java.lang.String</classname>
+ <description>
+ Code describing the language used in the generated
+ markup for this component
+ </description>
+ </property>
</component>
</components>
Modified: trunk/ui/progressBAR/src/main/java/org/richfaces/component/UIProgressBar.java
===================================================================
---
trunk/ui/progressBAR/src/main/java/org/richfaces/component/UIProgressBar.java 2008-02-19
11:42:38 UTC (rev 6155)
+++
trunk/ui/progressBAR/src/main/java/org/richfaces/component/UIProgressBar.java 2008-02-19
11:43:43 UTC (rev 6156)
@@ -22,6 +22,7 @@
import org.ajax4jsf.context.AjaxContextImpl;
import org.ajax4jsf.event.AjaxEvent;
import org.ajax4jsf.javascript.JSLiteral;
+import org.ajax4jsf.javascript.ScriptUtils;
import org.ajax4jsf.renderkit.AjaxRendererUtils;
import org.richfaces.renderkit.AbstractProgressBarRenderer;
@@ -59,9 +60,9 @@
Map params = request.getParameterMap();
if (!params.containsKey(FORCE_PERCENT_PARAM)
&& params.containsKey(PERCENT_PARAM)) {
- Number percent = getNumber(this.getAttributes().get("value"));
+ Number value = getNumber(this.getAttributes().get("value"));
ajaxContext.removeRenderedArea(this.getClientId(facesContext));
- ajaxContext.setResponseData(getResponseData(percent,
+ ajaxContext.setResponseData(getResponseData(value,
facesContext));
Object reRender = this.getAttributes().get(
@@ -89,14 +90,14 @@
* @param percent
* @return
*/
- private Map<Object, Object> getResponseData(Number percent,
+ private Map<Object, Object> getResponseData(Number value,
FacesContext facesContext) {
AbstractProgressBarRenderer renderer = (AbstractProgressBarRenderer) this
.getRenderer(facesContext);
Map<Object, Object> map = new HashMap<Object, Object>();
- map.put("percent", percent);
+ map.put("value", value);
map.put("interval", this.getInterval());
if (this.getAttributes().get("style") != null) {
@@ -106,9 +107,9 @@
boolean enabled = (Boolean) this.getAttributes().get("enabled");
map.put("enabled", Boolean.toString(enabled));
- if (!isSimple()) {
+ if (!isSimple(renderer)) {
map.put("markup", getMarkup(facesContext, renderer));
- map.put("context", getContext(renderer, percent));
+ map.put("context", getContext(renderer, value));
}
addStyles2Responce(map, "completeClass", this.getAttributes().get(
@@ -130,10 +131,10 @@
private JSLiteral getContext(AbstractProgressBarRenderer renderer,
Number percent) {
StringBuffer buffer = new StringBuffer("{");
- buffer.append("value:").append(percent.toString()).append(",");
- buffer.append("minValue:").append(this.getAttributes().get("minValue"))
+ buffer.append("value:").append(ScriptUtils.toScript(percent.toString())).append(",");
+ buffer.append("minValue:").append(ScriptUtils.toScript(this.getAttributes().get("minValue").toString()))
.append(",");
- buffer.append("maxValue:").append(this.getAttributes().get("maxValue"));
+ buffer.append("maxValue:").append(ScriptUtils.toScript(this.getAttributes().get("maxValue").toString()));
String parameters = renderer.getParameters(this);
if (parameters != null) {
@@ -148,8 +149,8 @@
* Return true if markup is simple
* @return
*/
- private boolean isSimple() {
- return this.getChildCount() == 0;
+ private boolean isSimple(AbstractProgressBarRenderer renderer) {
+ return renderer.isSimpleMarkup(this);
}
/**
Modified:
trunk/ui/progressBAR/src/main/java/org/richfaces/renderkit/AbstractProgressBarRenderer.java
===================================================================
---
trunk/ui/progressBAR/src/main/java/org/richfaces/renderkit/AbstractProgressBarRenderer.java 2008-02-19
11:42:38 UTC (rev 6155)
+++
trunk/ui/progressBAR/src/main/java/org/richfaces/renderkit/AbstractProgressBarRenderer.java 2008-02-19
11:43:43 UTC (rev 6156)
@@ -102,26 +102,33 @@
public StringBuffer getMarkup(FacesContext context, UIComponent component) {
StringBuffer result = null;
CountingOutputWriter customWriter = new CountingOutputWriter();
- ResponseWriter writer = context.getResponseWriter();
try {
+ if (hasChildren(component)) {
+ ResponseWriter writer = context.getResponseWriter();
- String defaultRenderKitId = context.getApplication()
- .getDefaultRenderKitId();
- if (null == defaultRenderKitId) {
- defaultRenderKitId = RenderKitFactory.HTML_BASIC_RENDER_KIT;
- }
- RenderKitFactory renderKitFactory = (RenderKitFactory) FactoryFinder
- .getFactory(FactoryFinder.RENDER_KIT_FACTORY);
- RenderKit renderKit = renderKitFactory.getRenderKit(context,
- defaultRenderKitId);
+ String defaultRenderKitId = context.getApplication()
+ .getDefaultRenderKitId();
+ if (null == defaultRenderKitId) {
+ defaultRenderKitId = RenderKitFactory.HTML_BASIC_RENDER_KIT;
+ }
+ RenderKitFactory renderKitFactory = (RenderKitFactory) FactoryFinder
+ .getFactory(FactoryFinder.RENDER_KIT_FACTORY);
+ RenderKit renderKit = renderKitFactory.getRenderKit(context,
+ defaultRenderKitId);
- ResponseWriter responseWriter = renderKit.createResponseWriter(
- customWriter, null, "UTF-8");
- context.setResponseWriter(responseWriter);
- writeScriptBody(context, component, true);
- result = customWriter.getContent();
- if (writer != null) {
- context.setResponseWriter(writer);
+ ResponseWriter responseWriter = renderKit.createResponseWriter(
+ customWriter, null, "UTF-8");
+ context.setResponseWriter(responseWriter);
+ writeScriptBody(context, component, true);
+ result = customWriter.getContent();
+ if (writer != null) {
+ context.setResponseWriter(writer);
+ }
+
+ } else {
+ writeScriptBody(customWriter, (String) component
+ .getAttributes().get("label"));
+ result = customWriter.getContent();
}
} catch (Exception e) {
e.getMessage();
@@ -222,7 +229,7 @@
String mode = (String) component.getAttributes().get("mode");
Number minValue = getNumber(component.getAttributes().get("minValue"));
Number maxValue = getNumber(component.getAttributes().get("maxValue"));
- Number value = (Number)variables.getVariable("percent");
+ Number value =(Number)variables.getVariable("value");
StringBuffer markup = getMarkup(context, component);
script.append("new ProgressBar('")
@@ -250,7 +257,7 @@
script.append(state);
script.append("',");
script.append(value.toString());
- script.append(");\n");
+ script.append(")\n;");
writer.write(script.toString());
}
@@ -268,6 +275,9 @@
Integer interval = new Integer(progressBar.getInterval());
options.put("pollId", clientId);
options.put("pollinterval", interval);
+ if (progressBar.getAttributes().containsKey("ignoreDupResponses")) {
+ options.put("ignoreDupResponses",
progressBar.getAttributes().get("ignoreDupResponses"));
+ }
Map parameters = (Map) options.get("parameters");
parameters.put("percent", "percent");
// options.put("onbeforedomupdate", getOnComplete(clientId, progressBar,
@@ -398,6 +408,7 @@
String clientId = component.getClientId(context);
ComponentVariables variables = ComponentsVariableResolver.getVariables(
this, component);
+
Number value = (Number) variables.getVariable("percent");
String width = String.valueOf(value.intValue());
@@ -506,12 +517,28 @@
}
/**
+ * Return true if component has children components
+ * @param component
+ * @return
+ */
+ private boolean hasChildren (UIComponent component) {
+ return (component.getChildCount() != 0);
+ }
+
+ /**
* Returns true if markup should rendered as simple 2 divs
* @param component
* @return
*/
- private boolean isSimpleMarkup(UIComponent component) {
- return (component.getChildCount() == 0);
+ public boolean isSimpleMarkup(UIComponent component) {
+ if (hasChildren(component)) {
+ return false;
+ } else {
+ if (component.getAttributes().get("label") != null) {
+ return false;
+ }
+ }
+ return true;
}
/**
@@ -592,6 +619,21 @@
}
return result;
}
+
+ /**
+ * Calculates percent value according to min & max value
+ * @param value
+ * @param minValue
+ * @param maxValue
+ * @return
+ */
+ public Number calculatePercent(Number value, Number minValue, Number maxValue) {
+ if (minValue.doubleValue() < value.doubleValue() && value.doubleValue() <
maxValue.doubleValue()) {
+ return (Number)( (value.doubleValue() - minValue.doubleValue()) *
100.0/(maxValue.doubleValue() - minValue.doubleValue()));
+ } else {
+ return value;
+ }
+ }
/**
* Returns JS script to stop polling
Modified:
trunk/ui/progressBAR/src/main/resources/org/richfaces/renderkit/html/js/progressBar.js
===================================================================
---
trunk/ui/progressBAR/src/main/resources/org/richfaces/renderkit/html/js/progressBar.js 2008-02-19
11:42:38 UTC (rev 6155)
+++
trunk/ui/progressBAR/src/main/resources/org/richfaces/renderkit/html/js/progressBar.js 2008-02-19
11:43:43 UTC (rev 6156)
@@ -31,7 +31,7 @@
onComplete: function (data) {
if (!$(this.id) || this.disabled) { return; }
if (data) {
- this.value = data['percent'];
+ this.value = data['value'];
if (this.state == "progressState") {
if (this.value > this.getMaxValue()) {
this.forceState("complete",null);
@@ -61,7 +61,7 @@
},
updateComponent: function (data) {
this.updateStyle(data['style']);
- this.setValue(data['percent']);
+ this.setValue(this.value);
if (!data['enabled']) { this.disable(); }
this.updateClassName($(this.id + ":complete"),
data['completeClass']);
this.updateClassName($(this.id + ":remain"), data['remainClass']);
@@ -96,8 +96,8 @@
getContext: function () {
var context = this.context;
if (!context) { context = {}; }
- context['minValue'] = this.minValue;
- context['maxValue'] = this.maxValue;
+ context['minValue'] = (this.minValue == 0 ? "0" : this.minValue);
+ context['maxValue'] = (this.maxValue == 0 ? "0" : this.maxValue);
context['value'] = (this.value == 0 ? "0" : this.value);
if (this.progressVar) {
context[this.progressVar] = context['value'];
@@ -143,19 +143,21 @@
isAjaxMode: function () {
return (this.getMode() == "ajax");
},
+ calculatePercent: function(v) {
+ var min = parseFloat(this.getMinValue());
+ var max = parseFloat(this.getMaxValue());
+ var value = parseFloat(v);
+ if (value > min && value < max) {
+ return (100*(value - min))/(max - min);
+ }
+ return value;
+ },
setValue: function (val) {
this.value = val;
- var p = val;
- val = "" + val;
- if (val != null) {
- if (val.indexOf("%") < 0)
- val = val + "%";
- }
-
if (!this.isAjaxMode()) {
- if ( parseFloat(p) <= parseFloat(this.getMinValue())) {
+ if (parseFloat(val) <= parseFloat(this.getMinValue())) {
this.switchState("initialState");
- }else if ( parseFloat(p) > parseFloat(this.getMaxValue())) {
+ }else if (parseFloat(val) > parseFloat(this.getMaxValue())) {
this.switchState("completeState");
}else {
this.switchState("progressState");
@@ -168,15 +170,16 @@
} else {
//this.setLabel("{value}%");
}
-
+
+ var p = this.calculatePercent(val);
var d = $(this.id + ":upload");
- if (d != null) d.style.width = val;
+ if (d != null) d.style.width = (p + "%");
},
enable: function (ev) {
if (!this.isAjaxMode()) {
this.switchState("progressState");
- this.setValue(0);
+ this.setValue(this.getMinValue() + 1);
}else {
this.disable();
this.poll();
@@ -188,7 +191,12 @@
A4J.AJAX.StopPoll(this.id);
},
finish: function () {
- //this.switchMode("completed");
+ if (!this.isAjaxMode()) {
+ this.switchState("completeState");
+ }else {
+ this.disable();
+ this.forceState("complete");
+ }
},
hideAll: function () {
Element.hide($(this.id + ":progressState"));
Modified: trunk/ui/progressBAR/src/main/templates/org/richfaces/progressBar.jspx
===================================================================
--- trunk/ui/progressBAR/src/main/templates/org/richfaces/progressBar.jspx 2008-02-19
11:42:38 UTC (rev 6155)
+++ trunk/ui/progressBAR/src/main/templates/org/richfaces/progressBar.jspx 2008-02-19
11:43:43 UTC (rev 6156)
@@ -21,14 +21,16 @@
<jsp:scriptlet>
<![CDATA[
String mode = (String) component.getAttributes().get("mode");
+ boolean isAjax = ("ajax".equalsIgnoreCase(mode));
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));
Number value = getNumber(component.getAttributes().get("value"));
- variables.setVariable("percent",value);
+ Number percent = calculatePercent(value,minValue, maxValue);
+ variables.setVariable("percent",percent);
+ variables.setVariable("value",value);
variables.setVariable("style",(String)component.getAttributes().get("style"));
variables.setVariable("styleClass",(String)component.getAttributes().get("styleClass"));
String forcedState = getForcedState(context,component);