[richfaces-svn-commits] JBoss Rich Faces SVN: r5009 - in trunk/sandbox/ui: progressBar and 12 other directories.

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Wed Dec 26 11:12:54 EST 2007


Author: andrei_exadel
Date: 2007-12-26 11:12:54 -0500 (Wed, 26 Dec 2007)
New Revision: 5009

Added:
   trunk/sandbox/ui/progressBar/
   trunk/sandbox/ui/progressBar/pom.xml
   trunk/sandbox/ui/progressBar/src/
   trunk/sandbox/ui/progressBar/src/main/
   trunk/sandbox/ui/progressBar/src/main/java/
   trunk/sandbox/ui/progressBar/src/main/java/org/
   trunk/sandbox/ui/progressBar/src/main/java/org/richfaces/
   trunk/sandbox/ui/progressBar/src/main/java/org/richfaces/component/
   trunk/sandbox/ui/progressBar/src/main/java/org/richfaces/component/UIProgressBar.java
   trunk/sandbox/ui/progressBar/src/main/java/org/richfaces/renderkit/
   trunk/sandbox/ui/progressBar/src/main/java/org/richfaces/renderkit/AbstractProgressBarRenderer.java
   trunk/sandbox/ui/progressBar/src/test/
   trunk/sandbox/ui/progressBar/src/test/java/
   trunk/sandbox/ui/progressBar/src/test/java/org/
   trunk/sandbox/ui/progressBar/src/test/java/org/richfaces/
   trunk/sandbox/ui/progressBar/src/test/java/org/richfaces/sandbox/
   trunk/sandbox/ui/progressBar/src/test/java/org/richfaces/sandbox/ProgressBarComponentTest.java
Modified:
   trunk/sandbox/ui/pom.xml
Log:
RF-1686 (Progress Bar Component)

Modified: trunk/sandbox/ui/pom.xml
===================================================================
--- trunk/sandbox/ui/pom.xml	2007-12-26 15:25:59 UTC (rev 5008)
+++ trunk/sandbox/ui/pom.xml	2007-12-26 16:12:54 UTC (rev 5009)
@@ -22,5 +22,6 @@
     <!--module>contextMenu</module-->
     <module>fileUpload</module>
     <module>combobox</module>
+    <module>progressBar</module>
   </modules>
 </project>
\ No newline at end of file

Added: trunk/sandbox/ui/progressBar/pom.xml
===================================================================
--- trunk/sandbox/ui/progressBar/pom.xml	                        (rev 0)
+++ trunk/sandbox/ui/progressBar/pom.xml	2007-12-26 16:12:54 UTC (rev 5009)
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="UTF-8"?><project>
+  <parent>
+    <artifactId>ui</artifactId>
+    <groupId>org.richfaces.sandbox</groupId>
+    <version>3.2.0-SNAPSHOT</version>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.richfaces.sandbox.ui</groupId>
+  <artifactId>progressBar</artifactId>
+  <name>progressBar</name>
+  <version>3.2.0-SNAPSHOT</version>
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.richfaces.cdk</groupId>
+        <artifactId>maven-cdk-plugin</artifactId>
+        <version>3.2.0-SNAPSHOT</version>
+        <executions>
+          <execution>
+            <phase>generate-sources</phase>
+            <goals>
+              <goal>generate</goal>
+            </goals>
+          </execution>
+        </executions>
+        <configuration>
+          <library>
+            <prefix>org.richfaces.sandbox.ui</prefix>
+            <taglib>
+              <shortName>progressBar</shortName>
+            </taglib>
+          </library>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+  <dependencies>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>3.8.1</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.richfaces.framework</groupId>
+      <artifactId>richfaces-impl</artifactId>
+      <version>3.2.0-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>org.richfaces.ui</groupId>
+      <artifactId>core</artifactId>
+      <version>3.2.0-SNAPSHOT</version>
+    </dependency>
+  </dependencies>
+</project>
\ No newline at end of file

Added: trunk/sandbox/ui/progressBar/src/main/java/org/richfaces/component/UIProgressBar.java
===================================================================
--- trunk/sandbox/ui/progressBar/src/main/java/org/richfaces/component/UIProgressBar.java	                        (rev 0)
+++ trunk/sandbox/ui/progressBar/src/main/java/org/richfaces/component/UIProgressBar.java	2007-12-26 16:12:54 UTC (rev 5009)
@@ -0,0 +1,26 @@
+/*
+ * UIProgressBar.java		Date created: 19.12.2007
+ * Last modified by: $Author$
+ * $Revision$	$Date$
+ */
+
+package org.richfaces.component;
+
+import javax.faces.context.FacesContext;
+
+import org.ajax4jsf.component.UIPoll;
+import org.ajax4jsf.context.AjaxContext;
+
+/**
+ * TODO Class description goes here.
+ * 
+ * @author "Andrey Markavtsov"
+ * 
+ */
+public abstract class UIProgressBar extends UIPoll {
+
+    public static final String COMPONENT_TYPE = "org.richfaces.ProgressBar";
+
+    public static final String COMPONENT_FAMILY = "org.richfaces.ProgressBar";
+  
+}

Added: trunk/sandbox/ui/progressBar/src/main/java/org/richfaces/renderkit/AbstractProgressBarRenderer.java
===================================================================
--- trunk/sandbox/ui/progressBar/src/main/java/org/richfaces/renderkit/AbstractProgressBarRenderer.java	                        (rev 0)
+++ trunk/sandbox/ui/progressBar/src/main/java/org/richfaces/renderkit/AbstractProgressBarRenderer.java	2007-12-26 16:12:54 UTC (rev 5009)
@@ -0,0 +1,192 @@
+/*
+ * AbstractProgressBarRenderer.java		Date created: 20.12.2007
+ * Last modified by: $Author$
+ * $Revision$	$Date$
+ */
+
+package org.richfaces.renderkit;
+
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+
+import org.ajax4jsf.context.AjaxContext;
+import org.ajax4jsf.javascript.JSFunction;
+import org.ajax4jsf.javascript.JSFunctionDefinition;
+import org.ajax4jsf.renderkit.AjaxCommandRendererBase;
+import org.ajax4jsf.renderkit.AjaxRendererUtils;
+import org.ajax4jsf.renderkit.ComponentVariables;
+import org.ajax4jsf.renderkit.ComponentsVariableResolver;
+import org.ajax4jsf.renderkit.RendererUtils.HTML;
+import org.richfaces.component.UIProgressBar;
+
+/**
+ * Abstract progress bar renderer
+ * 
+ * @author "Andrey Markavtsov"
+ * 
+ */
+public class AbstractProgressBarRenderer extends AjaxCommandRendererBase {
+
+    /** AJAX polling function name */
+    private static final String AJAX_POLL_FUNCTION = "A4J.AJAX.Poll";
+
+    /**
+     * Methods encodes AJAX script for polling
+     * 
+     * @param context -
+     *                faces context
+     * @param component -
+     *                component instance
+     * @throws IOException -
+     *                 IOException
+     */
+    public void encodePollScript(FacesContext context, UIComponent component)
+	    throws IOException {
+
+	ResponseWriter writer = context.getResponseWriter();
+	UIProgressBar progressBar = (UIProgressBar) component;
+	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 script = new StringBuffer("\n");
+	if (progressBar.isEnabled()) {
+	    JSFunction function = AjaxRendererUtils.buildAjaxFunction( // encode
+		    // script
+		    // if
+		    // polling
+		    // enable
+		    component, context, AJAX_POLL_FUNCTION);
+	    Map options = AjaxRendererUtils.buildEventOptions(context,
+		    component);
+	    Integer interval = new Integer(progressBar.getInterval());
+	    options.put("pollinterval", interval);
+	    options.put("pollId", component.getClientId(context));
+	    Object onsubmit = component.getAttributes().get("onsubmit");
+	    if (null != onsubmit) {
+		JSFunctionDefinition onsubmitFunction = new JSFunctionDefinition();
+		onsubmitFunction.addToBody(onsubmit);
+		options.put("onsubmit", onsubmitFunction);
+	    }
+
+	    function.addParameter(options);
+	    function.appendScript(script);
+	} else {
+	    script.append("A4J.AJAX.StopPoll('").append(
+		    component.getClientId(context)).append("')");
+	}
+	script.append(";\n");
+	writer.writeText(script.toString(), null);
+	writer.endElement(HTML.SCRIPT_ELEM);
+	writer.endElement(HTML.SPAN_ELEM);
+    }
+
+    public void encodePersent(FacesContext context, UIComponent component)
+	    throws IOException {
+	ResponseWriter writer = context.getResponseWriter();
+	String determinedAttr = (String)component.getAttributes().get("determined");
+	if (determinedAttr != null && "true".equals(determinedAttr)) {
+	    ComponentVariables variables = ComponentsVariableResolver
+		    .getVariables(this, component);
+	    Integer percent = (Integer) variables.getVariable("percent");
+	    if (percent != null) {
+		writer.write(percent.toString() + "%");
+	    }
+	}
+
+    }
+
+    /**
+     * Methods encodes start facet of progress bar component
+     * 
+     * @param context -
+     *                faces context
+     * @param component -
+     *                component instance
+     * @throws IOException -
+     *                 IOException
+     */
+    public void encodeInitialState(FacesContext context, UIComponent component)
+	    throws IOException {
+	String clientId = component.getClientId(context);
+	ResponseWriter writer = context.getResponseWriter();
+	writer.startElement(HTML.DIV_ELEM, component);
+	writer.writeAttribute(HTML.id_ATTRIBUTE, clientId, null);
+	UIComponent initial = component.getFacet("initial");
+	if (initial != null) {
+	    renderChild(context, initial);
+	}
+	encodePollScript(context, component);
+	writer.endElement(HTML.DIV_ELEM);
+
+    }
+
+    /**
+     * Methods encodes finish facet of progress bar component
+     * 
+     * @param context -
+     *                faces context
+     * @param component -
+     *                component instance
+     * @throws IOException -
+     *                 IOException
+     */
+    public void encodeCompletedState(FacesContext context, UIComponent component)
+	    throws IOException {
+
+	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);
+	    }
+	}
+
+	String clientId = component.getClientId(context);
+	ResponseWriter writer = context.getResponseWriter();
+	writer.startElement(HTML.DIV_ELEM, component);
+	writer.writeAttribute(HTML.id_ATTRIBUTE, clientId, null);
+	UIComponent completed = component.getFacet("completed");
+	if (completed != null) {
+	    renderChild(context, completed);
+	}
+	writer.endElement(HTML.DIV_ELEM);
+
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.ajax4jsf.renderkit.RendererBase#getComponentClass()
+     */
+    protected Class getComponentClass() {
+	// only poll component is allowed.
+	return UIProgressBar.class;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.ajax4jsf.renderkit.AjaxCommandRendererBase#isSubmitted(javax.faces.context.FacesContext,
+     *      javax.faces.component.UIComponent)
+     */
+    protected boolean isSubmitted(FacesContext facesContext,
+	    UIComponent uiComponent) {
+	boolean submitted = super.isSubmitted(facesContext, uiComponent);
+	UIProgressBar poll = (UIProgressBar) uiComponent;
+	poll.setSubmitted(submitted);
+	return submitted;
+    }
+
+}

