1 16 package javax.faces.model; 17 18 22 public class ScalarDataModel extends DataModel 23 { 24 private int _rowIndex = -1; 26 private Object _data; 27 28 public ScalarDataModel() 30 { 31 super(); 32 } 33 34 public ScalarDataModel(Object scalar) 35 { 36 setWrappedData(scalar); 37 } 38 39 public int getRowCount() 41 { 42 return _data != null ? 1 : -1; 43 } 44 45 public Object getRowData() 46 { 47 if (_data == null) 48 { 49 return null; 50 } 51 if (!isRowAvailable()) 52 { 53 throw new IllegalArgumentException ("row is unavailable"); 54 } 55 return _data; 56 } 57 58 public int getRowIndex() 59 { 60 return _rowIndex; 61 } 62 63 public Object getWrappedData() 64 { 65 return _data; 66 } 67 68 public boolean isRowAvailable() 69 { 70 if (_data == null) 71 { 72 return false; 73 } 74 return _rowIndex == 0; 75 } 76 77 public void setRowIndex(int rowIndex) 78 { 79 if (rowIndex < -1) 80 { 81 throw new IllegalArgumentException ("illegal rowIndex " + rowIndex); 82 } 83 int oldRowIndex = _rowIndex; 84 _rowIndex = rowIndex; 85 if (_data != null && oldRowIndex != _rowIndex) 86 { 87 Object data = isRowAvailable() ? getRowData() : null; 88 DataModelEvent event = new DataModelEvent(this, _rowIndex, data); 89 DataModelListener[] listeners = getDataModelListeners(); 90 for (int i = 0; i < listeners.length; i++) 91 { 92 listeners[i].rowSelected(event); 93 } 94 } 95 } 96 97 public void setWrappedData(Object data) 98 { 99 _data = data; 100 int rowIndex = _data != null ? 0 : -1; 101 setRowIndex(rowIndex); 102 } 103 104 } 105 | Popular Tags |