| Line | Hits | Source |
|---|---|---|
| 1 | /******************************************************************************* | |
| 2 | * InternetCafe is a software solution that helps the management of Cybercafes | |
| 3 | * according with the ITALIAN DECREE LAW ON ANTI-TERROR MEASURES, 27 JULY 2005. | |
| 4 | * Copyright (C) 2006 Guido Angelo Ingenito | |
| 5 | ||
| 6 | * This program is free software; you can redistribute it and/or | |
| 7 | * modify it under the terms of the GNU General Public License | |
| 8 | * as published by the Free Software Foundation; either version 2 | |
| 9 | * of the License, or (at your option) any later version. | |
| 10 | ||
| 11 | * This program is distributed in the hope that it will be useful, | |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 14 | * GNU General Public License for more details. | |
| 15 | * | |
| 16 | * You should have received a copy of the GNU General Public License | |
| 17 | * along with this program; if not, write to the Free Software | |
| 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
| 19 | *******************************************************************************/ | |
| 20 | package ui.table.model; | |
| 21 | ||
| 22 | import java.util.Observable; | |
| 23 | ||
| 24 | import javax.swing.table.AbstractTableModel; | |
| 25 | ||
| 26 | import ui.Messages; | |
| 27 | import base.user.NAddress; | |
| 28 | import base.user.PhoneNumber; | |
| 29 | import base.user.User; | |
| 30 | ||
| 31 | @SuppressWarnings("serial") //$NON-NLS-1$ | |
| 32 | public class PhoneNumberTableModel extends AbstractTableModel { | |
| 33 | 0 | |
| 34 | 0 | String[] columnNames = { Messages.getString("common.id"), Messages.getString("common.areacode"), Messages.getString("common.exchange"), Messages.getString("common.number"), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ |
| 35 | 0 | Messages.getString("common.description") }; //$NON-NLS-1$ |
| 36 | 0 | |
| 37 | public static final int PHONENUMBER_ID_COLUMN = 0; | |
| 38 | ||
| 39 | public static final int PHONENUMBER_AREA_CODE_COLUMN = 1; | |
| 40 | ||
| 41 | public static final int PHONENUMBER_EXCHANGE_COLUMN = 2; | |
| 42 | ||
| 43 | public static final int PHONENUMBER_NUMBER_COLUMN = 3; | |
| 44 | ||
| 45 | public static final int PHONENUMBER_DESCRIPTION_COLUMN = 4; | |
| 46 | ||
| 47 | private User user; | |
| 48 | 0 | |
| 49 | 0 | public PhoneNumberTableModel(User user) { |
| 50 | 0 | this.user = user; |
| 51 | 0 | } |
| 52 | 0 | |
| 53 | 0 | public int getColumnCount() { |
| 54 | 0 | return columnNames.length; |
| 55 | 0 | } |
| 56 | ||
| 57 | 0 | public int getRowCount() { |
| 58 | 0 | return user.getPhoneNumber().length; |
| 59 | 0 | } |
| 60 | ||
| 61 | 0 | public String getColumnName(int col) { |
| 62 | 0 | return columnNames[col]; |
| 63 | 0 | } |
| 64 | ||
| 65 | 0 | public Object getValueAt(int row, int column) { |
| 66 | 0 | if (row < 0 || column < 0) |
| 67 | 0 | return null; |
| 68 | 0 | PhoneNumber[] phoneNumber = user.getPhoneNumber(); |
| 69 | 0 | Object result = null; |
| 70 | 0 | switch (column) { |
| 71 | 0 | case PHONENUMBER_ID_COLUMN: |
| 72 | 0 | result = phoneNumber[row].getId(); |
| 73 | 0 | break; |
| 74 | 0 | case PHONENUMBER_AREA_CODE_COLUMN: |
| 75 | 0 | result = phoneNumber[row].getAreaCode(); |
| 76 | 0 | break; |
| 77 | 0 | case PHONENUMBER_EXCHANGE_COLUMN: |
| 78 | 0 | result = phoneNumber[row].getExchange(); |
| 79 | 0 | break; |
| 80 | 0 | case PHONENUMBER_NUMBER_COLUMN: |
| 81 | 0 | result = phoneNumber[row].getNumber(); |
| 82 | 0 | break; |
| 83 | 0 | case PHONENUMBER_DESCRIPTION_COLUMN: |
| 84 | 0 | result = phoneNumber[row].getDescription(); |
| 85 | 0 | break; |
| 86 | 0 | } |
| 87 | 0 | return result; |
| 88 | 0 | } |
| 89 | ||
| 90 | @SuppressWarnings("unchecked") //$NON-NLS-1$ | |
| 91 | 0 | public Class getColumnClass(int column) { |
| 92 | 0 | if (column < 0) |
| 93 | 0 | return null; |
| 94 | 0 | Class result = null; |
| 95 | 0 | switch (column) { |
| 96 | 0 | case PHONENUMBER_ID_COLUMN: |
| 97 | 0 | result = Integer.class; |
| 98 | 0 | break; |
| 99 | 0 | case PHONENUMBER_AREA_CODE_COLUMN: |
| 100 | 0 | result = String.class; |
| 101 | 0 | break; |
| 102 | 0 | case PHONENUMBER_EXCHANGE_COLUMN: |
| 103 | 0 | result = String.class; |
| 104 | 0 | break; |
| 105 | 0 | case PHONENUMBER_NUMBER_COLUMN: |
| 106 | 0 | result = String.class; |
| 107 | 0 | break; |
| 108 | 0 | case PHONENUMBER_DESCRIPTION_COLUMN: |
| 109 | 0 | result = String.class; |
| 110 | 0 | break; |
| 111 | 0 | } |
| 112 | 0 | return result; |
| 113 | 0 | } |
| 114 | ||
| 115 | /* | |
| 116 | * Don't need to implement this method unless your table's editable. | |
| 117 | */ | |
| 118 | 0 | public boolean isCellEditable(int row, int column) { |
| 119 | 0 | if (row < 0 || column < 0) |
| 120 | 0 | return false; |
| 121 | 0 | // Note that the data/cell address is constant, |
| 122 | 0 | // no matter where the cell appears onscreen. |
| 123 | 0 | boolean result = false; |
| 124 | 0 | switch (column) { |
| 125 | 0 | case PHONENUMBER_ID_COLUMN: |
| 126 | 0 | result = false; |
| 127 | 0 | break; |
| 128 | 0 | case PHONENUMBER_AREA_CODE_COLUMN: |
| 129 | 0 | result = true; |
| 130 | 0 | break; |
| 131 | 0 | case PHONENUMBER_EXCHANGE_COLUMN: |
| 132 | 0 | result = true; |
| 133 | 0 | break; |
| 134 | 0 | case PHONENUMBER_NUMBER_COLUMN: |
| 135 | 0 | result = true; |
| 136 | 0 | break; |
| 137 | 0 | case PHONENUMBER_DESCRIPTION_COLUMN: |
| 138 | 0 | result = true; |
| 139 | 0 | break; |
| 140 | 0 | } |
| 141 | 0 | return result; |
| 142 | 0 | } |
| 143 | ||
| 144 | /* | |
| 145 | * Don't need to implement this method unless your table's data can change. | |
| 146 | */ | |
| 147 | 0 | public void setValueAt(Object value, int row, int column) { |
| 148 | 0 | if (row < 0 || column < 0) |
| 149 | 0 | return; |
| 150 | 0 | PhoneNumber phoneNumber = user.getPhoneNumberById(row); |
| 151 | 0 | switch (column) { |
| 152 | 0 | case PHONENUMBER_ID_COLUMN: |
| 153 | 0 | break; |
| 154 | 0 | case PHONENUMBER_AREA_CODE_COLUMN: |
| 155 | 0 | phoneNumber.setAreaCode(value.toString()); |
| 156 | 0 | break; |
| 157 | 0 | case PHONENUMBER_EXCHANGE_COLUMN: |
| 158 | 0 | phoneNumber.setExchange(value.toString()); |
| 159 | 0 | break; |
| 160 | 0 | case PHONENUMBER_NUMBER_COLUMN: |
| 161 | 0 | phoneNumber.setNumber(value.toString()); |
| 162 | 0 | break; |
| 163 | 0 | case PHONENUMBER_DESCRIPTION_COLUMN: |
| 164 | 0 | phoneNumber.setDescription(value.toString()); |
| 165 | 0 | break; |
| 166 | 0 | } |
| 167 | 0 | fireTableCellUpdated(row, column); |
| 168 | 0 | } |
| 169 | 0 | |
| 170 | /* | |
| 171 | * (non-Javadoc) | |
| 172 | * | |
| 173 | * @see java.util.Observer#update(java.util.Observable, java.lang.Object) | |
| 174 | */ | |
| 175 | 0 | public void update(Observable observable, Object changedObject) { |
| 176 | 0 | if (changedObject instanceof NAddress) |
| 177 | 0 | this.fireTableDataChanged(); |
| 178 | 0 | } |
| 179 | 0 | } |
|
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |