public void setRowIndex(int rowIndex) { if (rowIndex < -1) { throw new IllegalArgumentException(); } int oldIndex = index; index = rowIndex; if (result == null) { return; } DataModelListener[] listeners = getDataModelListeners(); if ((oldIndex != index) && (listeners != null)) { Object rowData = null; if (isRowAvailable()) { rowData = getRowData(); } DataModelEvent event = new DataModelEvent(this, index, rowData); for (int i = 0; i < listeners.length; i++) { listeners[i].rowSelected(event); } } }
public void setWrappedData(Object data) { if (data == null) { setRowIndex(-1); } else { _data = ((Result)data); setRowIndex(0); } }
/** * <p>Construct a new {@link ResultDataModel} wrapping the specified * <code>Result</code>.</p> * * @param result <code>Result</code> to be wrapped (if any) */ public ResultDataModel(Result result) { super(); setWrappedData(result); }
public Object getRowData() { if (getRows() == null) { return null; } if (!isRowAvailable()) { throw new IllegalArgumentException("row is unavailable"); } return getRows()[_rowIndex]; }
public void setRowIndex(int rowIndex) { if (rowIndex < -1) { throw new IllegalArgumentException("illegal rowIndex " + rowIndex); } int oldRowIndex = _rowIndex; _rowIndex = rowIndex; if (getRows() != null && oldRowIndex != _rowIndex) { Object data = isRowAvailable() ? getRowData() : null; DataModelEvent event = new DataModelEvent(this, _rowIndex, data); DataModelListener[] listeners = getDataModelListeners(); for (int i = 0; i < listeners.length; i++) { listeners[i].rowSelected(event); } } }
@SuppressWarnings("unchecked") protected DataModel<?> createFacesModel(Object value) { DataModel<?> model = null; if (value == null) { model = new ListDataModel(Collections.EMPTY_LIST); } else if (value instanceof DataModel) { model = (DataModel) value; } else if (value instanceof List) { model = new ListDataModel((List) value); } else if (Object[].class.isAssignableFrom(value.getClass())) { model = new ArrayDataModel((Object[]) value); } else if (value instanceof ResultSet) { model = new ResultSetDataModel((ResultSet) value); } else if (value instanceof Result) { model = new ResultDataModel((Result) value); } else { model = new ScalarDataModel(value); } return model; }
public Object getRowData() { if (result == null) { return null; } if (!isRowAvailable()) { throw new IllegalArgumentException(); } return rows_[index]; }
/** * Creates a new DataModel around the current value. */ protected DataModel createDataModel() { Object value = getValue(); if (value == null) { return EMPTY_DATA_MODEL; } else if (value instanceof DataModel) { return (DataModel) value; } else if (value instanceof List) { return new ListDataModel((List) value); } else if (value instanceof Collection) { return new ListDataModel(new ArrayList((Collection) value)); } else if (OBJECT_ARRAY_CLASS.isAssignableFrom(value.getClass())) { return new ArrayDataModel((Object[]) value); } else if (value instanceof ResultSet) { return new ResultSetDataModel((ResultSet) value); } else if (value instanceof Result) { return new ResultDataModel((Result) value); } else { return new ScalarDataModel(value); } }
@Override public void setRowIndex(int rowIndex) { if (rowIndex < -1) { throw new IllegalArgumentException("illegal rowIndex " + rowIndex); } int oldRowIndex = _rowIndex; _rowIndex = rowIndex; if (getRows() != null && oldRowIndex != _rowIndex) { SortedMap<String, Object> data = isRowAvailable() ? getRowData() : null; DataModelEvent event = new DataModelEvent(this, _rowIndex, data); DataModelListener[] listeners = getDataModelListeners(); for (int i = 0; i < listeners.length; i++) { listeners[i].rowSelected(event); } } }
/** * <p>If row data is available, return the <code>SortedMap</code> array * element at the index specified by <code>rowIndex</code> of the * array returned by calling <code>getRows()</code> on the underlying * <code>Result</code>. If no wrapped data is available, * return <code>null</code>.</p> * * <p>Note that, if a non-<code>null</code> <code>Map</code> is returned * by this method, it will contain the values of the columns for the * current row, keyed by column name. Column name comparisons must be * performed in a case-insensitive manner.</p> * * @throws FacesException if an error occurs getting the row data * @throws IllegalArgumentException if now row data is available * at the currently specified row index */ public SortedMap<String,Object> getRowData() { if (result == null) { return (null); } else if (!isRowAvailable()) { throw new NoRowAvailableException(); } else { //noinspection unchecked return ((SortedMap<String,Object>)rows[index]); } }
@Override public SortedMap<String, Object> getRowData() { if (getRows() == null) { return null; } if (!isRowAvailable()) { throw new IllegalArgumentException("row is unavailable"); } return getRows()[_rowIndex]; }
/** * @throws javax.faces.FacesException {@inheritDoc} * @throws IllegalArgumentException {@inheritDoc} */ @Override public void setRowIndex(int rowIndex) { if (rowIndex < -1) { throw new IllegalArgumentException(); } int old = index; index = rowIndex; if (result == null) { return; } DataModelListener [] listeners = getDataModelListeners(); if ((old != index) && (listeners != null)) { SortedMap<String,Object> rowData = null; if (isRowAvailable()) { rowData = getRowData(); } DataModelEvent event = new DataModelEvent(this, index, rowData); int n = listeners.length; for (int i = 0; i < n; i++) { if (null != listeners[i]) { listeners[i].rowSelected(event); } } } }
public static DataModel getSuitableDataModel(Object obj) { DataModel model = null; if (obj == null) { model = new ListDataModel(Collections.EMPTY_LIST); } else if (obj instanceof DataModel) { model = (DataModel) obj; } else if (obj instanceof List) { model = new ListDataModel((List) obj); } else if (Object[].class.isAssignableFrom(obj.getClass())) { model = new ArrayDataModel((Object[]) obj); } else if (obj instanceof ResultSet) { model = new ResultSetDataModel((ResultSet) obj); } else if (obj instanceof Result) { model = new ResultDataModel((Result) obj); } else { model = new ScalarDataModel(obj); } return model; }
/** * <p>Construct a new {@link ResultDataModel} wrapping the specified * <code>Result</code>.</p> * * @param result <code>Result</code> to be wrapped (if any) */ public ResultDataModel(Result result) { super(); setWrappedData(result); }
@Override public void setWrappedData(Object data) { if (data == null) { setRowIndex(-1); _data = null; } else { _data = ((Result)data); _rowIndex = -1; setRowIndex(0); } }
/** * <p>If row data is available, return the <code>SortedMap</code> array * element at the index specified by <code>rowIndex</code> of the * array returned by calling <code>getRows()</code> on the underlying * <code>Result</code>. If no wrapped data is available, * return <code>null</code>.</p> * * <p>Note that, if a non-<code>null</code> <code>Map</code> is returned * by this method, it will contain the values of the columns for the * current row, keyed by column name. Column name comparisons must be * performed in a case-insensitive manner.</p> * * @throws javax.faces.FacesException if an error occurs getting the row data * @throws IllegalArgumentException if now row data is available * at the currently specified row index */ @Override public SortedMap<String,Object> getRowData() { if (result == null) { return (null); } else if (!isRowAvailable()) { throw new NoRowAvailableException(); } else { //noinspection unchecked return ((SortedMap<String,Object>)rows[index]); } }
/** * @throws javax.faces.FacesException {@inheritDoc} * @throws IllegalArgumentException {@inheritDoc} */ @Override public void setRowIndex(int rowIndex) { if (rowIndex < -1) { throw new IllegalArgumentException(); } int old = index; index = rowIndex; if (result == null) { return; } DataModelListener [] listeners = getDataModelListeners(); if ((old != index) && (listeners != null)) { SortedMap<String,Object> rowData = null; if (isRowAvailable()) { rowData = getRowData(); } DataModelEvent event = new DataModelEvent(this, index, rowData); int n = listeners.length; for (int i = 0; i < n; i++) { if (null != listeners[i]) { listeners[i].rowSelected(event); } } } }
return new ResultDataModel((Result) data);
/** * <p>Construct a new {@link ResultDataModel} wrapping the specified * <code>Result</code>.</p> * * @param result <code>Result</code> to be wrapped (if any) */ public ResultDataModel(Result result) { super(); setWrappedData(result); }
public void setWrappedData(Object data) { if (data == null) { setRowIndex(-1); } else { result = (Result) data; rows_ = result.getRows(); setRowIndex(0); } }