1 /*
2 * $Id: IDataModel.java,v 1.1 2007/01/12 15:40:45 oeuillot Exp $
3 */
4 package org.rcfaces.core.model;
5
6 import javax.faces.FacesException;
7 import javax.faces.model.DataModel;
8 import javax.faces.model.DataModelEvent;
9 import javax.faces.model.DataModelListener;
10
11 /**
12 *
13 * @author Olivier Oeuillot (latest modification by $Author: oeuillot $)
14 * @version $Revision: 1.1 $ $Date: 2007/01/12 15:40:45 $
15 */
16 public interface IDataModel {
17 /**
18 * <p>
19 * Return a flag indicating whether there is <code>rowData</code>
20 * available at the current <code>rowIndex</code>. If no
21 * <code>wrappedData</code> is available, return <code>false</code>.
22 * </p>
23 *
24 * @exception FacesException
25 * if an error occurs getting the row availability
26 */
27 boolean isRowAvailable();
28
29 /**
30 * <p>
31 * Return the number of rows of data objects represented by this
32 * {@link DataModel}. If the number of rows is unknown, or no
33 * <code>wrappedData</code> is available, return -1.
34 * </p>
35 *
36 * @exception FacesException
37 * if an error occurs getting the row count
38 */
39 int getRowCount();
40
41 /**
42 * <p>
43 * Return an object representing the data for the currenty selected row
44 * index. If no <code>wrappedData</code> is available, return
45 * <code>null</code>.
46 * </p>
47 *
48 * @exception FacesException
49 * if an error occurs getting the row data
50 * @exception IllegalArgumentException
51 * if now row data is available at the currently specified
52 * row index
53 */
54 Object getRowData();
55
56 /**
57 * <p>
58 * Return the zero-relative index of the currently selected row. If we are
59 * not currently positioned on a row, or no <code>wrappedData</code> is
60 * available, return -1.
61 * </p>
62 *
63 * @exception FacesException
64 * if an error occurs getting the row index
65 */
66 int getRowIndex();
67
68 /**
69 * <p>
70 * Set the zero-relative index of the currently selected row, or -1 to
71 * indicate that we are not positioned on a row. It is possible to set the
72 * row index at a value for which the underlying data collection does not
73 * contain any row data. Therefore, callers may use the
74 * <code>isRowAvailable()</code> method to detect whether row data will be
75 * available for use by the <code>getRowData()</code> method.
76 * </p>
77 *
78 * <p>
79 * If there is no <code>wrappedData</code> available when this method is
80 * called, the specified <code>rowIndex</code> is stored (and may be
81 * retrieved by a subsequent call to <code>getRowData()</code>), but no
82 * event is sent. Otherwise, if the currently selected row index is changed
83 * by this call, a {@link DataModelEvent} will be sent to the
84 * <code>rowSelected()</code> method of all registered
85 * {@link DataModelListener}s.
86 * </p>
87 *
88 * @param rowIndex
89 * The new zero-relative index (must be non-negative)
90 *
91 * @exception FacesException
92 * if an error occurs setting the row index
93 * @exception IllegalArgumentException
94 * if <code>rowIndex</code> is less than -1
95 */
96 void setRowIndex(int rowIndex);
97
98 /**
99 * <p>
100 * Return the object representing the data wrapped by this {@link DataModel},
101 * if any.
102 * </p>
103 */
104 Object getWrappedData();
105
106 /**
107 * <p>
108 * Set the object representing the data collection wrapped by this
109 * {@link DataModel}. If the specified <code>data</code> is
110 * <code>null</code>, detach this {@link DataModel} from any previously
111 * wrapped data collection instead.
112 * </p>
113 *
114 * <p>
115 * If <code>data</code> is non-<code>null</code>, the currently
116 * selected row index must be set to zero, and a {@link DataModelEvent} must
117 * be sent to the <code>rowSelected()</code> method of all registered
118 * {@link DataModelListener}s indicating that this row is now selected.
119 * </p>
120 *
121 * @param data
122 * Data collection to be wrapped, or <code>null</code> to
123 * detach from any previous data collection
124 *
125 * @exception ClassCastException
126 * if <code>data</code> is not of the appropriate type for
127 * this {@link DataModel} implementation
128 */
129 void setWrappedData(Object data);
130 }