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