1 30 package com.genimen.djeneric.ui; 31 32 import java.util.ArrayList ; 33 34 import javax.swing.table.AbstractTableModel ; 35 import javax.swing.table.TableCellEditor ; 36 import javax.swing.table.TableCellRenderer ; 37 38 import com.genimen.djeneric.language.Messages; 39 import com.genimen.djeneric.repository.DjExtent; 40 import com.genimen.djeneric.repository.exceptions.DjenericException; 41 42 public abstract class DjTableModel extends AbstractTableModel 43 { 44 protected DjModelColumn[] _columns = new DjModelColumn[0]; 45 protected DjExtent _extent = null; 47 private ArrayList _listeners = new ArrayList (); 48 protected boolean _editable = true; 49 protected boolean _insertable = true; 50 protected boolean _deleteable = true; 51 52 public DjTableModel() 53 { 54 } 55 56 public void setEditable(boolean b) 57 { 58 _editable = b; 59 } 60 61 public boolean isEditable() 62 { 63 return _editable; 64 } 65 66 public void setInsertable(boolean b) 67 { 68 _insertable = b; 69 } 70 71 public boolean isInsertable() 72 { 73 return _insertable; 74 } 75 76 public void setDeleteable(boolean b) 77 { 78 _deleteable = b; 79 } 80 81 public boolean isDeleteable() 82 { 83 return _deleteable; 84 } 85 86 public void setExtent(DjExtent extent) 87 { 88 _extent = extent; 89 } 90 91 public DjExtent getExtent() 92 { 93 return _extent; 94 } 95 96 public int getColumnCount() 97 { 98 return _columns.length; 99 } 100 101 public String getColumnName(int column) 102 { 103 return _columns[column]._title; 104 } 105 106 public TableCellRenderer getColumnRenderer(int column) 107 { 108 return _columns[column].getCellRenderer(); 109 } 110 111 public TableCellEditor getColumnEditor(int column) 112 { 113 return _columns[column]._editor; 114 } 115 116 public int getColumnWidth(int column) 117 { 118 return _columns[column]._dspWidth; 119 } 120 121 public boolean isCellEditable(int row, int column) 122 { 123 return _editable && _columns[column]._editable; 124 } 125 126 public abstract int insertRow(int atIdx) throws DjenericException; 127 128 public abstract boolean deleteRow(int atIdx) throws DjenericException; 129 130 public void addStatusListener(DjStatusListener lsnr) 131 132 { 133 if (!_listeners.contains(lsnr)) _listeners.add(lsnr); 134 } 135 136 public void removeStatusListener(DjStatusListener lsnr) 137 { 138 _listeners.remove(lsnr); 139 } 140 141 public void setStatusMessage(String msg, boolean informative) 142 { 143 for (int i = 0; i < _listeners.size(); i++) 144 { 145 ((DjStatusListener) (_listeners.get(i))).setStatusMessage(msg, informative); 146 } 147 } 148 149 public void notifyModified() 150 { 151 for (int i = 0; i < _listeners.size(); i++) 152 { 153 ((DjStatusListener) (_listeners.get(i))).notifyModified(); 154 } 155 } 156 157 public void setStatusMessage(String msg) 158 { 159 setStatusMessage(msg, true); 160 } 161 162 public void setStatusMessage(Throwable t) 163 { 164 for (int i = 0; i < _listeners.size(); i++) 165 { 166 ((DjStatusListener) (_listeners.get(i))).setStatusMessage(t); 167 } 168 } 169 170 public int convert2Int(String str) throws DjenericException 171 { 172 int result = 0; 173 if (str.trim().length() > 0) 174 { 175 try 176 { 177 result = Integer.parseInt(str); 178 } 179 catch (Exception x) 180 { 181 throw new DjenericException(Messages.getString("DjTableModel.InvalidNumber", str)); 182 } 183 } 184 return result; 185 } 186 } | Popular Tags |