Author: ilya_shaikovsky
Date: 2009-07-17 09:31:51 -0400 (Fri, 17 Jul 2009)
New Revision: 14949
Added:
branches/community/3.3.X/samples/richfaces-demo/src/main/java/org/richfaces/demo/datatable/Choice.java
branches/community/3.3.X/samples/richfaces-demo/src/main/java/org/richfaces/demo/datatable/ChoicesBean.java
branches/community/3.3.X/samples/richfaces-demo/src/main/java/org/richfaces/demo/layout/CustomizableLayout.java
branches/community/3.3.X/samples/richfaces-demo/src/main/webapp/richfaces/dataTable/choices.xhtml
branches/community/3.3.X/samples/richfaces-demo/src/main/webapp/richfaces/dataTable/examples/choices.xhtml
branches/community/3.3.X/samples/richfaces-demo/src/main/webapp/richfaces/layouts/page/coolTSemanticTemplate.xhtml
Modified:
branches/community/3.3.X/samples/richfaces-demo/src/main/webapp/richfaces/dataTable.xhtml
Log:
new push sample
Added:
branches/community/3.3.X/samples/richfaces-demo/src/main/java/org/richfaces/demo/datatable/Choice.java
===================================================================
---
branches/community/3.3.X/samples/richfaces-demo/src/main/java/org/richfaces/demo/datatable/Choice.java
(rev 0)
+++
branches/community/3.3.X/samples/richfaces-demo/src/main/java/org/richfaces/demo/datatable/Choice.java 2009-07-17
13:31:51 UTC (rev 14949)
@@ -0,0 +1,29 @@
+package org.richfaces.demo.datatable;
+
+public class Choice {
+ private String label;
+ private int votesCount;
+
+ public Choice(String label) {
+ this.label = label;
+ this.votesCount = 0;
+ }
+
+ public void increment(int i) {
+ this.votesCount+=i;
+ }
+
+ public String getLabel() {
+ return label;
+ }
+ public void setLabel(String label) {
+ this.label = label;
+ }
+ public int getVotesCount() {
+ return votesCount;
+ }
+ public void setVotesCount(int votesCount) {
+ this.votesCount = votesCount;
+ }
+
+}
Added:
branches/community/3.3.X/samples/richfaces-demo/src/main/java/org/richfaces/demo/datatable/ChoicesBean.java
===================================================================
---
branches/community/3.3.X/samples/richfaces-demo/src/main/java/org/richfaces/demo/datatable/ChoicesBean.java
(rev 0)
+++
branches/community/3.3.X/samples/richfaces-demo/src/main/java/org/richfaces/demo/datatable/ChoicesBean.java 2009-07-17
13:31:51 UTC (rev 14949)
@@ -0,0 +1,156 @@
+package org.richfaces.demo.datatable;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.EventListener;
+import java.util.EventObject;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.ThreadPoolExecutor;
+
+import org.ajax4jsf.event.PushEventListener;
+import org.jboss.seam.ScopeType;
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.Scope;
+import org.richfaces.datatablescroller.DataTableScrollerBean;
+
+@Name("choicesBean")
+(a)Scope(ScopeType.SESSION)
+public class ChoicesBean implements Runnable {
+ private List<Choice> choices;
+ private List<Choice> lastVotes;
+ private Set<Integer> keysSet;
+ private Thread thread;
+ private boolean enabled = false;
+ private Date startDate;
+ private String updateInfo;
+ PushEventListener listener;
+
+ public ChoicesBean() {
+ keysSet = new HashSet<Integer>();
+ choices = new ArrayList<Choice>();
+ lastVotes = new ArrayList<Choice>();
+
+ choices.add(new Choice("Orange"));
+ choices.add(new Choice("Pineapple"));
+ choices.add(new Choice("Banana"));
+ choices.add(new Choice("Kiwifruit"));
+ choices.add(new Choice("Apple"));
+
+ lastVotes.add(new Choice("Orange"));
+ lastVotes.add(new Choice("Pineapple"));
+ lastVotes.add(new Choice("Banana"));
+ lastVotes.add(new Choice("Kiwifruit"));
+ lastVotes.add(new Choice("Apple"));
+ }
+
+ public List<Choice> getChoices() {
+ return choices;
+ }
+
+ public void setChoices(List<Choice> choices) {
+ this.choices = choices;
+ }
+
+ public Set<Integer> getKeysSet() {
+ return keysSet;
+ }
+
+ public void setKeysSet(Set<Integer> keysSet) {
+ this.keysSet = keysSet;
+ }
+
+ public void addListener(EventListener listener) {
+ if (this.listener != listener) {
+ this.listener = (PushEventListener) listener;
+ }
+ }
+
+ public String getTimeStamp() {
+ return new Date().toGMTString();
+ }
+
+ public synchronized void start() {
+ if (thread == null) {
+ thread = new Thread(this);
+ thread.setDaemon(true);
+ thread.start();
+ setStartDate(new Date());
+ setEnabled(true);
+ }
+ }
+
+ public synchronized void stop() {
+ if (thread != null) {
+ // thread.stop();
+ setStartDate(null);
+ setEnabled(false);
+ thread = null;
+ }
+ }
+
+ public void run() {
+ while (thread != null) {
+ try {
+ if (((new Date()).getTime() - startDate.getTime()) >= 60000) {
+ stop();
+ }
+ // changing votes count
+ for (Choice choice : lastVotes) {
+ choice.setVotesCount(DataTableScrollerBean.rand(0, 3));
+ }
+ listener.onEvent(new EventObject(this));
+ Thread.sleep(10000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ public void processUpdates() {
+ Set<Integer> keysForUpdate = new HashSet<Integer>();
+ for (Choice choice : lastVotes) {
+ if (choice.getVotesCount() > 0) {
+ int index = lastVotes.indexOf(choice);
+ keysForUpdate.add(index);
+ choices.get(index).increment(choice.getVotesCount());
+ }
+ }
+ updateInfo="[ ";
+ for (Choice choice : lastVotes) {
+ updateInfo+=choice.getVotesCount()+" ";
+ }
+ updateInfo+="] ";
+ keysSet = keysForUpdate;
+ }
+
+ public Thread getThread() {
+ return thread;
+ }
+
+ public boolean isEnabled() {
+ return enabled;
+ }
+
+ public void setEnabled(boolean enabled) {
+ this.enabled = enabled;
+ }
+
+ public Date getStartDate() {
+ return startDate;
+ }
+
+ public void setStartDate(Date startDate) {
+ this.startDate = startDate;
+ }
+
+ public String getUpdateInfo() {
+ return updateInfo;
+ }
+
+ public List<Choice> getLastVotes() {
+ return lastVotes;
+ }
+
+}
Added:
branches/community/3.3.X/samples/richfaces-demo/src/main/java/org/richfaces/demo/layout/CustomizableLayout.java
===================================================================
---
branches/community/3.3.X/samples/richfaces-demo/src/main/java/org/richfaces/demo/layout/CustomizableLayout.java
(rev 0)
+++
branches/community/3.3.X/samples/richfaces-demo/src/main/java/org/richfaces/demo/layout/CustomizableLayout.java 2009-07-17
13:31:51 UTC (rev 14949)
@@ -0,0 +1,5 @@
+package org.richfaces.demo.layout;
+
+public class CustomizableLayout {
+
+}
Added:
branches/community/3.3.X/samples/richfaces-demo/src/main/webapp/richfaces/dataTable/choices.xhtml
===================================================================
---
branches/community/3.3.X/samples/richfaces-demo/src/main/webapp/richfaces/dataTable/choices.xhtml
(rev 0)
+++
branches/community/3.3.X/samples/richfaces-demo/src/main/webapp/richfaces/dataTable/choices.xhtml 2009-07-17
13:31:51 UTC (rev 14949)
@@ -0,0 +1,34 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html
xmlns="http://www.w3.org/1999/xhtml"
+
xmlns:ui="http://java.sun.com/jsf/facelets"
+
xmlns:h="http://java.sun.com/jsf/html"
+
xmlns:f="http://java.sun.com/jsf/core"
+
xmlns:a4j="http://richfaces.org/a4j"
+
xmlns:rich="http://richfaces.org/rich">
+ <ui:composition template="/templates/component-sample.xhtml">
+ <ui:define name="sample">
+ <p>
+Desc </p>
+ <fieldset class="demo_fieldset">
+ <legend class="demo_legend">Table cells updates</legend>
+ <div class="sample-container">
+ <ui:include src="/richfaces/dataTable/examples/choices.xhtml"/>
+ <ui:include src="/templates/include/sourceview.xhtml">
+ <ui:param name="sourcepath"
value="/richfaces/dataTable/examples/choices.xhtml"/>
+ </ui:include>
+ <ui:include src="/templates/include/sourceview.xhtml">
+ <ui:param name="sourcetype" value="java" />
+ <ui:param name="openlabel" value="Choice Object" />
+ <ui:param name="sourcepath"
value="/richfaces/dataTable/snippets/Choice.java"/>
+ </ui:include>
+ <ui:include src="/templates/include/sourceview.xhtml">
+ <ui:param name="sourcetype" value="java" />
+ <ui:param name="openlabel" value="Choices Bean" />
+ <ui:param name="sourcepath"
value="/richfaces/dataTable/snippets/ChoicesBean.java"/>
+ </ui:include>
+ </div>
+ </fieldset>
+ </ui:define>
+
+ </ui:composition>
+</html>
Added:
branches/community/3.3.X/samples/richfaces-demo/src/main/webapp/richfaces/dataTable/examples/choices.xhtml
===================================================================
---
branches/community/3.3.X/samples/richfaces-demo/src/main/webapp/richfaces/dataTable/examples/choices.xhtml
(rev 0)
+++
branches/community/3.3.X/samples/richfaces-demo/src/main/webapp/richfaces/dataTable/examples/choices.xhtml 2009-07-17
13:31:51 UTC (rev 14949)
@@ -0,0 +1,55 @@
+<ui:composition
xmlns="http://www.w3.org/1999/xhtml"
+
xmlns:ui="http://java.sun.com/jsf/facelets"
+
xmlns:h="http://java.sun.com/jsf/html"
+
xmlns:f="http://java.sun.com/jsf/core"
+
xmlns:a4j="http://richfaces.org/a4j"
+
xmlns:rich="http://richfaces.org/rich">
+ <style>
+.top {
+ vertical-align: top;
+}
+</style>
+ <h:form>
+ <rich:dataTable value="#{choicesBean.choices}" var="choice"
+ rowKeyVar="row" ajaxKeys="#{choicesBean.keysSet}">
+ <f:facet name="header">
+ <h:outputText value="Voting for favourite fruit" />
+ </f:facet>
+ <rich:column>
+ <f:facet name="header">
+ <h:outputText value="" />
+ </f:facet>
+ <h:outputText value="#{row}" />
+ </rich:column>
+ <rich:column>
+ <f:facet name="header">
+ <h:outputText value="Choice name" />
+ </f:facet>
+ <h:outputText value="#{choice.label}" id="choiceLabel" />
+ </rich:column>
+ <rich:column>
+ <f:facet name="header">
+ <h:outputText value="Current Votes" />
+ </f:facet>
+ <h:outputText value="#{choice.votesCount}" id="choiceVotes"
/>
+ </rich:column>
+ </rich:dataTable>
+ <a4j:commandButton value="Start" action="#{choicesBean.start}"
+ id="start" disabled="#{choicesBean.enabled}"
ajaxSingle="true"
+ reRender="push, stop, start" limitToList="true" />
+
+ <a4j:commandButton value="Stop" action="#{choicesBean.stop}"
id="stop"
+ disabled="#{!choicesBean.enabled}" ajaxSingle="true"
+ reRender="push,start, stop" limitToList="true" />
+ <a4j:outputPanel layout="block" id="tempResults">
+ <h:outputText
+ value="Latest update votes was: #{choicesBean.updateInfo} at
#{choicesBean.timeStamp}"
+ rendered="#{choicesBean.enabled}" />
+ </a4j:outputPanel>
+
+ <a4j:push enabled="#{choicesBean.enabled}" interval="3000"
+ timeout="3000" eventProducer="#{choicesBean.addListener}"
id="push"
+ limitToList="true" action="#{choicesBean.processUpdates}"
+ reRender="choiceVotes, push, tempResults" />
+ </h:form>
+</ui:composition>
\ No newline at end of file
Modified:
branches/community/3.3.X/samples/richfaces-demo/src/main/webapp/richfaces/dataTable.xhtml
===================================================================
---
branches/community/3.3.X/samples/richfaces-demo/src/main/webapp/richfaces/dataTable.xhtml 2009-07-17
13:31:31 UTC (rev 14948)
+++
branches/community/3.3.X/samples/richfaces-demo/src/main/webapp/richfaces/dataTable.xhtml 2009-07-17
13:31:51 UTC (rev 14949)
@@ -21,6 +21,9 @@
<rich:tab label="Edit Table with ModalPanel"
name="editDataTable">
<ui:include src="/richfaces/dataTable/editDataTable.xhtml"/>
</rich:tab>
+ <rich:tab label="Push and Table cells updates"
name="choices">
+ <ui:include src="/richfaces/dataTable/choices.xhtml"/>
+ </rich:tab>
<rich:tab name="info" label="Tag Information">
<rich:insert
src="/WEB-INF/#{componentNavigator.currentComponent.tagInfoLocation}"
Added:
branches/community/3.3.X/samples/richfaces-demo/src/main/webapp/richfaces/layouts/page/coolTSemanticTemplate.xhtml
===================================================================
---
branches/community/3.3.X/samples/richfaces-demo/src/main/webapp/richfaces/layouts/page/coolTSemanticTemplate.xhtml
(rev 0)
+++
branches/community/3.3.X/samples/richfaces-demo/src/main/webapp/richfaces/layouts/page/coolTSemanticTemplate.xhtml 2009-07-17
13:31:51 UTC (rev 14949)
@@ -0,0 +1,54 @@
+<rich:page
xmlns="http://www.w3.org/1999/xhtml"
+
xmlns:ui="http://java.sun.com/jsf/facelets"
+
xmlns:h="http://java.sun.com/jsf/html"
+
xmlns:f="http://java.sun.com/jsf/core"
+
xmlns:rich="http://richfaces.org/rich"
+
xmlns:a4j="http://richfaces.org/a4j" markupType="xhtml"
+ contentType="text/html" theme="#{layoutBean.theme}"
+ width="#{layoutBean.width}"
sidebarWidth="#{layoutBean.sidebarWidth}"
+ sidebarPosition="#{layoutBean.position}">
+ <f:facet name="sidebar">
+ <ui:include src="/richfaces/layouts/page/includes/sidebar.xhtml" />
+ </f:facet>
+ <f:facet name="header">
+ <h:panelGroup>
+ <table width="100%"><tbody><tr>
+ <td><h2>RichFaces Layouts</h2></td>
+ <td align="right">
+ <h:outputLink
value="http://labs.jboss.com/portal/jbossrichfaces/downloads"&g...;
+ <h:outputLink
value="http://jboss.com/index.html?module=bb&op=viewforum&am...;
+ <h:outputLink
value="http://labs.jboss.com/file-access/default/members/jbossrichfa...
Guide</h:outputLink>
+ </td>
+ </tr></tbody></table>
+ </h:panelGroup>
+ </f:facet>
+ <f:facet name="footer">
+ <h:outputText
+ value="Copyright (c) 2009 RichFaces. All rights reserved. RichFaces version
#{environment.version}" />
+ </f:facet>
+ <rich:tabPanel switchType="client">
+ <rich:tab label="overview">
+ <rich:layout>
+ <rich:layoutPanel position="top" width="100%">
+ <ui:include src="/richfaces/layouts/page/includes/gridtop.xhtml" />
+ </rich:layoutPanel>
+ <rich:layoutPanel position="left" width="50%">
+ <ui:include src="/richfaces/layouts/page/includes/gridleft.xhtml" />
+ </rich:layoutPanel>
+ <rich:layoutPanel position="center" width="50%">
+ <ui:include src="/richfaces/layouts/page/includes/gridcenter.xhtml"
/>
+ </rich:layoutPanel>
+ <rich:layoutPanel position="bottom">
+ <ui:include src="/templates/include/sourceview.xhtml">
+ <ui:param name="sourcepath"
value="/richfaces/layouts/page/template.xhtml"/>
+ <ui:param name="openlabel" value="View this page template source
code"/>
+ </ui:include>
+ <br/>
+ </rich:layoutPanel>
+ </rich:layout>
+ </rich:tab>
+ <rich:tab label="Themes support">
+ <ui:include src="/richfaces/layouts/page/includes/themes.xhtml" />
+ </rich:tab>
+ </rich:tabPanel>
+</rich:page>