* @param key Key to return
* @return Human-readable message
*/
+ @Override
public final String getMessageStringFromKey (final String key) {
// Return message
return this.getBundle().getString(key);
}
+
+ /**
+ * Aborts program with given exception
+ *
+ * @param throwable Any type of Throwable
+ */
+ protected final void abortProgramWithException (final Throwable throwable) {
+ // Log exception ...
+ this.getLogger().catching(throwable);
+
+ // .. and exit
+ System.exit(1);
+
+ }
}
// Ignore it
}
}
- // --- Main loop ends here ---
+ // --- Main loop ends here ---
// Debug message
this.getLogger().debug("Main loop exit - shutting down ..."); //NOI18N
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.DefaultComboBoxModel;
-import javax.swing.InputVerifier;
+import javax.swing.JButton;
import javax.swing.JComboBox;
-import javax.swing.JComponent;
import javax.swing.JDialog;
+import javax.swing.JFormattedTextField;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
+import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.border.TitledBorder;
import javax.swing.table.TableModel;
/**
* Whether this frame has been initialized
*/
- private boolean isInitialized;
-
- /**
- * Layout instance
- */
- private GridLayout layout;
+ private boolean initialized;
/**
* Status label needs to be updated
// Is the "add contact" window visible?
if (this.addContact.isVisible()) {
// Something bad happened
- throw new IllegalStateException("Window addContact is already visible.");
+ throw new IllegalStateException("Window addContact is already visible."); //NOI18N
}
// Disable main window
this.initComponents();
// Set flag
- this.isInitialized = true;
+ this.initialized = true;
// Trace message
this.getLogger().trace("EXIT!"); //NOI18N
*/
@Override
public final boolean isInitialized () {
- return this.isInitialized;
+ return this.initialized;
}
/**
this.getLogger().trace("EXIT!"); //NOI18N
}
+ /**
+ * Adds a JTextField with label and tool tip to given panel
+ *
+ * @param panel Panel instance to add text field
+ * @param key Part of message key from resource bundle
+ * @param fieldLength Length of text field
+ */
+ private void addTextFieldWithLabelToPanel (final JPanel panel, final String key, final int fieldLength) {
+ // Trace message
+ this.getLogger().trace(MessageFormat.format("panel={0},key={1},fieldLength={2} - CALLED!", panel, key, fieldLength)); //NOI18N
+
+ // Init label for given key
+ JLabel label = new JLabel(this.getBundle().getString(String.format("AddressbookFrame.%s.text", key))); //NOI18N
+
+ // And input box wih tool tip
+ JTextField field = new JTextField(fieldLength);
+ field.setToolTipText(this.getBundle().getString(String.format("AddressbookFrame.%s.toolTipText", key))); //NOI18N
+
+ // Add both to panel
+ panel.add(label);
+ panel.add(field);
+
+ // Trace message
+ this.getLogger().trace("EXIT!"); //NOI18N
+ }
+
/**
* Generates a title for borders
*
* Initializes "add" and "cancel" buttons
*/
private void initAddCancelButtons () {
+ // Trace message
+ this.getLogger().trace("CALLED!"); //NOI18N
+
+ // Init panel
+ JPanel panel = new JPanel();
+ panel.setLayout(new GridLayout(1, 2, 10, 10));
+
+ // Generate "add" button
+ JButton addButton = new JButton(this.getBundle().getString("AddressbookFrame.button.addAddress.text"));
+
+ // Add listener
+ addButton.addActionListener(new AddActionListener(this.addContact, this));
+
+ // Add button to panel
+ panel.add(addButton);
+
+ // Generate "cancel" button
+ JButton cancelButton = new JButton(this.getBundle().getString("AddressbookFrame.button.cancel.text"));
+
+ // Add listener
+ cancelButton.addActionListener(new CancelActionListener(this.addContact, this));
+
+ // Add button to panel
+ panel.add(cancelButton);
+
+ // Add panel to main panel
+ this.addContact.add(panel);
+
+ // Trace message
+ this.getLogger().trace("EXIT!"); //NOI18N
}
/**
*/
private void initAddContactDialog () {
// Trace message
- this.getLogger().trace("EXIT!"); //NOI18N
+ this.getLogger().trace("CALLED!"); //NOI18N
// Instance dialog and set title
this.addContact = new JDialog();
// 3) "other" panel
initOtherDataPanel(this.addContact);
- // 4) "Add" and "Cancel" buttons
+ // 4) "Add" and "Cancel" buttons, combined they are unique for this dialog
initAddCancelButtons();
// x)Only for developing:
// Panel "address" input boxes
JPanel addressPanel = new JPanel();
- addressPanel.setLayout(new BoxLayout(addressPanel, BoxLayout.Y_AXIS));
+ addressPanel.setLayout(new GridLayout(0, 4, 3, 3));
// Set border to titled version
addressPanel.setBorder(new TitledBorder(this.generateBorderTitle("address"))); //NOI18N
- // Init all elements:
- // 1) Street and number together
- JPanel streetNumberPanel = new JPanel();
- streetNumberPanel.setLayout(new GridLayout(1, 4, 5, 5));
-
- // Label for street
- JLabel streetLabel = new JLabel(this.getBundle().getString("AddressbookFrame.street.text"));
-
- // Init text field with label
- JTextField street = new JTextField(20);
- street.setToolTipText(this.getBundle().getString("AddressbookFrame.street.tooltipText"));
-
- // Add both to street panel
- streetNumberPanel.add(streetLabel);
- streetNumberPanel.add(street);
+ // Add text field for street
+ this.addTextFieldWithLabelToPanel(addressPanel, "street", 20); //NOI18N
// Number label
JLabel numberLabel = new JLabel(this.getBundle().getString("AddressbookFrame.number.text"));
// And text field, but only accept numbers
- JTextField number = new JTextField(4);
- number.setToolTipText(this.getBundle().getString("AddressbookFrame.number.tooltipText"));
-
- // Add number verifier
- number.setInputVerifier(new InputVerifier() {
-
- /**
- * Method to verify that the entered data is a number.
- *
- * @param input Input to verify
- * @return Whether the data is a number
- */
- @Override
- public boolean verify (final JComponent input) {
- // Cast on text field
- JTextField text = (JTextField) input;
-
- // Default is passed
- boolean isValid = true;
-
- // Try to convert input text to a number
- try {
- int num = Integer.valueOf(text.getText());
- } catch (final NumberFormatException ex) {
- // Didn't work
- isValid = false;
- }
-
- // Return status
- return isValid;
- }
- });
+ JFormattedTextField number = new JFormattedTextField();
+ number.setToolTipText(this.getBundle().getString("AddressbookFrame.number.toolTipText"));
// Add both to street panel
- streetNumberPanel.add(numberLabel);
- streetNumberPanel.add(number);
-
- // Add panel to address panel
- addressPanel.add(streetNumberPanel);
-
- // 2) ZIP code and ccity name
- JPanel zipCityPanel = new JPanel();
- zipCityPanel.setLayout(new GridLayout(1, 4, 5, 5));
+ addressPanel.add(numberLabel);
+ addressPanel.add(number);
// Label for ZIP code, again numbers only
JLabel zipLabel = new JLabel(this.getBundle().getString("AddressbookFrame.zip.text"));
// Init text field with label
- JTextField zip = new JTextField(20);
- zip.setToolTipText(this.getBundle().getString("AddressbookFrame.zip.tooltipText"));
-
- // Add number verifier
- zip.setInputVerifier(new InputVerifier() {
-
- /**
- * Method to verify that the entered data is a number.
- *
- * @param input Input to verify
- * @return Whether the data is a number
- */
- @Override
- public boolean verify (final JComponent input) {
- // Cast on text field
- JTextField text = (JTextField) input;
-
- // Default is passed
- boolean isValid = true;
-
- // Try to convert input text to a number
- try {
- int num = Integer.valueOf(text.getText());
- } catch (final NumberFormatException ex) {
- // Didn't work
- isValid = false;
- }
-
- // Return status
- return isValid;
- }
- });
-
- // Add both to street panel
- zipCityPanel.add(zipLabel);
- zipCityPanel.add(zip);
-
- // Label for street
- JLabel cityLabel = new JLabel(this.getBundle().getString("AddressbookFrame.city.text"));
-
- // Init text field with label
- JTextField city = new JTextField(20);
- city.setToolTipText(this.getBundle().getString("AddressbookFrame.city.tooltipText"));
+ JFormattedTextField zip = new JFormattedTextField();
+ zip.setToolTipText(this.getBundle().getString("AddressbookFrame.zip.toolTipText"));
// Add both to street panel
- zipCityPanel.add(cityLabel);
- zipCityPanel.add(city);
+ addressPanel.add(zipLabel);
+ addressPanel.add(zip);
- // Add panel to address panel
- addressPanel.add(zipCityPanel);
+ // Add text field for city name
+ this.addTextFieldWithLabelToPanel(addressPanel, "city", 20); //NOI18N
// Add panel to dialog
dialog.add(addressPanel);
this.getLogger().trace("EXIT!"); //NOI18N
}
+ /**
+ * Initializes a menu item instance with tool tip
+ *
+ * @param key Message key part
+ * @return A finished JMenuItem instance
+ */
+ private JMenuItem initMenuItemWithTooltip (final String key) {
+ // Debug line
+ this.getLogger().trace(MessageFormat.format("key={0} - CALLED!", key)); //NOI18N
+
+ JMenuItem item = new JMenuItem(this.getBundle().getString(String.format("AddressbookFrame.menuItem.%s.text", key))); //NOI18N
+ item.setToolTipText(this.getBundle().getString(String.format("AddressbookFrame.menuItem.%s.toolTipText", key))); //NOI18N
+
+ // Trace message
+ this.getLogger().trace(MessageFormat.format("item={0} - EXIT!", item)); //NOI18N
+
+ // Return it
+ return item;
+ }
+
/**
* Initializes the menu system
*/
// Add menu items:
// 1.x) Exit program (should be last)
- item = new JMenuItem(this.getBundle().getString("AddressbookFrame.menuItem.exitProgram.text"));
- item.setToolTipText(this.getBundle().getString("AddressbookFrame.menuItem.exitProgram.toolTipText"));
-
- // Add listener to exit menu
- item.addActionListener(new ActionListener() {
+ this.addMenuItem(menu, "exitProgram", new ActionListener() { //NOI18N
/**
* If the user has performed this action
*
}
});
- // Add item -> menu
- menu.add(item);
-
// Add menu -> menu bar
menuBar.add(menu);
menu = new JMenu(this.getBundle().getString("AddressbookFrame.menu.addressbook.text"));
// 2.1) Add own data
- this.addOwnItem = new JMenuItem(this.getBundle().getString("AddressbookFrame.menuItem.addOwnData.text"));
- this.addOwnItem.setToolTipText(this.getBundle().getString("AddressbookFrame.menuItem.addOwnData.toolTipText"));
+ this.addOwnItem = this.initMenuItemWithTooltip("addOwnData"); //NOI18N
// Add listener to exit menu
this.addOwnItem.addActionListener(new ActionListener() {
menu.add(this.addOwnItem);
// 2.2) Edit own data
- this.editOwnItem = new JMenuItem(this.getBundle().getString("AddressbookFrame.menuItem.editOwnData.text"));
- this.editOwnItem.setToolTipText(this.getBundle().getString("AddressbookFrame.menuItem.editOwnData.toolTipText"));
+ this.editOwnItem = this.initMenuItemWithTooltip("editOwnData"); //NOI18N
// Add listener to exit menu
this.editOwnItem.addActionListener(new ActionListener() {
// Add item -> menu
menu.add(this.editOwnItem);
+ // Init more menus:
+ // 1) Add new contact
+ this.addMenuItem(menu, "addNewContact", new ActionListener() { //NOI18N
+ /**
+ * If the user has performed this action
+ *
+ * @param e An instance of an ActionEvent class
+ */
+ @Override
+ public void actionPerformed (final ActionEvent e) {
+ self.getClient().getContactManager().doAddOtherAddress();
+ }
+ });
+
// Add menu -> menu bar
menuBar.add(menu);
this.getLogger().trace("EXIT!"); //NOI18N
}
+ /**
+ * Adds a new menu item with given key to menu instance
+ *
+ * @param menu Menu instance to add item to
+ * @param key Message key part
+ * @param listener Listener instance
+ */
+ private void addMenuItem (final JMenu menu, final String key, final ActionListener listener) {
+ // Trace message
+ this.getLogger().trace(MessageFormat.format("menu={0},key={1},listener={2} - CALLED!", menu, key, listener)); //NOI18N
+
+ // New instance
+ JMenuItem item = this.initMenuItemWithTooltip(key);
+
+ // Add listener
+ item.addActionListener(listener);
+
+ // Add item -> menu
+ menu.add(item);
+
+ // Trace message
+ this.getLogger().trace("EXIT!"); //NOI18N
+ }
+
/**
* Initializes name panel
*
*/
private void initNameDataPanel (final JDialog dialog) {
// Trace message
- this.getLogger().trace("CALLED!"); //NOI18N
+ this.getLogger().trace(MessageFormat.format("dialog={0} - CALLED!", dialog)); //NOI18N
// Panel "name" input boxes
JPanel namePanel = new JPanel();
- namePanel.setLayout(new BoxLayout(namePanel, BoxLayout.Y_AXIS));
+ namePanel.setLayout(new GridLayout(0, 2, 3, 3));
// Set border to titled version
namePanel.setBorder(new TitledBorder(this.generateBorderTitle("name"))); //NOI18N
- // Panel for gender
- JPanel gPanel = new JPanel();
- gPanel.setLayout(new GridLayout(1, 2, 5, 5));
-
// Gender text field
JLabel gLabel = new JLabel(this.getBundle().getString("AddressbookFrame.gender.text"));
// Init gender combo box with tool tip
JComboBox<Gender> gender = new JComboBox<>(new DefaultComboBoxModel<>(genders));
- gender.setToolTipText(this.getBundle().getString("AddressbookFrame.gender.tooltipText"));
+ gender.setToolTipText(this.getBundle().getString("AddressbookFrame.gender.toolTipText"));
// Add both to gender panel
- gPanel.add(gLabel);
- gPanel.add(gender);
-
- // Add gender panel to "name" panel
- namePanel.add(gPanel);
-
- // Panel for surname
- JPanel sPanel = new JPanel();
- sPanel.setLayout(new GridLayout(1, 2, 5, 5));
-
- // New label for surname is not needed
- JLabel sLabel = new JLabel(this.getBundle().getString("AddressbookFrame.surname.text"));
-
- // And input box wih tool tip
- JTextField surname = new JTextField(20);
- surname.setToolTipText(this.getBundle().getString("AddressbookFrame.surname.tooltipText"));
-
- // Add both to surname panel
- sPanel.add(sLabel);
- sPanel.add(surname);
-
- // Add surname panel to "name" panel
- namePanel.add(sPanel);
+ namePanel.add(gLabel);
+ namePanel.add(gender);
- // Panel for surname
- JPanel fPanel = new JPanel();
- fPanel.setLayout(new GridLayout(1, 2));
+ // Add text field for surname
+ this.addTextFieldWithLabelToPanel(namePanel, "surname", 20); //NOI18N
- // New label for surname is not needed
- JLabel fLabel = new JLabel(this.getBundle().getString("AddressbookFrame.familyName.text"));
-
- // And input box wih tool tip
- JTextField familyName = new JTextField(20);
- familyName.setToolTipText(this.getBundle().getString("AddressbookFrame.familyName.tooltipText"));
-
- // Add both to surname panel
- fPanel.add(fLabel);
- fPanel.add(familyName);
-
- // Add family namepanel to "name" panel
- namePanel.add(fPanel);
+ // Add text field for family name
+ this.addTextFieldWithLabelToPanel(namePanel, "familyName", 20); //NOI18N
// Finally add panel to dialog
dialog.add(namePanel);
*/
private void initOtherDataPanel (final JDialog dialog) {
// Trace message
- this.getLogger().trace("CALLED!"); //NOI18N
+ this.getLogger().trace(MessageFormat.format("dialog={0} - CALLED!", dialog)); //NOI18N
// Panel "other" input boxes
JPanel otherPanel = new JPanel();
- otherPanel.setLayout(new BoxLayout(otherPanel, BoxLayout.Y_AXIS));
-
- // Set border to titled version
+ otherPanel.setLayout(new GridLayout(0, 2, 3, 3));
otherPanel.setBorder(new TitledBorder(this.generateBorderTitle("other"))); //NOI18N
+ // Add text field for email address
+ this.addTextFieldWithLabelToPanel(otherPanel, "emailAddress", 20); //NOI18N
+
+ // Add text field for phone number
+ this.addTextFieldWithLabelToPanel(otherPanel, "phoneNumber", 20); //NOI18N
+
+ // Add text field for cellphone number
+ this.addTextFieldWithLabelToPanel(otherPanel, "cellphoneNumber", 20); //NOI18N
+
+ // Add text field for fax number
+ this.addTextFieldWithLabelToPanel(otherPanel, "faxNumber", 20); //NOI18N
+
+ // Init label
+ JLabel commentLabel = new JLabel(this.getBundle().getString("AddressbookFrame.comment.text"));
+
+ // Init text area with tool tip
+ JTextArea comment = new JTextArea(5, 20);
+ comment.setToolTipText(this.getBundle().getString("AddressbookFrame.comment.toolTipText"));
+
+ // Add both to panel
+ otherPanel.add(commentLabel);
+ otherPanel.add(comment);
+
// Finally add panel to dialog
dialog.add(otherPanel);
// Trace message
this.getLogger().trace("EXIT!"); //NOI18N
}
+
+ /**
+ * Class for "add address" button
+ */
+ private static class AddActionListener extends BaseFrameworkSystem implements ActionListener {
+ /**
+ * Dialog instance
+ */
+ private final JDialog dialog;
+
+ /**
+ * Frame (not JFrame) instance
+ */
+ private final ClientFrame frame;
+
+ /**
+ * Constructor for action listener
+ *
+ * @param dialog Dialog instance to call back
+ * @param frame Frame instance (not JFrame)
+ */
+ protected AddActionListener (final JDialog dialog, final ClientFrame frame) {
+ // Set dialog and frame here
+ this.dialog = dialog;
+ this.frame = frame;
+ }
+
+ /**
+ * If the action has been performed
+ *
+ * @param e The performed action event
+ */
+ @Override
+ public void actionPerformed (final ActionEvent e) {
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+ }
+ }
+
+ /**
+ * Class for "cancel address" button
+ */
+ private static class CancelActionListener extends BaseFrameworkSystem implements ActionListener {
+ /**
+ * Dialog instance
+ */
+ private final JDialog dialog;
+
+ /**
+ * Frame (not JFrame) instance
+ */
+ private final ClientFrame frame;
+
+ /**
+ * Constructor for action listener
+ *
+ * @param dialog Dialog instance to call back
+ * @param frame Frame instance (not JFrame)
+ */
+ protected CancelActionListener (final JDialog dialog, final ClientFrame frame) {
+ // Set dialog and frame here
+ this.dialog = dialog;
+ this.frame = frame;
+ }
+
+ /**
+ * If the action has been performed
+ *
+ * @param e The performed action event
+ */
+ @Override
+ public void actionPerformed (final ActionEvent e) {
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+ }
+ }
}
*/
public boolean isInitialized ();
+ /**
+ * Shuts down application
+ */
public void shutdownApplication ();
}
// Init frame
this.frame.init();
} catch (final FrameAlreadyInitializedException ex) {
- this.getLogger().catching(ex);
- System.exit(1);
+ // Abort program
+ this.abortProgramWithException(ex);
}
// Now start the frame
*/
package org.mxchange.addressbook.database.backend;
+import java.sql.Driver;
+import java.sql.DriverManager;
+import java.text.MessageFormat;
+import java.util.Enumeration;
import org.mxchange.addressbook.BaseFrameworkSystem;
+import org.mxchange.addressbook.exceptions.UnsupportedDatabaseDriverException;
/**
* Generall database backend
*/
protected BaseDatabaseBackend () {
}
+
+ /**
+ * Validates driver name and throws an exception if the driver is not valid
+ *
+ * @param driverName Driver name (e.g. "mysql")
+ * @throws org.mxchange.addressbook.exceptions.UnsupportedDatabaseDriverException If the given driver name cannot be solved into a driver instance
+ */
+ protected void validateDriver (final String driverName) throws UnsupportedDatabaseDriverException {
+ // Trace message
+ this.getLogger().trace(MessageFormat.format("driverName={0} - CALLED!", driverName)); //NOI18N
+
+ // Try to find the driver in driver list
+ Enumeration<Driver> drivers = DriverManager.getDrivers();
+
+ // Default is not found
+ boolean isFound = false;
+
+ // Search for it
+ while (drivers.hasMoreElements()) {
+ // Get element
+ Driver driver = drivers.nextElement();
+
+ // Debug message
+ this.getLogger().debug(MessageFormat.format("Driver {0} is installed.", driver)); //NOI18N
+
+ // Get class name
+ String className = driver.getClass().getName();
+
+ // Is this wanted?
+ if (className.contains(driverName)) {
+ // Debug message
+ this.getLogger().debug("Found driver!"); //NOI18N
+
+ // Found it
+ isFound = true;
+ break;
+ }
+ }
+
+ // Is it found?
+ if (!isFound) {
+ // Throw exception
+ throw new UnsupportedDatabaseDriverException(driverName);
+ }
+
+ // Trace message
+ this.getLogger().trace("EXIT!"); //NOI18N
+ }
}
package org.mxchange.addressbook.database.backend;
import java.io.IOException;
+import java.util.Iterator;
import org.mxchange.addressbook.FrameworkInterface;
+import org.mxchange.addressbook.contact.Contact;
import org.mxchange.addressbook.database.storage.Storeable;
+import org.mxchange.addressbook.exceptions.BadTokenException;
/**
* A generic interface for database frontends
*/
public interface DatabaseBackend extends FrameworkInterface {
+ /**
+ * Tries a connection to the database
+ */
+ public void connectToDatabase ();
+
/**
* Shuts down this backend
*/
* @throws java.io.IOException From inner class
*/
public void store (final Storeable object) throws IOException;
+
+ /**
+ * Gets an iterator for contacts
+ *
+ * @return Iterator for contacts
+ * @throws org.mxchange.addressbook.exceptions.BadTokenException If the CSV
+ * token is badly formulated
+ */
+ public Iterator<Contact> contactIterator () throws BadTokenException;
}
import org.mxchange.addressbook.contact.book.BookContact;
import org.mxchange.addressbook.contact.user.UserContact;
import org.mxchange.addressbook.database.backend.BaseDatabaseBackend;
+import org.mxchange.addressbook.database.backend.DatabaseBackend;
import org.mxchange.addressbook.database.storage.Storeable;
import org.mxchange.addressbook.database.storage.csv.StoreableCsv;
import org.mxchange.addressbook.exceptions.BadTokenException;
*
* @author Roland Haeder
*/
-public class Base64CsvDatabaseBackend extends BaseDatabaseBackend implements CsvBackend {
+public class Base64CsvDatabaseBackend extends BaseDatabaseBackend implements DatabaseBackend {
/**
* Output stream for this storage engine
this.getLogger().debug(MessageFormat.format("Database for {0} has been initialized.", tableName)); //NOI18N
}
+ /**
+ * This database backend does not need to connect
+ */
+ @Override
+ public void connectToDatabase () {
+ // Empty body
+ }
+
/**
* Gets an iterator for contacts
*
// Close file
this.getStorageFile().close();
} catch (final IOException ex) {
- this.getLogger().catching(ex);
- System.exit(1);
+ // Abort program
+ this.abortProgramWithException(ex);
}
// Trace message
this.getLogger().debug(MessageFormat.format("length={0}", length)); //NOI18N
} catch (final IOException ex) {
// Length cannot be determined
- this.getLogger().catching(ex);
- System.exit(1);
+ // Abort program
+ this.abortProgramWithException(ex);
}
// Return result
// Rewind underlaying database file
this.getStorageFile().seek(0);
} catch (final IOException ex) {
- this.getLogger().catching(ex);
- System.exit(1);
+ // Abort program
+ this.abortProgramWithException(ex);
}
// Trace message
// Verify token, it must have double-quotes on each side
if ((!token.startsWith("\"")) || (!token.endsWith("\""))) { //NOI18N
// Something bad was read
- throw new BadTokenException(MessageFormat.format("Token {0} at position {1} has not double-quotes on both ends.", token, count)); //NOI18N
+ throw new BadTokenException(token, count); //NOI18N
}
// All fine, so remove it
+++ /dev/null
-/*
- * Copyright (C) 2015 Roland Haeder
- *
- * This program 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.
- *
- * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.addressbook.database.backend.csv;
-
-import java.util.Iterator;
-import org.mxchange.addressbook.contact.Contact;
-import org.mxchange.addressbook.database.backend.DatabaseBackend;
-import org.mxchange.addressbook.exceptions.BadTokenException;
-
-/**
- *
- * @author Roland Haeder
- */
-public interface CsvBackend extends DatabaseBackend {
-
- /**
- * Gets an iterator for contacts
- *
- * @return Iterator for contacts
- * @throws org.mxchange.addressbook.exceptions.BadTokenException If the CSV
- * token is badly formulated
- */
- public Iterator<Contact> contactIterator () throws BadTokenException;
-}
--- /dev/null
+/*
+ * Copyright (C) 2015 Roland Haeder
+ *
+ * This program 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.
+ *
+ * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.database.backend.mysql;
+
+import java.io.IOException;
+import java.util.Iterator;
+import org.mxchange.addressbook.contact.Contact;
+import org.mxchange.addressbook.database.backend.BaseDatabaseBackend;
+import org.mxchange.addressbook.database.backend.DatabaseBackend;
+import org.mxchange.addressbook.database.storage.Storeable;
+import org.mxchange.addressbook.exceptions.BadTokenException;
+import org.mxchange.addressbook.exceptions.UnsupportedDatabaseDriverException;
+
+/**
+ * A backend class for MySQL connections
+ *
+ * @author Roland Haeder
+ */
+public class MySqlDatabaseBackend extends BaseDatabaseBackend implements DatabaseBackend {
+ /**
+ * Constructor with table name
+ *
+ * @param tableName Table to access
+ * @throws org.mxchange.addressbook.exceptions.UnsupportedDatabaseDriverException
+ */
+ public MySqlDatabaseBackend (final String tableName) throws UnsupportedDatabaseDriverException {
+ // Validate driver
+ this.validateDriver("mysql"); //NOI18N
+
+ // Now that the driver is there ...
+ }
+
+ @Override
+ public void connectToDatabase () {
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+ }
+
+ @Override
+ public Iterator<Contact> contactIterator () throws BadTokenException {
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+ }
+
+ @Override
+ public void doShutdown () {
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+ }
+
+ @Override
+ public long length () {
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+ }
+
+ @Override
+ public void rewind () {
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+ }
+
+ @Override
+ public void store (final Storeable object) throws IOException {
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+ }
+}
import org.mxchange.addressbook.BaseFrameworkSystem;
import org.mxchange.addressbook.database.backend.DatabaseBackend;
import org.mxchange.addressbook.database.backend.csv.Base64CsvDatabaseBackend;
+import org.mxchange.addressbook.database.backend.mysql.MySqlDatabaseBackend;
+import org.mxchange.addressbook.exceptions.UnsupportedDatabaseBackendException;
+import org.mxchange.addressbook.exceptions.UnsupportedDatabaseDriverException;
/**
* General database frontend class
/**
* Initialize backend
+ *
+ * @throws org.mxchange.addressbook.exceptions.UnsupportedDatabaseBackendException If the backend is not supported
*/
- protected void initBackend () {
+ protected void initBackend () throws UnsupportedDatabaseBackendException {
// Trace message
this.getLogger().trace("CALLED!"); //NOI18N
- // Instance backend
- this.backend = new Base64CsvDatabaseBackend(this.getTableName());
+ // Read property
+ // @TODO rewrite this to own properties file
+ String backendType = System.getProperty("org.mxchange.addressbook.database.backendType", "base64csv"); //NOI18N
+
+ // Try it
+ try {
+ // Switch on backend type
+ switch (backendType) {
+ case "mysql": // MySQL backend, this requires more information //NOI18N
+ this.backend = new MySqlDatabaseBackend(this.getTableName());
+ break;
+
+ case "base64csv": // BASE64-encoded CSV rows //NOI18N
+ this.backend = new Base64CsvDatabaseBackend(this.getTableName());
+ break;
+
+ default: // Unsupported
+ throw new UnsupportedDatabaseBackendException(backendType);
+ }
+
+ // Try to run a connect on it
+ this.backend.connectToDatabase();
+ } catch (final UnsupportedDatabaseDriverException ex) {
+ // Continue to throw
+ throw new UnsupportedDatabaseBackendException(backendType, ex);
+ }
// Trace message
this.getLogger().trace("EXIT!"); //NOI18N
import java.util.Iterator;
import java.util.List;
import org.mxchange.addressbook.contact.Contact;
-import org.mxchange.addressbook.database.backend.csv.CsvBackend;
import org.mxchange.addressbook.database.frontend.BaseDatabaseFrontend;
import org.mxchange.addressbook.database.storage.Storeable;
import org.mxchange.addressbook.exceptions.BadTokenException;
+import org.mxchange.addressbook.exceptions.UnsupportedDatabaseBackendException;
import org.mxchange.addressbook.manager.contact.ContactManager;
/**
// Set "table" name
this.setTableName("contacts"); //NOI18N
- // Initalize backend
- this.initBackend();
+ try {
+ // Initalize backend
+ this.initBackend();
+ } catch (final UnsupportedDatabaseBackendException ex) {
+ // Abort program
+ this.abortProgramWithException(ex);
+ }
}
/**
this.getBackend().store((Storeable) contact);
} catch (final IOException ex) {
// Should not happen?
- this.getLogger().catching(ex);
- System.exit(1);
+ this.abortProgramWithException(ex);
}
}
// Trace message
this.getLogger().trace("CALLED!"); //NOI18N
- // Get iterator and case it
- CsvBackend backend = (CsvBackend) this.getBackend();
-
// First rewind to beginning
this.getBackend().rewind();
// Get backend iterator
Iterator<Contact> iterator = null;
try {
- iterator = backend.contactIterator();
+ iterator = this.getBackend().contactIterator();
} catch (final BadTokenException ex) {
- this.getLogger().catching(ex);
- System.exit(1);
+ // Abort program
+ this.abortProgramWithException(ex);
}
// Read all entries
*/
package org.mxchange.addressbook.exceptions;
+import java.text.MessageFormat;
+
/**
* This exception is thrown when a token has been badly formated. This may
* happen when a CSV file is broken.
*/
public class BadTokenException extends Exception {
- public BadTokenException (final String str) {
- super(str);
+ /**
+ * Constructor with token and count
+ * @param token Token that is not valid
+ * @param count Count
+ */
+ public BadTokenException (final String token, final int count) {
+ super(MessageFormat.format("Token {0} at position {1} has not double-quotes on both ends.", token, count));
}
}
*/
public class UnhandledUserChoiceException extends Exception {
+ /**
+ *
+ * @param message
+ */
public UnhandledUserChoiceException (final String message) {
super(message);
}
--- /dev/null
+/*
+ * Copyright (C) 2015 Roland Haeder
+ *
+ * This program 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.
+ *
+ * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.exceptions;
+
+import java.text.MessageFormat;
+
+/**
+ * An exception thrown when the given backend type is not valid
+ *
+ * @author Roland Haeder
+ */
+public class UnsupportedDatabaseBackendException extends Exception {
+
+ /**
+ *
+ * @param backendType
+ */
+ public UnsupportedDatabaseBackendException (final String backendType) {
+ // Call super constructor
+ super(MessageFormat.format("Backend {0} is not supported.", backendType)); //NOI18N
+ }
+
+ /**
+ * Constructor with backend type and cause
+ *
+ * @param backendType Backend type
+ * @param cause
+ */
+ public UnsupportedDatabaseBackendException (final String backendType, final Throwable cause) {
+ // Call super constructor
+ super(MessageFormat.format("Backend {0} is not supported.", backendType), cause); //NOI18N
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2015 Roland Haeder
+ *
+ * This program 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.
+ *
+ * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.exceptions;
+
+import java.text.MessageFormat;
+
+/**
+ * Thrown when the given driver is not found
+ *
+ * @author Roland Haeder
+ */
+public class UnsupportedDatabaseDriverException extends Exception {
+
+ /**
+ * Default constructor with driver name
+ * @param driverName
+ */
+ public UnsupportedDatabaseDriverException (final String driverName) {
+ // Call super method
+ super(MessageFormat.format("Database driver {0} is not found.", driverName));
+ }
+
+}
AddressbookFrame.border.name.title.text=Anrede, Vorname, Nachname:
AddressbookFrame.border.address.title.text=Anschrift:
AddressbookFrame.border.other.title.text=Andere Angaben:
+AddressbookFrame.button.addAddress.text=Adresse hinzuf\u00fcgen
+AddressbookFrame.button.cancel.text=Abbrechen
AddressbookFrame.menu.file.text=Datei
AddressbookFrame.menu.addressbook.text=Adressbuch
AddressbookFrame.statusLabel.initializing.text=Initialisiere ...
AddressbookFrame.statusLabel.done.text=Fertig.
AddressbookFrame.statusLabel.shutdown.text=Shuttting down ...
-AddressbookFrame.menuItem.exitProgram.toolTipText=Beendet das Programm und speichert alle Einstellungen ab.
AddressbookFrame.menuItem.exitProgram.text=Programm beenden
+AddressbookFrame.menuItem.exitProgram.toolTipText=Beendet das Programm und speichert alle Einstellungen ab.
AddressbookFrame.menuItem.addOwnData.text=Eigene Adresse hinzuf\u00fcgen
AddressbookFrame.menuItem.addOwnData.toolTipText=Erlaubt das Hinzuf\u00fcgen eigener Daten.
AddressbookFrame.menuItem.editOwnData.text=Eigene Adresse \u00e4ndern
AddressbookFrame.menuItem.editOwnData.toolTipText=Erlaubt das \u00c4ndern eigener Daten.
+AddressbookFrame.menuItem.addNewContact.text=Neue Adresse hinzuf\u00fcgen
+AddressbookFrame.menuItem.addNewContact.toolTipText=Eine neue Adresse hinzuf\u00fcgen.
AddressbookFrame.dialog.addContact.title.text=Neue Adresse hinzuf\u00fcgen
AddressbookFrame.main.title.text=Adressen auflisten
AddressbookFrame.gender.text=Anrede:
-AddressbookFrame.gender.tooltipText=W\u00e4hlen Sie die Anrede aus.
+AddressbookFrame.gender.toolTipText=W\u00e4hlen Sie die Anrede aus.
AddressbookFrame.surname.text=Vorname:
-AddressbookFrame.surname.tooltipText=Geben Sie den Vornamen ein.
+AddressbookFrame.surname.toolTipText=Geben Sie den Vornamen ein.
AddressbookFrame.familyName.text=Nachname:
-AddressbookFrame.familyName.tooltipText=Geben Sie den Nachnamen ein.
+AddressbookFrame.familyName.toolTipText=Geben Sie den Nachnamen ein.
AddressbookFrame.street.text=Stra\u00dfe:
-AddressbookFrame.street.tooltipText=Geben Sie die Stra\u00dfe ein.
+AddressbookFrame.street.toolTipText=Geben Sie die Stra\u00dfe ein.
AddressbookFrame.number.text=Hausnummer:
-AddressbookFrame.number.tooltipText=Geben Sie die Hausnummer ein.
+AddressbookFrame.number.toolTipText=Geben Sie die Hausnummer ein.
AddressbookFrame.zip.text=PLZ:
-AddressbookFrame.zip.tooltipText=Geben Sie die Postleitzahl ein.
+AddressbookFrame.zip.toolTipText=Geben Sie die Postleitzahl ein.
AddressbookFrame.city.text=Stadt:
-AddressbookFrame.city.tooltipText=Geben Sie die Stadt ein.
+AddressbookFrame.city.toolTipText=Geben Sie die Stadt ein.
+AddressbookFrame.emailAddress.text=Email-Adresse:
+AddressbookFrame.emailAddress.toolTipText=Geben Sie die Email-Adresse ein.
+AddressbookFrame.phoneNumber.text=Telefon:
+AddressbookFrame.phoneNumber.toolTipText=Geben Sie die Telefonnummer ein.
+AddressbookFrame.cellphoneNumber.text=Mobil:
+AddressbookFrame.cellphoneNumber.toolTipText=Geben Sie die Handynummer ein.
+AddressbookFrame.faxNumber.text=Fax:
+AddressbookFrame.faxNumber.toolTipText=Geben Sie die Faxnummer ein.
+AddressbookFrame.comment.text=Anmerkungen:
+AddressbookFrame.comment.toolTipText=Geben Sie eine Anmerkung (Freifeld) ein.
BaseContact.gender.unknown.text=Unbekannt
BaseContact.gender.male.text=Herr
BaseContact.gender.female.text=Frau
AddressbookFrame.border.name.title.text=Gender, surname, family name:
AddressbookFrame.border.address.title.text=Address:
AddressbookFrame.border.other.title.text=Other data:
+AddressbookFrame.button.addAddress.text=Add address
+AddressbookFrame.button.cancel.text=Cancel
AddressbookFrame.menu.file.text=File
AddressbookFrame.menu.addressbook.text=Addressbook
AddressbookFrame.statusLabel.initializing.text=Initializing ...
AddressbookFrame.menuItem.addOwnData.toolTipText=Allows the user to add own address data
AddressbookFrame.menuItem.editOwnData.text=Edit own data
AddressbookFrame.menuItem.editOwnData.toolTipText=Allows the user to edit own address data
+AddressbookFrame.menuItem.addNewContact.text=Add new address
+AddressbookFrame.menuItem.addNewContact.toolTipText=Add a new address.
AddressbookFrame.dialog.addContact.title.text=Add new address
AddressbookFrame.main.title.text=List addresses
AddressbookFrame.gender.text=Gender:
-AddressbookFrame.gender.tooltipText=Choose gender.
+AddressbookFrame.gender.toolTipText=Choose gender.
AddressbookFrame.surname.text=Surname:
-AddressbookFrame.surname.tooltipText=Enter surname.
+AddressbookFrame.surname.toolTipText=Enter surname.
AddressbookFrame.familyName.text=Family name:
-AddressbookFrame.familyName.tooltipText=Enter family name.
+AddressbookFrame.familyName.toolTipText=Enter family name.
AddressbookFrame.street.text=Street:
-AddressbookFrame.street.tooltipText=Enter street.
+AddressbookFrame.street.toolTipText=Enter street.
AddressbookFrame.number.text=Number:
-AddressbookFrame.number.tooltipText=Enter number.
+AddressbookFrame.number.toolTipText=Enter number.
AddressbookFrame.zip.text=ZIP:
-AddressbookFrame.zip.tooltipText=Enter zip code.
+AddressbookFrame.zip.toolTipText=Enter zip code.
AddressbookFrame.city.text=City:
-AddressbookFrame.city.tooltipText=Enter city.
+AddressbookFrame.city.toolTipText=Enter city.
+AddressbookFrame.emailAddress.text=Email address:
+AddressbookFrame.emailAddress.toolTipText=Enter email address.
+AddressbookFrame.phoneNumber.text=Phone:
+AddressbookFrame.phoneNumber.toolTipText=Enter phone number.
+AddressbookFrame.cellphoneNumber.text=Mobile:
+AddressbookFrame.cellphoneNumber.toolTipText=Enter mobile number.
+AddressbookFrame.faxNumber.text=Fax:
+AddressbookFrame.faxNumber.toolTipText=Enter fax number.
+AddressbookFrame.comment.text=Note:
+AddressbookFrame.comment.toolTipText=Enter a note (free field).
BaseContact.gender.unknown.text=Unknown
BaseContact.gender.male.text=Mr.
BaseContact.gender.female.text=Mrs.