/* * Book Catalog - Catalog your book collection. * * Copyright (C) 2009 Joshua Walters * URL: http://joshwalters.com * * This file is part of Book Catalog. * * Book Catalog is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Book Catalog is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Book Catalog. If not, see . */ package com.joshwalters.bookcatalog; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.sql.SQLException; import javax.swing.JTable; import javax.swing.JTextArea; import javax.swing.JTextField; import com.joshwalters.bookcatalog.bookdatabase.BookDatabase; import com.joshwalters.bookcatalog.bookdatabase.EmptyDatabase; import com.joshwalters.bookcatalog.table.BookCatalogTableModel; /** * Updates a book's entry in the database. * * @author Josh Walters */ class ApplyChanges implements ActionListener { private JTable bookCatalogTable; private BookDatabase bookDatabase; private JTextField titleField; private JTextField authorField; private JTextField dateField; private JTextArea descriptionArea; private JTextField ISBNField; private JTextField priceField; private JTextField publisherField; private JTextField subjectField; private JTextArea notesArea; /** * Get the different objects needed for the class to function. * * @param bookCatalogTable * @param bookDatabase * @param titleField * @param authorField * @param dateField * @param descriptionArea * @param ISBNField * @param priceField * @param publisherField * @param subjectField * @param notesArea */ ApplyChanges(JTable bookCatalogTable, BookDatabase bookDatabase, JTextField titleField, JTextField authorField, JTextField dateField, JTextArea descriptionArea, JTextField ISBNField, JTextField priceField, JTextField publisherField, JTextField subjectField, JTextArea notesArea) { this.bookCatalogTable = bookCatalogTable; this.bookDatabase = bookDatabase; this.titleField = titleField; this.authorField = authorField; this.dateField = dateField; this.descriptionArea = descriptionArea; this.ISBNField = ISBNField; this.priceField = priceField; this.publisherField = publisherField; this.subjectField = subjectField; this.notesArea = notesArea; } /** * The user hit the "Apply Changes" button, update the book entry. */ public void actionPerformed(ActionEvent arg) { try { // Update the book entry. bookDatabase.updateBook(titleField.getText(), authorField.getText(), dateField.getText(), descriptionArea .getText(), ISBNField.getText(), priceField .getText(), publisherField.getText(), subjectField .getText(), notesArea.getText()); // Get the table model. BookCatalogTableModel bookCatalogTableModel = (BookCatalogTableModel) bookCatalogTable .getModel(); // Update the table's data. bookCatalogTableModel.setData(bookDatabase.getDatabaseForTable()); // Refresh the table. bookCatalogTableModel.fireTableDataChanged(); } catch (SQLException e) { // There was an SQL error. System.err.println(e.getLocalizedMessage()); } catch (EmptyDatabase e) { // The database was empty. System.err.println(e.getLocalizedMessage()); } } }