Author: abelevich
Date: 2007-05-28 14:13:40 -0400 (Mon, 28 May 2007)
New Revision: 909
Added:
trunk/sandbox-samples/scrollable-grid-demo/src/main/java/org/richfaces/demo/datagrid/bean/ChannelDataModel.java
Modified:
trunk/sandbox-samples/scrollable-grid-demo/src/main/java/org/richfaces/demo/datagrid/bean/SelectionBean.java
Log:
Added:
trunk/sandbox-samples/scrollable-grid-demo/src/main/java/org/richfaces/demo/datagrid/bean/ChannelDataModel.java
===================================================================
---
trunk/sandbox-samples/scrollable-grid-demo/src/main/java/org/richfaces/demo/datagrid/bean/ChannelDataModel.java
(rev 0)
+++
trunk/sandbox-samples/scrollable-grid-demo/src/main/java/org/richfaces/demo/datagrid/bean/ChannelDataModel.java 2007-05-28
18:13:40 UTC (rev 909)
@@ -0,0 +1,171 @@
+/*
+ * Copyright
+ * Copyright (c) Exadel,Inc. 2006
+ * All rights reserved.
+ *
+ * History
+ * $Source:
/cvs-master/intralinks-jsf-comps/web-projects/data-view-grid-demo/src/com/exadel/jsf/demo/datagrid/bean/ChannelDataModel.java,v
$
+ * $Revision: 1.4 $
+ */
+
+package org.richfaces.demo.datagrid.bean;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.richfaces.demo.datagrid.model.Channel;
+import org.richfaces.demo.datagrid.model.Issue;
+import org.richfaces.model.DataRange;
+import org.richfaces.model.ScrollableGridDataModel2;
+import org.richfaces.model.SortOrder;
+import org.richfaces.model.snapshot.ObjectLocator;
+
+/**
+ * Example data model. Uses {@link Channel} instance as data storage
+ *
+ * @author Maksim Kaszynski
+ *
+ */
+public class ChannelDataModel extends ScrollableGridDataModel2 {
+
+ /**
+ * Data range implementation. Wraps query result
+ * @author Maksim Kaszynski
+ *
+ */
+ public static class ChannelDataRange extends DataRange {
+
+ private List <Issue> window;
+
+ public ChannelDataRange(int startRow, int endRow, SortOrder sortOrder, List
<Issue> window) {
+ super(startRow, endRow, sortOrder);
+ this.window = window;
+ }
+
+ /**
+ * get loaded object
+ * @see com.exadel.jsf.model.DataRange#getRowData(int)
+ */
+ @Override
+ public Object getRowData(int index) {
+ return window.get(index - getStartRow());
+ }
+ }
+
+ /**
+ * Minimize LIST queries. Locate objects by their IDs
+ * @author Maksim Kaszynski
+ *
+ */
+ public class IssueLocator implements ObjectLocator {
+
+ public Collection findObjects(Collection ids) {
+ System.out.println("IssueLocator.findObjects()" + ids);
+
+ //sort of find by ids
+ List <Issue> issues = new ArrayList<Issue>(ids.size());
+ for (Object key : ids) {
+ Integer id = (Integer) key;
+ Issue issue = getChannel().findById(id);
+ issues.add(issue);
+ }
+
+ return issues;
+ }
+
+ public Serializable getObjectId(Object object) {
+ Issue issue = (Issue) object;
+ Integer id = issue.getIndex();
+ return id;
+ }
+
+ }
+
+ private ObjectLocator objectLocator = new IssueLocator();
+ private Channel channel;
+ private int rowIndex;
+
+ /**
+ * Load part of channel.
+ */
+ @Override
+ protected DataRange createDataRange(int startRow, int endRow,
+ SortOrder sortOrder) {
+ //access storage to get data
+ List <Issue> window = getChannel().executeQuery(startRow, endRow, sortOrder);
+ System.out.println("ChannelDataModel.createDataRange()");
+ return new ChannelDataRange(startRow, endRow, sortOrder, window);
+ }
+
+ /**
+ * @see javax.faces.model.DataModel#getRowCount()
+ */
+ @Override
+ public int getRowCount() {
+ return getChannel().size();
+ }
+
+
+ @Override
+ public Object getWrappedData() {
+ return getChannel();
+ }
+
+ /**
+ * @see javax.faces.model.DataModel#isRowAvailable()
+ */
+ @Override
+ public boolean isRowAvailable() {
+ return rowIndex < getRowCount();
+ }
+
+ @Override
+ public void setWrappedData(Object data) {
+ setChannel((Channel) data);
+ }
+
+ /**
+ * @return the channel
+ */
+ public Channel getChannel() {
+ return channel;
+ }
+
+ /**
+ * @param channel the channel to set
+ */
+ public void setChannel(Channel channel) {
+ this.channel = channel;
+ }
+
+ /**
+ * @return the rowIndex
+ */
+ public int getRowIndex() {
+ return rowIndex;
+ }
+
+ /**
+ * @param rowIndex the rowIndex to set
+ */
+ public void setRowIndex(int rowIndex) {
+ this.rowIndex = rowIndex;
+ }
+
+ /**
+ * @return the objectLocator
+ */
+ public ObjectLocator getObjectLocator() {
+ return objectLocator;
+ }
+
+ /**
+ * @param objectLocator the objectLocator to set
+ */
+ public void setObjectLocator(ObjectLocator objectLocator) {
+ this.objectLocator = objectLocator;
+ }
+
+}
Modified:
trunk/sandbox-samples/scrollable-grid-demo/src/main/java/org/richfaces/demo/datagrid/bean/SelectionBean.java
===================================================================
---
trunk/sandbox-samples/scrollable-grid-demo/src/main/java/org/richfaces/demo/datagrid/bean/SelectionBean.java 2007-05-28
18:13:31 UTC (rev 908)
+++
trunk/sandbox-samples/scrollable-grid-demo/src/main/java/org/richfaces/demo/datagrid/bean/SelectionBean.java 2007-05-28
18:13:40 UTC (rev 909)
@@ -1,31 +1,89 @@
+/*
+ * Copyright
+ * Copyright (c) Exadel,Inc. 2006
+ * All rights reserved.
+ *
+ * History
+ * $Source:
/cvs-master/intralinks-jsf-comps/web-projects/data-view-grid-demo/src/com/exadel/jsf/demo/datagrid/bean/SelectionBean.java,v
$
+ * $Revision: 1.19 $
+ */
+
package org.richfaces.demo.datagrid.bean;
+import javax.faces.event.ActionEvent;
-import java.util.List;
-
import org.richfaces.demo.datagrid.model.Channel;
+import org.richfaces.demo.datagrid.model.Issue;
+import org.richfaces.model.ScrollableGridDataModel2;
+import org.richfaces.model.visual.ScrollableGridVisualModel;
-
-public class SelectionBean{
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public class SelectionBean {
- List dataModel;
+ private ScrollableGridVisualModel visualModel;
- Channel channel;
+ private ScrollableGridDataModel2 dataModel;
+ private Channel channel;
- public SelectionBean(){
- System.out.println("create SelectionBean");
- }
+ private String key;
- public List getDataModel() {
+ private int id;
+
+
+ public ScrollableGridDataModel2 getDataModel() {
return dataModel;
}
- public void setDataModel(List dataModel) {
+ public void setDataModel(ScrollableGridDataModel2 dataModel) {
this.dataModel = dataModel;
}
+ public ScrollableGridVisualModel getVisualModel() {
+ return visualModel;
+ }
+
+ /**
+ * @param visualModel the visualModel to set
+ */
+ public void setVisualModel(ScrollableGridVisualModel visualModel) {
+ this.visualModel = visualModel;
+ }
+
+ public SelectionBean() {
+
+ }
+
+ public void setKeyz(ActionEvent e) {
+ System.out.println("SelectionBean.setKeyz() " + key + "id " + id);
+ Channel channel = (Channel) getDataModel().getWrappedData ();
+ Issue issue = channel.getIndex().get(id);
+ if (issue != null) {
+ channel.getIndex().remove(issue.getIndex());
+ channel.getIssues().remove(issue);
+ }
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public String getKey() {
+ return key;
+ }
+
+ public void setKey(String key) {
+ this.key = key;
+ }
+
public Channel getChannel() {
return channel;
}
@@ -33,5 +91,5 @@
public void setChannel(Channel channel) {
this.channel = channel;
}
+}
-}
Show replies by thread