Added: trunk/sandbox/ui/progressBar/src/test/java/org/richfaces/sandbox/ProgressBarComponentTest.java
===================================================================
--- trunk/sandbox/ui/progressBar/src/test/java/org/richfaces/sandbox/ProgressBarComponentTest.java	                        (rev 0)
+++ trunk/sandbox/ui/progressBar/src/test/java/org/richfaces/sandbox/ProgressBarComponentTest.java	2007-12-26 16:12:54 UTC (rev 5009)
@@ -0,0 +1,102 @@
+package org.richfaces.sandbox;
+
+import javax.faces.component.UIForm;
+import javax.faces.component.html.HtmlForm;
+
+import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
+import org.richfaces.component.UIProgressBar;
+
+import com.gargoylesoftware.htmlunit.html.DomText;
+import com.gargoylesoftware.htmlunit.html.HtmlElement;
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
+
+/**
+ * Unit test for Progress bar component.
+ */
+public class ProgressBarComponentTest extends AbstractAjax4JsfTestCase {
+
+    /** Form component */
+    private UIForm form = null;
+
+    /** Progress bar component */
+    private UIProgressBar progressBar = null;
+
+    /**
+     * TODO Description goes here.
+     * 
+     * @param name
+     */
+    public ProgressBarComponentTest(String name) {
+	super(name);
+	// TODO Auto-generated constructor stub
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.ajax4jsf.tests.AbstractAjax4JsfTestCase#setUp()
+     */
+    @Override
+    public void setUp() throws Exception {
+	// TODO Auto-generated method stub
+	super.setUp();
+	form = new HtmlForm();
+	form.setId("form");
+	facesContext.getViewRoot().getChildren().add(form);
+
+	progressBar = (UIProgressBar) application
+		.createComponent("org.richfaces.ProgressBar");
+	progressBar.setId("prgs");
+	progressBar.setValue(50);
+	progressBar.setInterval(1000);
+	progressBar.getAttributes().put("determined", "true");
+
+	form.getChildren().add(progressBar);
+
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.ajax4jsf.tests.AbstractAjax4JsfTestCase#tearDown()
+     */
+    @Override
+    public void tearDown() throws Exception {
+	// TODO Auto-generated method stub
+	super.tearDown();
+    }
+
+    /**
+     * Method tests progress bar component
+     * @throws Exception
+     */
+    public void testProgressBar() throws Exception {
+	HtmlPage page = renderView();
+	assertNotNull(page);
+
+	HtmlElement progress = page.getHtmlElementById(progressBar
+		.getClientId(facesContext));
+	assertNotNull(progress);
+	assertEquals("div", progress.getNodeName());
+
+	String classAttr = progress.getAttributeValue("class");
+	assertTrue(classAttr.contains("rich-progress-bar"));
+	
+	HtmlElement node = (HtmlElement)progress.getFirstChild();
+	assertTrue(node.getAttributeValue("class").contains("rich-progress-bar-base"));
+	assertTrue("50%".equals(node.asText()));
+	
+	node = (HtmlElement) progress.getLastChild();
+	assertTrue("span".equalsIgnoreCase(node.getTagName()));
+	
+	node = (HtmlElement) node.getLastChild();
+	assertTrue("script".equalsIgnoreCase(node.getTagName()));
+	
+	DomText text = (DomText) node.getFirstChild();
+	assertTrue(text.getData().contains("A4J.AJAX.Poll"));
+	assertTrue(text.getData().contains("1000"));
+
+
+    }
+
+}




More information about the richfaces-svn-commits mailing list