| 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.EAddress; | |
| 28 | import base.user.NAddress; | |
| 29 | import base.user.User; | |
| 30 | ||
| 31 | /** | |
| 32 | * @author skunk | |
| 33 | * | |
| 34 | */ | |
| 35 | @SuppressWarnings("serial") //$NON-NLS-1$ | |
| 36 | public class EAddressTableModel extends AbstractTableModel { | |
| 37 | 0 | |
| 38 | 0 | String[] columnNames = { Messages.getString("common.id"), Messages.getString("common.address"), Messages.getString("common.description") }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
| 39 | 0 | |
| 40 | public static final int EADDRESS_ID_COLUMN = 0; | |
| 41 | ||
| 42 | private static final int EADDRESS_ADDRESS_COLUMN = 1; | |
| 43 | ||
| 44 | private static final int EADDRESS_DESCRIPTION_COLUMN = 2; | |
| 45 | ||
| 46 | private User user; | |
| 47 | 0 | |
| 48 | 0 | public EAddressTableModel(User user) { |
| 49 | 0 | this.user = user; |
| 50 | 0 | } |
| 51 | 0 | |
| 52 | 0 | public int getColumnCount() { |
| 53 | 0 | return columnNames.length; |
| 54 | 0 | } |
| 55 | ||
| 56 | 0 | public int getRowCount() { |
| 57 | 0 | return user.getEAddress().length; |
| 58 | 0 | } |
| 59 | ||
| 60 | 0 | public String getColumnName(int col) { |
| 61 | 0 | return columnNames[col]; |
| 62 | 0 | } |
| 63 | ||
| 64 | 0 | public Object getValueAt(int row, int column) { |
| 65 | 0 | if (row < 0 || column < 0) |
| 66 | 0 | return null; |
| 67 | 0 | EAddress[] address = user.getEAddress(); |
| 68 | 0 | Object result = null; |
| 69 | 0 | switch (column) { |
| 70 | 0 | case EADDRESS_ID_COLUMN: |
| 71 | 0 | result = address[row].getId(); |
| 72 | 0 | break; |
| 73 | 0 | case EADDRESS_ADDRESS_COLUMN: |
| 74 | 0 | result = address[row].toString(); |
| 75 | 0 | break; |
| 76 | 0 | case EADDRESS_DESCRIPTION_COLUMN: |
| 77 | 0 | result = address[row].getDescription(); |
| 78 | 0 | break; |
| 79 | 0 | } |
| 80 | 0 | return result; |
| 81 | 0 | } |
| 82 | ||
| 83 | @SuppressWarnings("unchecked") //$NON-NLS-1$ | |
| 84 | 0 | public Class getColumnClass(int column) { |
| 85 | 0 | if (column < 0) |
| 86 | 0 | return null; |
| 87 | 0 | Class result = null; |
| 88 | 0 | switch (column) { |
| 89 | 0 | case EADDRESS_ID_COLUMN: |
| 90 | 0 | result = Integer.class; |
| 91 | 0 | break; |
| 92 | 0 | case EADDRESS_ADDRESS_COLUMN: |
| 93 | 0 | result = String.class; |
| 94 | 0 | break; |
| 95 | 0 | case EADDRESS_DESCRIPTION_COLUMN: |
| 96 | 0 | result = String.class; |
| 97 | 0 | break; |
| 98 | 0 | } |
| 99 | 0 | return result; |
| 100 | 0 | } |
| 101 | ||
| 102 | /* | |
| 103 | * Don't need to implement this method unless your table's editable. | |
| 104 | */ | |
| 105 | 0 | public boolean isCellEditable(int row, int column) { |
| 106 | 0 | if (row < 0 || column < 0) |
| 107 | 0 | return false; |
| 108 | 0 | // Note that the data/cell address is constant, |
| 109 | 0 | // no matter where the cell appears onscreen. |
| 110 | 0 | boolean result = false; |
| 111 | 0 | switch (column) { |
| 112 | 0 | case EADDRESS_ID_COLUMN: |
| 113 | 0 | result = false; |
| 114 | 0 | break; |
| 115 | 0 | case EADDRESS_ADDRESS_COLUMN: |
| 116 | 0 | result = false; |
| 117 | 0 | break; |
| 118 | 0 | case EADDRESS_DESCRIPTION_COLUMN: |
| 119 | 0 | result = true; |
| 120 | 0 | break; |
| 121 | 0 | } |
| 122 | 0 | return result; |
| 123 | 0 | } |
| 124 | ||
| 125 | /* | |
| 126 | * Don't need to implement this method unless your table's data can change. | |
| 127 | */ | |
| 128 | 0 | public void setValueAt(Object value, int row, int column) { |
| 129 | 0 | if (row < 0 || column < 0) |
| 130 | 0 | return; |
| 131 | 0 | EAddress[] address = user.getEAddress(); |
| 132 | 0 | switch (column) { |
| 133 | 0 | case EADDRESS_DESCRIPTION_COLUMN: |
| 134 | 0 | address[row].equals(value); |
| 135 | 0 | break; |
| 136 | 0 | } |
| 137 | 0 | fireTableCellUpdated(row, column); |
| 138 | 0 | } |
| 139 | 0 | |
| 140 | /* | |
| 141 | * (non-Javadoc) | |
| 142 | * | |
| 143 | * @see java.util.Observer#update(java.util.Observable, java.lang.Object) | |
| 144 | */ | |
| 145 | 0 | public void update(Observable observable, Object changedObject) { |
| 146 | 0 | if (changedObject instanceof NAddress) |
| 147 | 0 | this.fireTableDataChanged(); |
| 148 | 0 | } |
| 149 | 0 | } |
|
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |