| 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 | import java.io.File; | |
| 29 | ||
| 30 | import javax.swing.ImageIcon; | |
| 31 | import javax.swing.JButton; | |
| 32 | import javax.swing.JLabel; | |
| 33 | 0 | import javax.swing.JOptionPane; |
| 34 | import javax.swing.JPanel; | |
| 35 | 0 | import javax.swing.JScrollPane; |
| 36 | import javax.swing.JTable; | |
| 37 | 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.IO.LoadBackupCommand; | |
| 44 | import ui.command.creation.ShowNewBackupCommand; | |
| 45 | import ui.command.deletion.DeleteBackupCommand; | |
| 46 | import ui.table.BackupTable; | |
| 47 | import ui.table.TableSorter; | |
| 48 | import ui.table.model.BackupTableModel; | |
| 49 | import base.ConfigurationManager; | |
| 50 | import base.InternetCafeManager; | |
| 51 | import base.backup.Backup; | |
| 52 | ||
| 53 | 0 | @SuppressWarnings("serial") //$NON-NLS-1$ |
| 54 | 0 | public class TabledBackupPanel extends JPanel { |
| 55 | 0 | |
| 56 | 0 | private static final transient Logger logger = Logger |
| 57 | 0 | .getLogger(TabledBackupPanel.class.getName()); |
| 58 | 0 | |
| 59 | private JTable backUpHistoryTable; | |
| 60 | ||
| 61 | 0 | private JScrollPane backUpHistoryTableScrollPane; |
| 62 | 0 | |
| 63 | 0 | private TableSorter backUpHistoryTableSorter; |
| 64 | 0 | |
| 65 | 0 | private BackupTableModel backUpHistoryTableModel; |
| 66 | 0 | |
| 67 | private JPanel backUpButtonPanel; | |
| 68 | ||
| 69 | private JButton newBackUpButton; | |
| 70 | ||
| 71 | private JButton restoreBackUpButton; | |
| 72 | 0 | |
| 73 | 0 | private JButton loadBackUpButton; |
| 74 | 0 | |
| 75 | private JButton deleteBackUpButton; | |
| 76 | 0 | |
| 77 | 0 | public TabledBackupPanel() { |
| 78 | 0 | initialize(); |
| 79 | 0 | } |
| 80 | 0 | |
| 81 | 0 | protected void initialize() { |
| 82 | 0 | TitledBorder titledBorder = new TitledBorder(Messages.getString("panel.backuppanel.backuphistory")); //$NON-NLS-1$ |
| 83 | 0 | this.setBorder(titledBorder); |
| 84 | 0 | this.setLayout(new BorderLayout()); |
| 85 | 0 | this.add(getBackUpHistoryTableScrollPane(), BorderLayout.CENTER); |
| 86 | 0 | this.add(getBackUpButtonPanel(), BorderLayout.EAST); |
| 87 | 0 | } |
| 88 | ||
| 89 | /** | |
| 90 | * @return Returns the backUpHistoryTable. | |
| 91 | */ | |
| 92 | 0 | protected JTable getBackUpHistoryTable() { |
| 93 | 0 | if (backUpHistoryTable == null) { |
| 94 | 0 | backUpHistoryTable = new BackupTable(getUserTableSorter()); |
| 95 | 0 | backUpHistoryTable |
| 96 | 0 | .setPreferredScrollableViewportSize(new Dimension(500, 70)); |
| 97 | 0 | // We need to place it here to avoid a ciclyc call... |
| 98 | 0 | backUpHistoryTableSorter.setTableHeader(backUpHistoryTable |
| 99 | 0 | .getTableHeader()); |
| 100 | 0 | // Set up tool tips for column headers. |
| 101 | 0 | backUpHistoryTable |
| 102 | 0 | .getTableHeader() |
| 103 | 0 | .setToolTipText( |
| 104 | 0 | Messages.getString("tablesorter.header.tooltip")); //$NON-NLS-1$ |
| 105 | 0 | } |
| 106 | 0 | return backUpHistoryTable; |
| 107 | 0 | } |
| 108 | ||
| 109 | /** | |
| 110 | * @return Returns the backUpHistoryTableScrollPane. | |
| 111 | */ | |
| 112 | 0 | protected JScrollPane getBackUpHistoryTableScrollPane() { |
| 113 | 0 | if (backUpHistoryTableScrollPane == null) { |
| 114 | 0 | backUpHistoryTableScrollPane = new JScrollPane( |
| 115 | 0 | getBackUpHistoryTable()); |
| 116 | 0 | } |
| 117 | 0 | return backUpHistoryTableScrollPane; |
| 118 | } | |
| 119 | ||
| 120 | /** | |
| 121 | * @return Returns the backUpHistoryTableSorter. | |
| 122 | */ | |
| 123 | 0 | protected TableSorter getUserTableSorter() { |
| 124 | 0 | if (backUpHistoryTableSorter == null) { |
| 125 | 0 | backUpHistoryTableSorter = new TableSorter( |
| 126 | 0 | getBackUpHistoryTableModel()); |
| 127 | 0 | } |
| 128 | 0 | return backUpHistoryTableSorter; |
| 129 | 0 | } |
| 130 | 0 | |
| 131 | 0 | /** |
| 132 | 0 | * @return Returns the backUpHistoryTableModel. |
| 133 | */ | |
| 134 | 0 | protected BackupTableModel getBackUpHistoryTableModel() { |
| 135 | 0 | if (backUpHistoryTableModel == null) { |
| 136 | 0 | backUpHistoryTableModel = new BackupTableModel(); |
| 137 | 0 | } |
| 138 | 0 | return backUpHistoryTableModel; |
| 139 | } | |
| 140 | ||
| 141 | 0 | /** |
| 142 | 0 | * @return Returns the backUpButtonPanel. |
| 143 | 0 | */ |
| 144 | 0 | protected JPanel getBackUpButtonPanel() { |
| 145 | 0 | if (backUpButtonPanel == null) { |
| 146 | 0 | backUpButtonPanel = new JPanel(); |
| 147 | 0 | backUpButtonPanel.setLayout(new GridLayout(6, 1)); |
| 148 | 0 | backUpButtonPanel.add(new JLabel("")); //$NON-NLS-1$ |
| 149 | 0 | backUpButtonPanel.add(getNewBackUpButton()); |
| 150 | 0 | backUpButtonPanel.add(getLoadBackUpButton()); |
| 151 | 0 | backUpButtonPanel.add(getRestoreBackUpButton()); |
| 152 | 0 | backUpButtonPanel.add(getDeleteBackUpButton()); |
| 153 | 0 | backUpButtonPanel.add(new JLabel("")); //$NON-NLS-1$ |
| 154 | 0 | } |
| 155 | 0 | return backUpButtonPanel; |
| 156 | } | |
| 157 | ||
| 158 | /** | |
| 159 | * @return Returns the deleteBackUpButton. | |
| 160 | */ | |
| 161 | 0 | protected JButton getDeleteBackUpButton() { |
| 162 | 0 | if (deleteBackUpButton == null) { |
| 163 | 0 | deleteBackUpButton = new JButton(Messages.getString("button.delete")); //$NON-NLS-1$ |
| 164 | 0 | deleteBackUpButton.setIcon(new ImageIcon(this.getClass() |
| 165 | 0 | .getResource("/icon/22x22/actions/edit-delete.png"))); //$NON-NLS-1$ |
| 166 | 0 | |
| 167 | 0 | deleteBackUpButton.addActionListener(new ActionListener() { |
| 168 | 0 | public void actionPerformed(ActionEvent arg0) { |
| 169 | logger.debug("actionPerformed deleteBackUpButton"); //$NON-NLS-1$ | |
| 170 | if (getBackUpHistoryTable().getSelectedRow() != -1) { | |
| 171 | int backupId = Integer | |
| 172 | .parseInt(((TableSorter) getBackUpHistoryTable() | |
| 173 | .getModel()).getValueAt( | |
| 174 | getBackUpHistoryTable() | |
| 175 | 0 | .getSelectedRow(), |
| 176 | 0 | BackupTableModel.BACKUP_ID_COLUMN) |
| 177 | 0 | .toString()); |
| 178 | CommandExecutor.getInstance().executeCommand( | |
| 179 | new DeleteBackupCommand(backupId), false); | |
| 180 | 0 | } else |
| 181 | JOptionPane | |
| 182 | .showMessageDialog( | |
| 183 | null, | |
| 184 | Messages.getString("panel.tabledbackuppanel.message1"), //$NON-NLS-1$ | |
| 185 | Messages.getString("common.warning"), JOptionPane.WARNING_MESSAGE); //$NON-NLS-1$ | |
| 186 | } | |
| 187 | }); | |
| 188 | 0 | } |
| 189 | 0 | return deleteBackUpButton; |
| 190 | } | |
| 191 | ||
| 192 | /** | |
| 193 | * @return Returns the loadBackUpButton. | |
| 194 | */ | |
| 195 | 0 | protected JButton getLoadBackUpButton() { |
| 196 | 0 | if (loadBackUpButton == null) { |
| 197 | 0 | loadBackUpButton = new JButton(Messages.getString("button.load")); //$NON-NLS-1$ |
| 198 | 0 | loadBackUpButton.setIcon(new ImageIcon(this.getClass().getResource( |
| 199 | 0 | "/icon/22x22/actions/document-open.png"))); //$NON-NLS-1$ |
| 200 | 0 | |
| 201 | 0 | loadBackUpButton.addActionListener(new ActionListener() { |
| 202 | public void actionPerformed(ActionEvent arg0) { | |
| 203 | logger.debug("actionPerformed loadBackUpButton"); //$NON-NLS-1$ | |
| 204 | CommandExecutor.getInstance().executeCommand( | |
| 205 | new LoadBackupCommand(), false); | |
| 206 | } | |
| 207 | }); | |
| 208 | 0 | } |
| 209 | 0 | return loadBackUpButton; |
| 210 | } | |
| 211 | ||
| 212 | /** | |
| 213 | * @return Returns the newBackUpButton. | |
| 214 | */ | |
| 215 | 0 | protected JButton getNewBackUpButton() { |
| 216 | 0 | if (newBackUpButton == null) { |
| 217 | 0 | newBackUpButton = new JButton(Messages.getString("button.new")); //$NON-NLS-1$ |
| 218 | 0 | newBackUpButton.setIcon(new ImageIcon(this.getClass().getResource( |
| 219 | 0 | "/icon/22x22/actions/document-new.png"))); //$NON-NLS-1$ |
| 220 | 0 | |
| 221 | 0 | newBackUpButton.addActionListener(new ActionListener() { |
| 222 | public void actionPerformed(ActionEvent arg0) { | |
| 223 | logger.debug("actionPerformed newBackUpButton"); //$NON-NLS-1$ | |
| 224 | CommandExecutor.getInstance().executeCommand( | |
| 225 | new ShowNewBackupCommand(), false); | |
| 226 | } | |
| 227 | }); | |
| 228 | 0 | } |
| 229 | 0 | return newBackUpButton; |
| 230 | } | |
| 231 | ||
| 232 | /** | |
| 233 | * @return Returns the restoreBackUpButton. | |
| 234 | */ | |
| 235 | 0 | protected JButton getRestoreBackUpButton() { |
| 236 | 0 | if (restoreBackUpButton == null) { |
| 237 | 0 | restoreBackUpButton = new JButton(Messages.getString("button.restore")); //$NON-NLS-1$ |
| 238 | 0 | restoreBackUpButton.setIcon(new ImageIcon(this.getClass() |
| 239 | 0 | .getResource("/icon/22x22/actions/view-refresh.png"))); //$NON-NLS-1$ |
| 240 | 0 | |
| 241 | 0 | restoreBackUpButton.addActionListener(new ActionListener() { |
| 242 | public void actionPerformed(ActionEvent arg0) { | |
| 243 | logger.debug("actionPerformed restoreBackUpButton"); //$NON-NLS-1$ | |
| 244 | if (getBackUpHistoryTable().getSelectedRow() != -1) { | |
| 245 | Object[] options = { Messages.getString("TabledBackupPanel.19"), //$NON-NLS-1$ | |
| 246 | Messages.getString("TabledBackupPanel.20") }; //$NON-NLS-1$ | |
| 247 | int result = JOptionPane | |
| 248 | .showOptionDialog( | |
| 249 | null, | |
| 250 | Messages.getString("panel.tabledbackuppanel.message2"), //$NON-NLS-1$ | |
| 251 | Messages.getString("panel.tabledbackuppanel.backuprestore"), //$NON-NLS-1$ | |
| 252 | JOptionPane.YES_NO_OPTION, | |
| 253 | JOptionPane.QUESTION_MESSAGE, null, | |
| 254 | options, options[1]); | |
| 255 | if (result == JOptionPane.YES_OPTION) { | |
| 256 | int backupId = Integer | |
| 257 | .parseInt(((TableSorter) getBackUpHistoryTable() | |
| 258 | .getModel()).getValueAt( | |
| 259 | getBackUpHistoryTable() | |
| 260 | .getSelectedRow(), | |
| 261 | BackupTableModel.BACKUP_ID_COLUMN) | |
| 262 | .toString()); | |
| 263 | Backup backup = InternetCafeManager.getInstance() | |
| 264 | .getBackupById(backupId); | |
| 265 | if (backup != null) { | |
| 266 | if (new File(backup.getDbLocationPath()) | |
| 267 | .exists()) { | |
| 268 | ConfigurationManager.getInstance() | |
| 269 | .setDataBasePath( | |
| 270 | backup.getDbLocationPath()); | |
| 271 | InternetCafeManager.getInstance().clear(); | |
| 272 | InternetCafeManager.getInstance() | |
| 273 | 0 | .retrieve(); |
| 274 | } else | |
| 275 | JOptionPane | |
| 276 | .showMessageDialog( | |
| 277 | null, | |
| 278 | Messages.getString("panel.tabledbackuppanel.message3"), //$NON-NLS-1$ | |
| 279 | Messages.getString("common.error"), //$NON-NLS-1$ | |
| 280 | JOptionPane.ERROR_MESSAGE); | |
| 281 | } else | |
| 282 | logger.error(Messages.getString("BIG PROBLEM HERE!")); //$NON-NLS-1$ | |
| 283 | } | |
| 284 | } else | |
| 285 | JOptionPane | |
| 286 | .showMessageDialog( | |
| 287 | null, | |
| 288 | Messages.getString("panel.tabledbackuppanel.message1"), //$NON-NLS-1$ | |
| 289 | Messages.getString("common.warning"), JOptionPane.WARNING_MESSAGE); //$NON-NLS-1$ | |
| 290 | } | |
| 291 | }); | |
| 292 | ||
| 293 | 0 | } |
| 294 | 0 | return restoreBackUpButton; |
| 295 | } | |
| 296 | ||
| 297 | } |
|
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |