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.ShowNewNAddressDialogCommand; | |
41 | import ui.command.deletion.DeleteNAddressCommand; | |
42 | import ui.command.information.InfoOnNAddressCommand; | |
43 | import ui.table.NAddressTable; | |
44 | import ui.table.TableSorter; | |
45 | import ui.table.model.NAddressTableModel; | |
46 | import base.user.User; | |
47 | ||
48 | 0 | @SuppressWarnings("serial") //$NON-NLS-1$ |
49 | 0 | public class TabledNAddressPanel extends JPanel { |
50 | 0 | |
51 | 0 | private static final transient Logger logger = Logger |
52 | 0 | .getLogger(TabledNAddressPanel.class.getName()); |
53 | ||
54 | private JTable nAddressTable; | |
55 | ||
56 | private TableSorter nAddressTableSorter; | |
57 | ||
58 | private JScrollPane nAddressTableScrollPane; | |
59 | ||
60 | private NAddressTableModel nAddressTableModel; | |
61 | ||
62 | private JPanel nAddressButtonPanel; | |
63 | ||
64 | private JButton newNAddressButton; | |
65 | ||
66 | private JButton infoOnNAddressButton; | |
67 | ||
68 | private JButton deleteNAddressButton; | |
69 | ||
70 | private final User user; | |
71 | 0 | |
72 | 0 | public TabledNAddressPanel(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.normalmailaddresses"))); //$NON-NLS-1$ |
79 | 0 | this.setLayout(new BorderLayout()); |
80 | 0 | this.add(getNAddressTableScrollPane(), BorderLayout.CENTER); |
81 | 0 | this.add(getNAddressButtonPanel(), BorderLayout.EAST); |
82 | 0 | } |
83 | ||
84 | /** | |
85 | * @return Returns the nAddressTable. | |
86 | */ | |
87 | 0 | protected JTable getNAddressTable() { |
88 | 0 | if (nAddressTable == null) { |
89 | 0 | nAddressTable = new NAddressTable(getNAddressTableSorter()); |
90 | 0 | nAddressTable.setPreferredScrollableViewportSize(new Dimension(500, |
91 | 0 | 70)); |
92 | 0 | // We need to place it here to avoid a ciclyc call... |
93 | 0 | nAddressTableSorter.setTableHeader(nAddressTable.getTableHeader()); |
94 | 0 | // Set up tool tips for column headers. |
95 | 0 | nAddressTable |
96 | 0 | .getTableHeader() |
97 | 0 | .setToolTipText( |
98 | 0 | Messages.getString("tablesorter.header.tooltip")); //$NON-NLS-1$ |
99 | 0 | } |
100 | 0 | return nAddressTable; |
101 | } | |
102 | ||
103 | /** | |
104 | * @return Returns the nAddressTableScrollPane. | |
105 | */ | |
106 | 0 | protected JScrollPane getNAddressTableScrollPane() { |
107 | 0 | if (nAddressTableScrollPane == null) { |
108 | 0 | nAddressTableScrollPane = new JScrollPane(getNAddressTable()); |
109 | 0 | } |
110 | 0 | return nAddressTableScrollPane; |
111 | } | |
112 | ||
113 | /** | |
114 | * @return Returns the nAddressTableSorter. | |
115 | */ | |
116 | 0 | protected TableSorter getNAddressTableSorter() { |
117 | 0 | if (nAddressTableSorter == null) { |
118 | 0 | nAddressTableSorter = new TableSorter(getNAddressTableModel()); |
119 | 0 | } |
120 | 0 | return nAddressTableSorter; |
121 | } | |
122 | ||
123 | /** | |
124 | * @return Returns the nAddressTableModel. | |
125 | */ | |
126 | 0 | protected NAddressTableModel getNAddressTableModel() { |
127 | 0 | if (nAddressTableModel == null) { |
128 | 0 | nAddressTableModel = new NAddressTableModel(getUser()); |
129 | 0 | } |
130 | 0 | return nAddressTableModel; |
131 | } | |
132 | ||
133 | /** | |
134 | * @return Returns the nAddressButtonPanel. | |
135 | */ | |
136 | 0 | protected JPanel getNAddressButtonPanel() { |
137 | 0 | if (nAddressButtonPanel == null) { |
138 | 0 | nAddressButtonPanel = new JPanel(); |
139 | 0 | nAddressButtonPanel.setLayout(new GridLayout(3, 1)); |
140 | 0 | nAddressButtonPanel.add(getNewNAddressButton()); |
141 | 0 | nAddressButtonPanel.add(getDeleteNAddressButton()); |
142 | 0 | nAddressButtonPanel.add(getInfoOnNAddressButton()); |
143 | 0 | } |
144 | 0 | return nAddressButtonPanel; |
145 | } | |
146 | ||
147 | /** | |
148 | * @return Returns the deleteNAddressButton. | |
149 | */ | |
150 | 0 | protected JButton getDeleteNAddressButton() { |
151 | 0 | if (deleteNAddressButton == null) { |
152 | 0 | deleteNAddressButton = new JButton(); |
153 | 0 | deleteNAddressButton.setIcon(new ImageIcon(this.getClass() |
154 | 0 | .getResource("/icon/16x16/actions/list-remove.png"))); //$NON-NLS-1$ |
155 | 0 | |
156 | 0 | deleteNAddressButton.addActionListener(new ActionListener() { |
157 | public void actionPerformed(ActionEvent arg0) { | |
158 | logger.debug("actionPerformed deleteNAddressButton"); //$NON-NLS-1$ | |
159 | if (getNAddressTable().getSelectedRow() != -1) { | |
160 | int nAddressId = Integer | |
161 | .parseInt(((TableSorter) getNAddressTable() | |
162 | .getModel()).getValueAt( | |
163 | getNAddressTable().getSelectedRow(), | |
164 | NAddressTableModel.NADDRESS_ID_COLUMN) | |
165 | .toString()); | |
166 | CommandExecutor.getInstance().executeCommand( | |
167 | new DeleteNAddressCommand(getUser(), | |
168 | nAddressId, getNAddressTableModel()), | |
169 | false); | |
170 | } else | |
171 | JOptionPane | |
172 | .showMessageDialog( | |
173 | null, | |
174 | Messages.getString("panel.tablednaddresspanel.message1"), //$NON-NLS-1$ | |
175 | Messages.getString("common.warning"), JOptionPane.WARNING_MESSAGE); //$NON-NLS-1$ | |
176 | } | |
177 | }); | |
178 | 0 | } |
179 | 0 | return deleteNAddressButton; |
180 | } | |
181 | ||
182 | /** | |
183 | * @return Returns the infoOnNAddressButton. | |
184 | */ | |
185 | 0 | protected JButton getInfoOnNAddressButton() { |
186 | 0 | if (infoOnNAddressButton == null) { |
187 | 0 | infoOnNAddressButton = new JButton(); |
188 | 0 | infoOnNAddressButton.setIcon(new ImageIcon(this.getClass() |
189 | 0 | .getResource("/icon/16x16/status/dialog-information.png"))); //$NON-NLS-1$ |
190 | 0 | |
191 | 0 | infoOnNAddressButton.addActionListener(new ActionListener() { |
192 | public void actionPerformed(ActionEvent arg0) { | |
193 | logger.debug("actionPerformed infoOnNAddressButton"); //$NON-NLS-1$ | |
194 | if (getNAddressTable().getSelectedRow() != -1) { | |
195 | int nAddressId = Integer | |
196 | .parseInt(((TableSorter) getNAddressTable() | |
197 | .getModel()).getValueAt( | |
198 | getNAddressTable().getSelectedRow(), | |
199 | NAddressTableModel.NADDRESS_ID_COLUMN) | |
200 | .toString()); | |
201 | CommandExecutor.getInstance() | |
202 | .executeCommand( | |
203 | new InfoOnNAddressCommand(getUser(), | |
204 | nAddressId), false); | |
205 | } else | |
206 | JOptionPane | |
207 | .showMessageDialog( | |
208 | null, | |
209 | Messages.getString("panel.tablednaddresspanel.message1"), //$NON-NLS-1$ | |
210 | Messages.getString("common.warning"), JOptionPane.WARNING_MESSAGE); //$NON-NLS-1$ | |
211 | } | |
212 | }); | |
213 | 0 | } |
214 | 0 | return infoOnNAddressButton; |
215 | } | |
216 | ||
217 | /** | |
218 | * @return Returns the newNAddressButton. | |
219 | */ | |
220 | 0 | protected JButton getNewNAddressButton() { |
221 | 0 | if (newNAddressButton == null) { |
222 | 0 | newNAddressButton = new JButton(); |
223 | 0 | newNAddressButton.setIcon(new ImageIcon(this.getClass() |
224 | 0 | .getResource("/icon/16x16/actions/list-add.png"))); //$NON-NLS-1$ |
225 | 0 | |
226 | 0 | newNAddressButton.addActionListener(new ActionListener() { |
227 | public void actionPerformed(ActionEvent arg0) { | |
228 | logger.debug("actionPerformed newNAddressButton"); //$NON-NLS-1$ | |
229 | ShowNewNAddressDialogCommand showNewNAddressDialogCommand = new ShowNewNAddressDialogCommand( | |
230 | getUser(), getNAddressTableModel()); | |
231 | CommandExecutor.getInstance().executeCommand( | |
232 | showNewNAddressDialogCommand, false); | |
233 | } | |
234 | }); | |
235 | 0 | } |
236 | 0 | return newNAddressButton; |
237 | } | |
238 | ||
239 | /** | |
240 | * @return Returns the user. | |
241 | */ | |
242 | 0 | protected User getUser() { |
243 | 0 | return user; |
244 | } | |
245 | ||
246 | } |
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |