Author: mvitenkov
Date: 2008-09-29 14:14:39 -0400 (Mon, 29 Sep 2008)
New Revision: 10609
Added:
trunk/test-applications/facelets/src/main/java/extendedDataTable/
trunk/test-applications/facelets/src/main/java/extendedDataTable/DemoPatient.java
trunk/test-applications/facelets/src/main/java/extendedDataTable/DemoPatientProvider.java
trunk/test-applications/facelets/src/main/java/extendedDataTable/ExtendedDataTableBB.java
trunk/test-applications/facelets/src/main/java/extendedDataTable/ExtendedDataTableControlBean.java
Log:
+java beans extendedDataTable
Added: trunk/test-applications/facelets/src/main/java/extendedDataTable/DemoPatient.java
===================================================================
--- trunk/test-applications/facelets/src/main/java/extendedDataTable/DemoPatient.java
(rev 0)
+++
trunk/test-applications/facelets/src/main/java/extendedDataTable/DemoPatient.java 2008-09-29
18:14:39 UTC (rev 10609)
@@ -0,0 +1,86 @@
+package extendedDataTable;
+
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * @author pkawiak
+ */
+
+public class DemoPatient implements Serializable{
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -2265498014894008031L;
+ private Integer id;
+ private String firstName;
+ private String lastName;
+ private Date admissionDate;
+
+ DemoPatient(Integer id, String firstName, String lastName, Date admissionDate) {
+ this.id = id;
+ this.firstName = firstName;
+ this.lastName = lastName;
+ this.admissionDate = admissionDate;
+ }
+
+ /**
+ * @return the id
+ */
+ public Integer getId() {
+ return id;
+ }
+
+ /**
+ * @param id the id to set
+ */
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ /**
+ * @return the firstName
+ */
+ public String getFirstName() {
+ return firstName;
+ }
+
+ /**
+ * @param firstName the firstName to set
+ */
+ public void setFirstName(String firstName) {
+ this.firstName = firstName;
+ }
+
+ /**
+ * @return the lastName
+ */
+ public String getLastName() {
+ return lastName;
+ }
+
+ /**
+ * @param lastName the lastName to set
+ */
+ public void setLastName(String lastName) {
+ this.lastName = lastName;
+ }
+
+ /**
+ * @return the admissionDate
+ */
+ public Date getAdmissionDate() {
+ return admissionDate;
+ }
+
+ /**
+ * @param admissionDate the admissionDate to set
+ */
+ public void setAdmissionDate(Date admissionDate) {
+ this.admissionDate = admissionDate;
+ }
+
+
+
+}
Added:
trunk/test-applications/facelets/src/main/java/extendedDataTable/DemoPatientProvider.java
===================================================================
---
trunk/test-applications/facelets/src/main/java/extendedDataTable/DemoPatientProvider.java
(rev 0)
+++
trunk/test-applications/facelets/src/main/java/extendedDataTable/DemoPatientProvider.java 2008-09-29
18:14:39 UTC (rev 10609)
@@ -0,0 +1,125 @@
+package extendedDataTable;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Random;
+
+import org.richfaces.model.DataProvider;
+
+/**
+ * @author pkawiak
+ *
+ */
+
+public class DemoPatientProvider implements DataProvider<DemoPatient>{
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 7038048580234887663L;
+
+ private String allFirstNames[] = {
+ "Aaron", "Abbott", "Abel",
"Abner",
+ "Abraham", "Adam", "Addison",
"Adler",
+ "Adley", "Adrian", "Aedan",
"Aiken",
+ "Alan", "Alastair", "Albern",
"Albert",
+ "Albion", "Alden", "Aldis",
"Aldrich",
+ "Alexander", "Alfie", "Alfred",
"Algernon",
+ "Alston", "Alton", "Alvin",
"Ambrose",
+ "Amery", "Amos", "Andrew",
"Angus",
+ "Ansel", "Anthony", "Archer",
"Archibald",
+ "Arlen", "Arnold", "Arthur",
"Arvel",
+ "Atwater", "Atwood", "Aubrey",
"Austin",
+ "Małgorzata", "Paweł", "Piotr"
+ };
+
+ private String allLastNames[] = {
+ "Brown", "Smith", "Patel",
+ "Jones", "Williams", "Johnson",
+ "Taylor", "Thomas", "Roberts",
+ "Khan", "Lewis", "Jackson",
+ "Clarke", "James", "Phillips",
+ "Wilson", "Ali", "Mason",
+ "Davies", "Rodriguez", "Cox",
+ "Alexander", "Popiołek", "Buda",
+ "Goławski", "Kawiak", "Mitchel"
+
+ };
+
+ private List<DemoPatient> items;
+ private Integer itemsNumber;
+
+ private Random random = new Random();
+ private long now = new Date().getTime();
+
+
+ public DemoPatientProvider(Integer itemsNumber) {
+ super();
+ this.itemsNumber = itemsNumber;
+ }
+
+ private Date generateRandomDate(){
+ return new Date(Math.abs(random.nextLong()%now));
+ }
+
+ private String generateRandomFirstName() {
+ int rand = Math.abs(random.nextInt());
+ return allFirstNames[rand%(allFirstNames.length)];
+ }
+
+ private String generateRandomLastName() {
+ int rand = Math.abs(random.nextInt());
+ return allLastNames[rand%(allLastNames.length)];
+ }
+
+ /* (non-Javadoc)
+ * @see org.richfaces.model.DataProvider#getItemByKey(java.lang.Object)
+ */
+ public DemoPatient getItemByKey(Object key) {
+ if (key == null)
+ return null;
+ for (DemoPatient entity : getItems()){
+ if (entity.getId().equals(key))
+ return entity;
+ }
+ return null;
+ }
+
+ protected List<DemoPatient> getItems() {
+ if (items == null){
+ int l = itemsNumber;
+ items = new ArrayList<DemoPatient>(l);
+ for (int i=0;i<l;i++) {
+ items.add(new DemoPatient(i,
+ generateRandomFirstName(),
+ generateRandomLastName(),
+ generateRandomDate()));
+ }
+
+ }
+ return items;
+ }
+
+ /* (non-Javadoc)
+ * @see org.richfaces.model.DataProvider#getItemsByRange(int, int)
+ */
+ public List<DemoPatient> getItemsByRange(int firstRow, int lastRow) {
+ return getItems().subList(firstRow, lastRow);
+ }
+
+ /* (non-Javadoc)
+ * @see org.richfaces.model.DataProvider#getKey(java.lang.Object)
+ */
+ public Object getKey(DemoPatient item) {
+ return item.getId();
+ }
+
+ /* (non-Javadoc)
+ * @see org.richfaces.model.DataProvider#getRowCount()
+ */
+ public int getRowCount() {
+ return getItems().size();
+ }
+
+}
\ No newline at end of file
Added:
trunk/test-applications/facelets/src/main/java/extendedDataTable/ExtendedDataTableBB.java
===================================================================
---
trunk/test-applications/facelets/src/main/java/extendedDataTable/ExtendedDataTableBB.java
(rev 0)
+++
trunk/test-applications/facelets/src/main/java/extendedDataTable/ExtendedDataTableBB.java 2008-09-29
18:14:39 UTC (rev 10609)
@@ -0,0 +1,115 @@
+package extendedDataTable;
+
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.faces.context.FacesContext;
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.richfaces.model.ExtendedTableDataModel;
+import org.richfaces.model.selection.SimpleSelection;
+
+/**
+ * @author mvitenkov
+ *
+ */
+public class ExtendedDataTableBB {
+
+ private SimpleSelection selection = new SimpleSelection();
+ private List<DemoPatient> selectedItems;
+ private Comparator<DemoPatient> dateComparator;
+ private String tableState = null;
+ private ExtendedTableDataModel<DemoPatient> dataModel;
+ private Integer patientsNumber = 100;
+
+ public ExtendedDataTableBB() {
+ }
+
+ public ExtendedTableDataModel<DemoPatient> getDataModel(){
+ if (dataModel == null){
+ dataModel = new ExtendedTableDataModel<DemoPatient>(new
DemoPatientProvider(patientsNumber));
+ }
+ return dataModel;
+ }
+
+ public SimpleSelection getSelection() {
+ return selection;
+ }
+
+ public void setSelection(SimpleSelection selection) {
+ this.selection = selection;
+ }
+
+ public String takeSelection() {
+ getSelectedItems().clear();
+ Iterator<Object> iterator = getSelection().getKeys();
+ while (iterator.hasNext()){
+ Object key = iterator.next();
+ selectedItems.add(getDataModel().getObjectByKey(key));
+ }
+ return null;
+ }
+
+ public Integer getPatientsNumber() {
+ return patientsNumber;
+ }
+
+ public void setPatientsNumber(Integer patientsNumber) {
+ if (patientsNumber != this.patientsNumber) {
+ dataModel = new ExtendedTableDataModel<DemoPatient>(new
DemoPatientProvider(patientsNumber));
+ }
+ this.patientsNumber = patientsNumber;
+ }
+
+ public List<DemoPatient> getSelectedItems() {
+ if (selectedItems == null){
+ selectedItems = new ArrayList<DemoPatient>();
+ }
+ return selectedItems;
+ }
+
+ public void setSelectedItems(List<DemoPatient> selectedItems) {
+ this.selectedItems = selectedItems;
+ }
+
+ public String getTableState() {
+ if (tableState == null){
+ //try to get state from cookies
+ Cookie[] cookies =
((HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest()).getCookies();
+ if (cookies != null){
+ for (Cookie c : cookies){
+ if (c.getName().equals("g3demoTabelState")){
+ tableState = c.getValue();
+ break;
+ }
+ }
+ }
+ }
+ return tableState;
+ }
+
+ public void setTableState(String tableState) {
+ this.tableState = tableState;
+ //save state in cookies
+ Cookie stateCookie = new Cookie("g3demoTabelState", this.tableState);
+
((HttpServletResponse)FacesContext.getCurrentInstance().getExternalContext().getResponse()).addCookie(stateCookie);
+ }
+
+ public Comparator<DemoPatient> getDateComparator(){
+ if (dateComparator == null){
+ dateComparator = new Comparator<DemoPatient>(){
+
+ public int compare(DemoPatient o1, DemoPatient o2) {
+ return o1.getAdmissionDate().compareTo(o2.getAdmissionDate());
+ }
+
+ };
+ }
+ return dateComparator;
+ }
+
+}
Added:
trunk/test-applications/facelets/src/main/java/extendedDataTable/ExtendedDataTableControlBean.java
===================================================================
---
trunk/test-applications/facelets/src/main/java/extendedDataTable/ExtendedDataTableControlBean.java
(rev 0)
+++
trunk/test-applications/facelets/src/main/java/extendedDataTable/ExtendedDataTableControlBean.java 2008-09-29
18:14:39 UTC (rev 10609)
@@ -0,0 +1,215 @@
+package extendedDataTable;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.richfaces.component.html.HtmlExtendedDataTable;
+
+import util.componentInfo.ComponentInfo;
+
+import javax.faces.event.ActionEvent;
+import javax.faces.context.FacesContext;
+import javax.faces.model.SelectItem;
+
+public class ExtendedDataTableControlBean {
+
+ private String width = "100%";
+ private String height = "500px";
+ private List<SelectItem> sortModeSelectItems = new
ArrayList<SelectItem>();
+ private List<SelectItem> selectionModeSelectItems = new
ArrayList<SelectItem>();
+ private String sortMode;
+ private String selectionMode;
+ private Integer rowsNumber;
+ private boolean paginated = false;
+ private HtmlExtendedDataTable extDTable = null;
+ private String bindLabel;
+ private String border;
+ private String cellpadding;
+ private String cellspacing;
+ private String dir;
+ private int first;
+ private String frame;
+ private String groupingColumn;
+ private boolean rendered;
+ private String sortPriority;
+
+ public String getSortPriority() {
+ return sortPriority;
+ }
+
+ public void setSortPriority(String sortPriority) {
+ this.sortPriority = sortPriority;
+ }
+
+ public boolean isRendered() {
+ return rendered;
+ }
+
+ public void setRendered(boolean rendered) {
+ this.rendered = rendered;
+ }
+
+ public String getGroupingColumn() {
+ return groupingColumn;
+ }
+
+ public void setGroupingColumn(String groupingColumn) {
+ this.groupingColumn = groupingColumn;
+ }
+
+ public String getFrame() {
+ return frame;
+ }
+
+ public void setFrame(String frame) {
+ this.frame = frame;
+ }
+
+ public int getFirst() {
+ return first;
+ }
+
+ public void setFirst(int first) {
+ this.first = first;
+ }
+
+ public String getDir() {
+ return dir;
+ }
+
+ public void setDir(String dir) {
+ this.dir = dir;
+ }
+
+ public String getCellpadding() {
+ return cellpadding;
+ }
+
+ public void setCellpadding(String cellpadding) {
+ this.cellpadding = cellpadding;
+ }
+
+ public String getCellspacing() {
+ return cellspacing;
+ }
+
+ public void setCellspacing(String cellspacing) {
+ this.cellspacing = cellspacing;
+ }
+
+ public String getBorder() {
+ return border;
+ }
+
+ public void setBorder(String border) {
+ this.border = border;
+ }
+
+ public HtmlExtendedDataTable getExtDTable() {
+ return extDTable;
+ }
+
+ public void setExtDTable(HtmlExtendedDataTable extDTable) {
+ this.extDTable = extDTable;
+ }
+
+ public void checkBinding(ActionEvent actionEvent){
+ FacesContext context = FacesContext.getCurrentInstance();
+ bindLabel = extDTable.getBaseClientId(context);
+ }
+ public void addExtDTable(){
+ ComponentInfo info = ComponentInfo.getInstance();
+ info.addField(extDTable);
+ }
+
+ public ExtendedDataTableControlBean() {
+ sortModeSelectItems.add(new SelectItem("single", "single"));
+ sortModeSelectItems.add(new SelectItem("multi", "multi"));
+ selectionModeSelectItems.add(new SelectItem("single",
"single"));
+ selectionModeSelectItems.add(new SelectItem("multi",
"multi"));
+ selectionModeSelectItems.add(new SelectItem("none",
"none"));
+ bindLabel = "click binding";
+ border = "1px";
+ cellpadding = "1px";
+ cellspacing = "1px";
+ dir = "LTR";
+ first = 0;
+ frame = "void";
+ rendered = true;
+ }
+
+ public boolean isPaginated() {
+ return paginated;
+ }
+
+ public void setPaginated(boolean paginated) {
+ this.paginated = paginated;
+ }
+
+ public Integer getRowsNumber() {
+ return rowsNumber;
+ }
+
+ public void setRowsNumber(Integer rowsNumber) {
+ this.rowsNumber = rowsNumber;
+ }
+
+ public List<SelectItem> getSelectionModeSelectItems() {
+ return selectionModeSelectItems;
+ }
+
+ public void setSelectionModeSelectItems(
+ List<SelectItem> selectionModeSelectItems) {
+ this.selectionModeSelectItems = selectionModeSelectItems;
+ }
+
+
+
+ public List<SelectItem> getSortModeSelectItems() {
+ return sortModeSelectItems;
+ }
+
+ public void setSortModeSelectItems(List<SelectItem> sortModeSelectItems) {
+ this.sortModeSelectItems = sortModeSelectItems;
+ }
+
+ public String getSortMode() {
+ return sortMode;
+ }
+
+ public void setSortMode(String sortMode) {
+ this.sortMode = sortMode;
+ }
+
+ public String getSelectionMode() {
+ return selectionMode;
+ }
+
+ public void setSelectionMode(String selectionMode) {
+ this.selectionMode = selectionMode;
+ }
+
+ public String getWidth() {
+ return width;
+ }
+
+ public void setWidth(String width) {
+ this.width = width;
+ }
+
+ public String getHeight() {
+ return height;
+ }
+
+ public void setHeight(String height) {
+ this.height = height;
+ }
+
+ public String getBindLabel() {
+ return bindLabel;
+ }
+
+ public void setBindLabel(String bindLabel) {
+ this.bindLabel = bindLabel;
+ }
+
+}