// Init components
initComponents();
- // Has the user entered own data?
- //if (client.)
-
// Set client here
this.client = client;
}
}//GEN-LAST:event_addOwnDataActionPerformed
/**
- * Initializes the frame
+ * Setups the frame
+ *
+ * @param client Client instance
*/
@Override
- public void initFrame (final Client client) {
+ public void setupFrame (final Client client) {
+ // Has the user entered own data?
+ if (!this.getClient().getContactManager().isOwnContactAdded()) {
+ // Debug message
+ this.getLogger().debug("Enabling menus: isOwnContactAdded()=false");
+
+ // Not entered yet, so enable menu
+ addOwnData.setEnabled(true);
+ }
+
/*
* Set the Nimbus look and feel
*/
- //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
- /*
+ //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
+ /*
* If Nimbus (introduced in Java SE 6) is not available, stay with the
* default look and feel. For details see
* http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/\r
public interface ClientFrame extends FrameworkInterface {\r
/**\r
- * Initializes the frame\r
+ * Setups the frame\r
* \r
* @param client Client instance\r
*/\r
- public void initFrame (final Client client);\r
+ public void setupFrame (final Client client);\r
}\r
package org.mxchange.addressbook.client.gui;\r
\r
import org.mxchange.addressbook.UnhandledUserChoiceException;\r
-import org.mxchange.addressbook.application.AddressbookApplication;\r
+import org.mxchange.addressbook.application.Application;\r
import org.mxchange.addressbook.client.BaseClient;\r
import org.mxchange.addressbook.client.Client;\r
import org.mxchange.addressbook.contact.Contact;\r
* Constructor with application instance\r
* @param application \r
*/\r
- public SwingClient (final AddressbookApplication application) {\r
+ public SwingClient (final Application application) {\r
super();\r
\r
// Set application instance\r
* @param accessKey Key to access the menu\r
* @param text Text to show to user\r
* @return A SelectableMenuItem\r
- * @todo Make sure the access key is unique\r
*/\r
@Override\r
public SelectableMenuItem getMenuItem (final char accessKey, final String text) {\r
this.initContactManager();\r
\r
// Now start the frame\r
- this.frame.initFrame(this);\r
+ this.frame.setupFrame(this);\r
}\r
\r
@Override\r
import org.mxchange.addressbook.database.backend.csv.CsvBackend;\r
import org.mxchange.addressbook.database.frontend.BaseDatabaseFrontend;\r
import org.mxchange.addressbook.database.storage.Storeable;\r
-import org.mxchange.addressbook.manager.contact.ManageableContact;\r
+import org.mxchange.addressbook.manager.contact.ContactManager;\r
\r
/**\r
* Stores and retrieves Contact instances\r
* @author Roland Haeder\r
*/\r
public class ContactDatabaseFrontend extends BaseDatabaseFrontend implements ContactWrapper {\r
+ /**\r
+ * Constructor which accepts a contact manager\r
+ * @param manager\r
+ */\r
+ public ContactDatabaseFrontend (final ContactManager manager) {\r
+ // Call own constructor\r
+ this();\r
+ \r
+ // Set contact manager\r
+ this.setContactManager(manager);\r
+ }\r
+\r
/**\r
* Basic constrcutor\r
*/\r
- public ContactDatabaseFrontend () {\r
+ protected ContactDatabaseFrontend () {\r
super();\r
\r
// Set "table" name\r
\r
/**\r
* Flushes all contact entries to database\r
- * @param contactManager An instance of a MangeableContact class\r
*/\r
@Override\r
- public void flushAllContacts (final ManageableContact contactManager) {\r
+ public void flushAllContacts () {\r
// Get full list\r
- List<Contact> contacts = contactManager.getList();\r
+ List<Contact> contacts = this.getContactManager().getList();\r
\r
// Get iterator\r
Iterator<Contact> iterator = contacts.iterator();\r
/**\r
* Reads all contacts from database backend and handles them over to the\r
* contact manager\r
- * \r
- * @param contactManager Contact manager to handle loaded contacts\r
*/\r
@Override\r
- public void readAllContacts (final ManageableContact contactManager) {\r
+ public void readAllContacts () {\r
// Get iterator and case it\r
CsvBackend backend = (CsvBackend) this.getBackend();\r
\r
Contact contact = iterator.next();\r
\r
// Add contact instance to manager\r
- contactManager.addContact(contact);\r
+ this.getContactManager().addContact(contact);\r
}\r
}\r
}\r
package org.mxchange.addressbook.database.frontend.contact;\r
\r
import org.mxchange.addressbook.database.frontend.DatabaseWrapper;\r
-import org.mxchange.addressbook.manager.contact.ManageableContact;\r
\r
/**\r
*\r
\r
/**\r
* Flushes all contact entries to database\r
- * \r
- * @param contactManager An instance of a MangeableContact class\r
*/\r
- public void flushAllContacts (final ManageableContact contactManager);\r
+ public void flushAllContacts ();\r
\r
/**\r
* Reads all contacts from database backend and handles them over to the\r
* contact manager\r
- * \r
- * @param contactManager \r
*/\r
- public void readAllContacts (final ManageableContact contactManager);\r
+ public void readAllContacts ();\r
}\r
this.contacts = new ArrayList<>(maxContacts);\r
\r
// Init database connection\r
- this.contactDatabase = new ContactDatabaseFrontend();\r
+ this.contactDatabase = new ContactDatabaseFrontend(this);\r
\r
// Read all entries\r
- this.contactDatabase.readAllContacts(this);\r
+ this.contactDatabase.readAllContacts();\r
\r
// Debug message\r
//* NOISY-DEBUG: */ this.getLogger().debug("client=" + client);\r
return Collections.unmodifiableList(this.contacts);\r
}\r
\r
+ /**\r
+ * Checks whether own contact is already added by checking all entries for\r
+ * isOwnContact flag\r
+ *\r
+ * @return Whether own contact is already added\r
+ */\r
+ @Override\r
+ public boolean isOwnContactAdded () {\r
+ // Default is not added\r
+ boolean isAdded = false;\r
+ \r
+ // Now get it back from address book, first get an iterator\r
+ Iterator<Contact> iterator = this.contacts.iterator();\r
+ \r
+ // Check entries\r
+ while (iterator.hasNext()) {\r
+ // Get next entry\r
+ Contact contact = iterator.next();\r
+ \r
+ // Is it valid?\r
+ if (contact instanceof Contact) {\r
+ // Get flag\r
+ isAdded = contact.isOwnContact();\r
+ \r
+ // Is this own contact?\r
+ if (isAdded) {\r
+ // Then abort loop\r
+ break;\r
+ }\r
+ }\r
+ }\r
+ // Return result\r
+ return isAdded;\r
+ }\r
+\r
@Override\r
public void listContacts () {\r
throw new UnsupportedOperationException("Not supported yet.");\r
*/\r
private void flush () {\r
// Flusgh all\r
- this.getContactDatabase().flushAllContacts(this);\r
+ this.getContactDatabase().flushAllContacts();\r
}\r
\r
/**\r
// Return result\r
return isFound;\r
}\r
-\r
- /**\r
- * Checks whether own contact is already added by checking all entries for\r
- * isOwnContact flag\r
- * \r
- * @return Whether own contact is already added\r
- */\r
- private boolean isOwnContactAdded () {\r
- // Default is not added\r
- boolean isAdded = false;\r
-\r
- // Now get it back from address book, first get an iterator\r
- Iterator<Contact> iterator = this.contacts.iterator();\r
-\r
- // Check entries\r
- while (iterator.hasNext()) {\r
- // Get next entry\r
- Contact contact = iterator.next();\r
-\r
- // Is it valid?\r
- if (contact instanceof Contact) {\r
- // Get flag\r
- isAdded = contact.isOwnContact();\r
-\r
- // Is this own contact?\r
- if (isAdded) {\r
- // Then abort loop\r
- break;\r
- }\r
- }\r
- }\r
- // Return result\r
- return isAdded;\r
- }\r
}\r
*/\r
public void searchContacts ();\r
\r
+ /**\r
+ * Checks whether own contact is already added by checking all entries for\r
+ * isOwnContact flag\r
+ * \r
+ * @return Whether own contact is already added\r
+ */\r
+ public boolean isOwnContactAdded ();\r
+\r
/**\r
* Getter for size\r
*\r