| 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.panel; | |
| 21 | ||
| 22 | import java.awt.BorderLayout; | |
| 23 | import java.awt.Dimension; | |
| 24 | import java.awt.GridLayout; | |
| 25 | import java.awt.event.ActionEvent; | |
| 26 | import java.awt.event.ActionListener; | |
| 27 | ||
| 28 | import javax.swing.ImageIcon; | |
| 29 | import javax.swing.JButton; | |
| 30 | import javax.swing.JOptionPane; | |
| 31 | import javax.swing.JPanel; | |
| 32 | import javax.swing.JScrollPane; | |
| 33 | import javax.swing.JTable; | |
| 34 | import javax.swing.border.TitledBorder; | |
| 35 | ||
| 36 | import org.apache.log4j.Logger; | |
| 37 | ||
| 38 | import ui.Messages; | |
| 39 | import ui.command.CommandExecutor; | |
| 40 | import ui.command.creation.ShowNewEAddressDialogCommand; | |
| 41 | import ui.command.deletion.DeleteEAddressCommand; | |
| 42 | import ui.command.information.InfoOnEAddressCommand; | |
| 43 | import ui.table.EAddressTable; | |
| 44 | import ui.table.TableSorter; | |
| 45 | import ui.table.model.EAddressTableModel; | |
| 46 | import base.user.User; | |
| 47 | ||
| 48 | 0 | @SuppressWarnings("serial") //$NON-NLS-1$ |
| 49 | 0 | public class TabledEAddressPanel extends JPanel { |
| 50 | 0 | |
| 51 | 0 | private static final transient Logger logger = Logger |
| 52 | 0 | .getLogger(TabledEAddressPanel.class.getName()); |
| 53 | ||
| 54 | private JTable eAddressTable; | |
| 55 | ||
| 56 | private TableSorter eAddressTableSorter; | |
| 57 | ||
| 58 | private JScrollPane eAddressTableScrollPane; | |
| 59 | ||
| 60 | private EAddressTableModel eAddressTableModel; | |
| 61 | ||
| 62 | private JPanel eAddressButtonPanel; | |
| 63 | ||
| 64 | private JButton newEAddressButton; | |
| 65 | ||
| 66 | private JButton infoOnEAddressButton; | |
| 67 | ||
| 68 | private JButton deleteEAddressButton; | |
| 69 | ||
| 70 | private final User user; | |
| 71 | 0 | |
| 72 | 0 | public TabledEAddressPanel(User user) { |
| 73 | 0 | this.user = user; |
| 74 | 0 | initialize(); |
| 75 | 0 | } |
| 76 | ||
| 77 | 0 | protected void initialize() { |
| 78 | 0 | this.setBorder(new TitledBorder(Messages.getString("common.elettronicmailaddresses"))); //$NON-NLS-1$ |
| 79 | 0 | this.setLayout(new BorderLayout()); |
| 80 | 0 | this.add(getEAddressTableScrollPane(), BorderLayout.CENTER); |
| 81 | 0 | this.add(getEAddressButtonPanel(), BorderLayout.EAST); |
| 82 | 0 | } |
| 83 | ||
| 84 | /** | |
| 85 | * @return Returns the eAddressTable. | |
| 86 | */ | |
| 87 | 0 | protected JTable getEAddressTable() { |
| 88 | 0 | if (eAddressTable == null) { |
| 89 | 0 | eAddressTable = new EAddressTable(getEAddressTableSorter()); |
| 90 | 0 | eAddressTable.setPreferredScrollableViewportSize(new Dimension(500, |
| 91 | 0 | 70)); |
| 92 | 0 | // We need to place it here to avoid a ciclyc call... |
| 93 | 0 | eAddressTableSorter.setTableHeader(eAddressTable.getTableHeader()); |
| 94 | 0 | // Set up tool tips for column headers. |
| 95 | 0 | eAddressTable |
| 96 | 0 | .getTableHeader() |
| 97 | 0 | .setToolTipText( |
| 98 | 0 | Messages.getString("tablesoreter.header.tooltip")); //$NON-NLS-1$ |
| 99 | 0 | } |
| 100 | 0 | return eAddressTable; |
| 101 | } | |
| 102 | ||
| 103 | /** | |
| 104 | * @return Returns the eAddressTableScrollPane. | |
| 105 | */ | |
| 106 | 0 | protected JScrollPane getEAddressTableScrollPane() { |
| 107 | 0 | if (eAddressTableScrollPane == null) { |
| 108 | 0 | eAddressTableScrollPane = new JScrollPane(getEAddressTable()); |
| 109 | 0 | } |
| 110 | 0 | return eAddressTableScrollPane; |
| 111 | } | |
| 112 | ||
| 113 | /** | |
| 114 | * @return Returns the eAddressTableSorter. | |
| 115 | */ | |
| 116 | 0 | protected TableSorter getEAddressTableSorter() { |
| 117 | 0 | if (eAddressTableSorter == null) { |
| 118 | 0 | eAddressTableSorter = new TableSorter(getEAddressTableModel()); |
| 119 | 0 | } |
| 120 | 0 | return eAddressTableSorter; |
| 121 | } | |
| 122 | ||
| 123 | /** | |
| 124 | * @return Returns the eAddressTableModel. | |
| 125 | */ | |
| 126 | 0 | protected EAddressTableModel getEAddressTableModel() { |
| 127 | 0 | if (eAddressTableModel == null) { |
| 128 | 0 | eAddressTableModel = new EAddressTableModel(getUser()); |
| 129 | 0 | } |
| 130 | 0 | return eAddressTableModel; |
| 131 | } | |
| 132 | ||
| 133 | /** | |
| 134 | * @return Returns the eAddressButtonPanel. | |
| 135 | */ | |
| 136 | 0 | protected JPanel getEAddressButtonPanel() { |
| 137 | 0 | if (eAddressButtonPanel == null) { |
| 138 | 0 | eAddressButtonPanel = new JPanel(); |
| 139 | 0 | eAddressButtonPanel.setLayout(new GridLayout(3, 1)); |
| 140 | 0 | eAddressButtonPanel.add(getNewEAddressButton()); |
| 141 | 0 | eAddressButtonPanel.add(getDeleteEAddressButton()); |
| 142 | 0 | eAddressButtonPanel.add(getInfoOnEAddressButton()); |
| 143 | 0 | } |
| 144 | 0 | return eAddressButtonPanel; |
| 145 | } | |
| 146 | ||
| 147 | /** | |
| 148 | * @return Returns the deleteEAddressButton. | |
| 149 | */ | |
| 150 | 0 | protected JButton getDeleteEAddressButton() { |
| 151 | 0 | if (deleteEAddressButton == null) { |
| 152 | 0 | deleteEAddressButton = new JButton(); |
| 153 | 0 | deleteEAddressButton.setIcon(new ImageIcon(this.getClass() |
| 154 | 0 | .getResource("/icon/16x16/actions/list-remove.png"))); //$NON-NLS-1$ |
| 155 | 0 | deleteEAddressButton.addActionListener(new ActionListener() { |
| 156 | public void actionPerformed(ActionEvent arg0) { | |
| 157 | logger.debug("actionPerformed deleteEAddressButton"); //$NON-NLS-1$ | |
| 158 | if (getEAddressTable().getSelectedRow() != -1) { | |
| 159 | int eAddressId = Integer | |
| 160 | .parseInt(((TableSorter) getEAddressTable() | |
| 161 | .getModel()).getValueAt( | |
| 162 | getEAddressTable().getSelectedRow(), | |
| 163 | EAddressTableModel.EADDRESS_ID_COLUMN) | |
| 164 | .toString()); | |
| 165 | CommandExecutor.getInstance().executeCommand( | |
| 166 | new DeleteEAddressCommand(getUser(), | |
| 167 | eAddressId, getEAddressTableModel()), | |
| 168 | false); | |
| 169 | } else | |
| 170 | JOptionPane | |
| 171 | .showMessageDialog( | |
| 172 | null, | |
| 173 | Messages.getString("panel.tabledeaddresspanel.message1"), //$NON-NLS-1$ | |
| 174 | Messages.getString("common.warning"), JOptionPane.WARNING_MESSAGE); //$NON-NLS-1$ | |
| 175 | } | |
| 176 | }); | |
| 177 | 0 | } |
| 178 | 0 | return deleteEAddressButton; |
| 179 | } | |
| 180 | ||
| 181 | /** | |
| 182 | * @return Returns the infoOnEAddressButton. | |
| 183 | */ | |
| 184 | 0 | protected JButton getInfoOnEAddressButton() { |
| 185 | 0 | if (infoOnEAddressButton == null) { |
| 186 | 0 | infoOnEAddressButton = new JButton(); |
| 187 | 0 | infoOnEAddressButton.setIcon(new ImageIcon(this.getClass() |
| 188 | 0 | .getResource("/icon/16x16/status/dialog-information.png"))); //$NON-NLS-1$ |
| 189 | 0 | infoOnEAddressButton.addActionListener(new ActionListener() { |
| 190 | public void actionPerformed(ActionEvent arg0) { | |
| 191 | logger.debug("actionPerformed infoOnEAddressButton"); //$NON-NLS-1$ | |
| 192 | if (getEAddressTable().getSelectedRow() != -1) { | |
| 193 | int eAddressId = Integer | |
| 194 | .parseInt(((TableSorter) getEAddressTable() | |
| 195 | .getModel()).getValueAt( | |
| 196 | getEAddressTable().getSelectedRow(), | |
| 197 | EAddressTableModel.EADDRESS_ID_COLUMN) | |
| 198 | .toString()); | |
| 199 | CommandExecutor.getInstance() | |
| 200 | .executeCommand( | |
| 201 | new InfoOnEAddressCommand(getUser(), | |
| 202 | eAddressId), false); | |
| 203 | } else | |
| 204 | JOptionPane | |
| 205 | .showMessageDialog( | |
| 206 | null, | |
| 207 | Messages.getString("panel.tabledeaddresspanel.message1"), //$NON-NLS-1$ | |
| 208 | Messages.getString("common.warning"), JOptionPane.WARNING_MESSAGE); //$NON-NLS-1$ | |
| 209 | } | |
| 210 | }); | |
| 211 | ||
| 212 | 0 | } |
| 213 | 0 | return infoOnEAddressButton; |
| 214 | } | |
| 215 | ||
| 216 | /** | |
| 217 | * @return Returns the newEAddressButton. | |
| 218 | */ | |
| 219 | 0 | protected JButton getNewEAddressButton() { |
| 220 | 0 | if (newEAddressButton == null) { |
| 221 | 0 | newEAddressButton = new JButton(); |
| 222 | 0 | newEAddressButton.setIcon(new ImageIcon(this.getClass() |
| 223 | 0 | .getResource("/icon/16x16/actions/list-add.png"))); //$NON-NLS-1$ |
| 224 | 0 | |
| 225 | 0 | newEAddressButton.addActionListener(new ActionListener() { |
| 226 | public void actionPerformed(ActionEvent arg0) { | |
| 227 | logger.debug("actionPerformed newEAddressButton"); //$NON-NLS-1$ | |
| 228 | ShowNewEAddressDialogCommand showNewEAddressDialogCommand = new ShowNewEAddressDialogCommand( | |
| 229 | getUser(), getEAddressTableModel()); | |
| 230 | CommandExecutor.getInstance().executeCommand( | |
| 231 | showNewEAddressDialogCommand, false); | |
| 232 | } | |
| 233 | }); | |
| 234 | 0 | } |
| 235 | 0 | return newEAddressButton; |
| 236 | } | |
| 237 | ||
| 238 | /** | |
| 239 | * @return Returns the user. | |
| 240 | */ | |
| 241 | 0 | protected User getUser() { |
| 242 | 0 | return user; |
| 243 | } | |
| 244 | ||
| 245 | } |
|
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |