update project.

This commit is contained in:
2026-02-19 18:48:06 -05:00
parent e436b4a3c9
commit 21f792685c
25 changed files with 315 additions and 265 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+6 -6
View File
@@ -1,13 +1,13 @@
arguments= arguments=--init-script /home/sherwinp/.config/VSCodium/User/globalStorage/redhat.java/1.50.0/config_linux/org.eclipse.osgi/58/0/.cp/gradle/init/init.gradle --init-script /home/sherwinp/.config/VSCodium/User/globalStorage/redhat.java/1.50.0/config_linux/org.eclipse.osgi/58/0/.cp/gradle/protobuf/init.gradle
auto.sync=false auto.sync=true
build.scans.enabled=false build.scans.enabled=false
connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER) connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER)
connection.project.dir= connection.project.dir=
eclipse.preferences.version=1 eclipse.preferences.version=1
gradle.user.home= gradle.user.home=
java.home= java.home=/usr/lib/jvm/java-25-openjdk
jvm.arguments= jvm.arguments=
offline.mode=false offline.mode=false
override.workspace.settings=false override.workspace.settings=true
show.console.view=false show.console.view=true
show.executions.view=false show.executions.view=true
+1 -1
View File
@@ -23,7 +23,7 @@
"name": "Linux Current File", "name": "Linux Current File",
"request": "launch", "request": "launch",
"mainClass": "edu.bookocontacts.AppSceneView", "mainClass": "edu.bookocontacts.AppSceneView",
"vmArgs": " --module-path '/home/sherwinp/workspace/javafx-sdk/lib/' --add-modules ALL-MODULE-PATH --enable-native-access=javafx.graphics" "vmArgs": " --class-path .:edu.bookocontacts:edu.bookocontacts.model --module-path '/home/sherwinp/workspace/javafx-sdk/lib/' --add-modules ALL-MODULE-PATH --enable-native-access=javafx.graphics"
} }
] ]
} }
+1 -1
View File
@@ -66,7 +66,7 @@ tasks.named('jar') {
'Implementation-Title': group, 'Implementation-Title': group,
'Implementation-Version': 1.0, 'Implementation-Version': 1.0,
'Main-Class': application.mainClass, 'Main-Class': application.mainClass,
'Class-Path': 'edu.bookocontacts javafx.base javafx.controls .' ) 'Class-Path': '. edu.bookocontacts edu.bookocontacts.model javafx.base javafx.controls' )
} }
} }
BIN
View File
Binary file not shown.
+21
View File
@@ -21,6 +21,27 @@ Tests with ASPECTJ:
schema schema
-------
CREATE TABLE CONTACT(
ID NUMBER PRIMARY KEY,
FIRST_NAME TEXT,
LAST_NAME TEXT,
PHONE_NUMBER TEXT,
EMAIL_ADDRESS TEXT,
MAIL_ADDRESS TEXT
);
-------
INSERT INTO CONTACT (ID, FIRST_NAME, LAST_NAME, PHONE_NUMBER, EMAIL_ADDRESS, MAIL_ADDRESS)
VALUES
(8,"Ramon", "Razone", "443-310-8764","Raz@home.com",NULL),
(9,"Manny", "Zonie", "443-350-6764","Zonie@home.com","7000 Hause Ln, People City,MN, 34090"),
(10,"Von", "Ray", "443-210-9764","RayVon@home.com","");
UPDATE CONTACT SET MAIL_ADDRESS=NULL WHERE ID=8;
-------
CREATE TABLE contact ( CREATE TABLE contact (
contact_id NUMBER PRIMARY KEY, contact_id NUMBER PRIMARY KEY,
first_name TEXT, first_name TEXT,
@@ -4,6 +4,7 @@ import java.io.InputStream;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import edu.bookocontacts.model.DATASET;
import javafx.application.Application; import javafx.application.Application;
import javafx.fxml.FXMLLoader; import javafx.fxml.FXMLLoader;
import javafx.fxml.JavaFXBuilderFactory; import javafx.fxml.JavaFXBuilderFactory;
@@ -11,11 +11,15 @@ import javafx.scene.control.Dialog;
import javafx.scene.control.TextField; import javafx.scene.control.TextField;
import javafx.util.Callback; import javafx.util.Callback;
import edu.bookocontacts.model.Address; import edu.bookocontacts.model.MailAddress;
import edu.bookocontacts.model.Contact; import edu.bookocontacts.model.Contact;
import edu.bookocontacts.model.EmailAddress; import edu.bookocontacts.model.EmailAddress;
import edu.bookocontacts.model.PhoneNumber; import edu.bookocontacts.model.PhoneNumber;
/**
* FXML Controller class
*
*/
public class ControlDDXDialog extends Dialog<Contact> { public class ControlDDXDialog extends Dialog<Contact> {
@FXML @FXML
@@ -60,55 +64,51 @@ public class ControlDDXDialog extends Dialog<Contact> {
} }
private void setResultConverter() { private void setResultConverter() {
Logger.getLogger(getClass().getName()).log(Level.INFO, "setResultConverter called.");
Callback<ButtonType, Contact> aRC = (buttonType) -> { Callback<ButtonType, Contact> aRC = (buttonType) -> {
if (buttonType == ButtonType.OK) { if (buttonType == ButtonType.OK) {
if (getFirstName().isBlank() && (getEmail().isBlank() || getPhoneNo().isBlank())) { if (getFirstName().isBlank() && (getEmail().isBlank() || getPhoneNo().isBlank())) {
return null; return null;
} }
if (getFirstName().isBlank() || getStreet().isEmpty() || getCity().isEmpty() || getState().isEmpty()
|| getZip().isEmpty()) {
return null;
}
return new Contact(getFirstName(), getLastName(), new EmailAddress(getEmail()), return new Contact(getFirstName(), getLastName(), new EmailAddress(getEmail()),
new PhoneNumber(getPhoneNo()), new Address(getStreet(), getCity(), getState(), getZip())); new PhoneNumber(getPhoneNo()), new MailAddress(getStreet(), getCity(), getState(), getZip()));
} }
return null; return null;
}; };
setResultConverter(aRC); setResultConverter(aRC);
Logger.getLogger(getClass().getName()).log(Level.INFO, "setResultConverter called.");
} }
private String getFirstName() { private String getFirstName() {
return ""; return String.format( "%s", tfFirstName.getText());
} }
private String getLastName() { private String getLastName() {
return ""; return String.format("%s", tfLastName.getText());
} }
private String getPhoneNo() { private String getPhoneNo() {
return ""; return String.format("%s", tfPhoneNo.getText());
} }
private String getEmail() { private String getEmail() {
return ""; return String.format("%s", tfEmail.getText());
} }
private String getZip() { private String getZip() {
return tfZip.getText(); return String.format("%s", tfZip.getText());
} }
private String getState() { private String getState() {
return tfState.getText(); return String.format("%s", tfState.getText());
} }
private String getCity() { private String getCity() {
return tfCity.getText(); return String.format("%s", tfCity.getText());
} }
private String getStreet() { private String getStreet() {
return tfStreet.getText(); return String.format("%s", tfStreet.getText());
} }
} }
@@ -1,38 +0,0 @@
package edu.bookocontacts;
import java.io.File;
import java.io.PrintWriter;
import java.nio.file.Files;
import java.util.ListIterator;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.sqlite.SQLiteDataSource;
import edu.bookocontacts.model.Contact;
public final class DATASET {
public final static ListIterator<Contact> FINDDATA() {
try {
File rootDir = new File(String.format("%s", DataRepositoryConfig.getPath()));
Files.createDirectories(rootDir.toPath());
SQLiteDataSource dataSource = new SQLiteDataSource();
dataSource.setUrl(String.format("jdbc:sqlite:%ssample.db", DataRepositoryConfig.getPath()));
dataSource.getConnection();
} catch (Exception ex) {
Logger.getLogger(DATASET.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
public final static class DataRepositoryConfig {
public final static String getPath() {
String home = System.getenv("HOME") != null ? System.getenv("HOME")
: System.getenv("HOMEDRIVE") + System.getenv("HOMEPATH");
return home.replace('\\', '/') + "/workspace/bookocontacts/db/";
}
}
}
@@ -4,20 +4,17 @@
*/ */
package edu.bookocontacts; package edu.bookocontacts;
import java.util.logging.Level;
import java.util.logging.Logger;
import edu.bookocontacts.model.Factory;
import edu.bookocontacts.model.Person;
import edu.bookocontacts.model.Address;
import edu.bookocontacts.model.PhoneNumber;
import edu.bookocontacts.model.Contact;
import java.net.URL; import java.net.URL;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.Optional; import java.util.Optional;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.Logger;
import edu.bookocontacts.model.Contact;
import edu.bookocontacts.model.Factory;
import edu.bookocontacts.model.PhoneNumber;
import javafx.beans.value.ChangeListener; import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue; import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections; import javafx.collections.FXCollections;
@@ -27,12 +24,9 @@ import javafx.fxml.Initializable;
import javafx.scene.control.Button; import javafx.scene.control.Button;
import javafx.scene.control.Pagination; import javafx.scene.control.Pagination;
import javafx.scene.control.TableColumn; import javafx.scene.control.TableColumn;
import javafx.scene.control.TableColumn.SortType;
import javafx.scene.control.TableView; import javafx.scene.control.TableView;
import javafx.scene.control.TextField; import javafx.scene.control.TextField;
import javafx.scene.control.cell.PropertyValueFactory; import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
/** /**
* FXML Controller class * FXML Controller class
@@ -43,29 +37,29 @@ public class ViewController implements Initializable {
Logger logger = Logger.getLogger(getClass().getName()); Logger logger = Logger.getLogger(getClass().getName());
@FXML @FXML
private TableView<Contact> personView = new TableView<>(); private TableView<Contact> contactView = new TableView<>();
@FXML @FXML
private TableColumn<Contact, String> personViewIdCol; private TableColumn<Contact, String> contactViewIdCol;
@FXML @FXML
private TableColumn<Contact, String> personViewNameCol; private TableColumn<Contact, String> contactViewNameCol;
@FXML @FXML
private TableColumn<Contact, PhoneNumber> personViewPhoneNoCol; private TableColumn<Contact, PhoneNumber> contactViewPhoneNoCol;
@FXML @FXML
Pagination pagination; Pagination pagination;
@FXML @FXML
private Button save; private Button btnAdd;
@FXML
private Button id = new Button("ID"); private Button btnDel;
@FXML
private ImageView upImg = new ImageView(new Image("/media/up.png")); private Button btnSrch;
private ImageView downImg = new ImageView(new Image("/media/down.png")); @FXML
private TextField txtSrch;
private ObservableList<Contact> contacts = null; private ObservableList<Contact> contacts = null;
private int pageCount = 5; private int pageCount = 5;
private int itemsPerPage = 4; private int itemsPerPage = 4;
private int currentPageIndex = 0; private int currentPageIndex = 0;
private boolean order = true;
private void log(String message) { private void log(String message) {
logger.log(Level.INFO, message); logger.log(Level.INFO, message);
@@ -76,8 +70,11 @@ public class ViewController implements Initializable {
*/ */
public void initialize(URL location, ResourceBundle resources) { public void initialize(URL location, ResourceBundle resources) {
log("initialize"); log("initialize");
btnSrch.setDisable(true);
txtSrch.setDisable(true);
contacts = FXCollections.observableArrayList(Factory.getAll(new Contact())); contacts = FXCollections.observableArrayList(Factory.getAll(new Contact()));
log(String.format("Person size: %d", contacts.size())); log(String.format("Contact List size: %d", contacts.size()));
sort(); sort();
initializeTable(); initializeTable();
@@ -89,13 +86,17 @@ public class ViewController implements Initializable {
pagination.currentPageIndexProperty().addListener(new ChangeListener<Number>() { pagination.currentPageIndexProperty().addListener(new ChangeListener<Number>() {
@Override @Override
public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) { public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
log("Pagination Changed from " + oldValue + " , to " + newValue); log(String.format("Pagination Changed from %d to %d", oldValue, newValue));
currentPageIndex = newValue.intValue(); currentPageIndex = newValue.intValue();
updatePersonView(); try {
updatecontactView();
} catch (IllegalArgumentException ex) {
log(ex.getMessage());
}
} }
}); });
save.setOnAction(new javafx.event.EventHandler<javafx.event.ActionEvent>() { btnAdd.setOnAction(new javafx.event.EventHandler<javafx.event.ActionEvent>() {
@Override @Override
public void handle(javafx.event.ActionEvent t) { public void handle(javafx.event.ActionEvent t) {
@@ -106,33 +107,53 @@ public class ViewController implements Initializable {
if (result.isPresent()) { if (result.isPresent()) {
log("result is present."); log("result is present.");
// add to storage // add to storage
// contacts.add((Address) result.get()); Contact ct = (Contact) result.get();
// bind to model ct.setId(contacts.size());
// tvInventory.refresh(); contacts.add(ct);
// try {
// sort(); ct.save();
// updatePersonView(); } catch (Exception ex) {
log(ex.getMessage());
}
updatecontactView();
} }
} }
}); });
id.setOnAction(new javafx.event.EventHandler<javafx.event.ActionEvent>() { btnDel.setOnAction(new javafx.event.EventHandler<javafx.event.ActionEvent>() {
@Override @Override
public void handle(javafx.event.ActionEvent t) { public void handle(javafx.event.ActionEvent t) {
sort(); Contact ct = contactView.getSelectionModel().getSelectedItem();
if (order) { log(String.format("%s", ct));
Collections.reverse(contacts); contacts.remove(ct);
pagination.setPageCount(getPageCount(contacts.size(), itemsPerPage));
try {
// delete from storage
ct.markDeleted();
ct.save();
} catch (Exception ex) {
log(ex.getMessage());
} }
log(" order = " + order + "; data = " + contacts); updatecontactView();
order = !order;
id.setGraphic((order) ? upImg : downImg);
updatePersonView();
log(" comparator called");
} }
}); });
} }
private void initializeTable() {
contactViewIdCol.setCellValueFactory(new PropertyValueFactory<Contact, String>("Id"));
contactViewNameCol.setCellValueFactory(new PropertyValueFactory<Contact, String>("Name"));
contactViewPhoneNoCol.setCellValueFactory(new PropertyValueFactory<Contact, PhoneNumber>("PhoneNo"));
contactViewPhoneNoCol.setSortable(false);
if (contacts.size() < itemsPerPage) {
contactView.getItems().setAll(contacts.subList(0, contacts.size()));
} else {
contactView.getItems().setAll(contacts.subList(0, itemsPerPage));
}
}
private void sort() { private void sort() {
Collections.sort(contacts, new Comparator<Contact>() { Collections.sort(contacts, new Comparator<Contact>() {
@Override @Override
@@ -143,35 +164,15 @@ public class ViewController implements Initializable {
}); });
} }
public void updatePersonView() { public void updatecontactView() throws IllegalArgumentException {
log("update View"); log("update View");
personView.getItems() contactView.getItems()
.setAll(contacts.subList(currentPageIndex * itemsPerPage, .setAll(contacts.subList(currentPageIndex * itemsPerPage,
((currentPageIndex * itemsPerPage + itemsPerPage <= contacts.size()) ((currentPageIndex * itemsPerPage + itemsPerPage <= contacts.size())
? currentPageIndex * itemsPerPage + itemsPerPage ? currentPageIndex * itemsPerPage + itemsPerPage
: contacts.size()))); : contacts.size())));
} }
private void initializeTable() {
personViewIdCol.setCellValueFactory(new PropertyValueFactory<Contact, String>("Id"));
id.setGraphic(upImg);
personViewIdCol.setGraphic(id);
personViewIdCol.setSortable(false);
personViewNameCol.setCellValueFactory(new PropertyValueFactory<Contact, String>("Name"));
personViewNameCol.sortTypeProperty().addListener(new ChangeListener<SortType>() {
@Override
public void changed(ObservableValue<? extends SortType> paramObservableValue, SortType paramT1,
SortType paramT2) {
log("NAME Clicked -- sortType = " + paramT1 + ", SortType=" + paramT2);
id.setGraphic(null);
}
});
personViewPhoneNoCol.setCellValueFactory(new PropertyValueFactory<Contact, PhoneNumber>("PhoneNo"));
personViewPhoneNoCol.setText("PhoneNo");
personViewPhoneNoCol.setSortable(false);
personView.getItems().setAll(contacts.subList(0, itemsPerPage));
}
public int getItemsPerPage() { public int getItemsPerPage() {
return itemsPerPage; return itemsPerPage;
} }
@@ -12,7 +12,8 @@ public class Contact {
private String last_name = null; private String last_name = null;
private PhoneNumber phone_number; private PhoneNumber phone_number;
private EmailAddress email_address; private EmailAddress email_address;
private Address mailing_address; private MailAddress mailing_address;
EnumStatus status = EnumStatus.STORED;
public Contact() { public Contact() {
this("", ""); this("", "");
@@ -24,7 +25,7 @@ public class Contact {
} }
public Contact(String first_name, String last_name, EmailAddress email_address, PhoneNumber phone_number, public Contact(String first_name, String last_name, EmailAddress email_address, PhoneNumber phone_number,
Address mailing_address) MailAddress mailing_address)
throws IllegalArgumentException { throws IllegalArgumentException {
this.phone_number = phone_number; this.phone_number = phone_number;
this.mailing_address = mailing_address; this.mailing_address = mailing_address;
@@ -34,7 +35,8 @@ public class Contact {
this.last_name = last_name; this.last_name = last_name;
if (this.first_name == null && (email_address.isBlank() || phone_number.isBlank())) { if (this.first_name == null && (email_address.isBlank() || phone_number.isBlank())) {
throw new IllegalArgumentException(String.format("%s %s", "Contact: requires Phone Number or Email Address")); throw new IllegalArgumentException(
String.format("%s %s", "Contact: requires Phone Number or Email Address"));
} }
this.phone_number = phone_number; this.phone_number = phone_number;
@@ -42,7 +44,7 @@ public class Contact {
this.email_address = email_address; this.email_address = email_address;
} }
public Contact(PhoneNumber phone_number, Address mailing_address, EmailAddress email_address) public Contact(PhoneNumber phone_number, MailAddress mailing_address, EmailAddress email_address)
throws IllegalArgumentException { throws IllegalArgumentException {
this.phone_number = phone_number; this.phone_number = phone_number;
this.mailing_address = mailing_address; this.mailing_address = mailing_address;
@@ -76,16 +78,20 @@ public class Contact {
public String toString() { public String toString() {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("{ \"Account\":{"); sb.append("{\"id\": \"").append(id).append("\",");
sb.append("\"account_number\": \"").append(id).append("\",");
sb.append("\"phone_number\": \"").append(phone_number).append("\","); sb.append("\"phone_number\": \"").append(phone_number).append("\",");
sb.append("\"mailing_address\": ").append(mailing_address).append(",");
sb.append("\"email_address\": ").append(email_address).append(","); sb.append("\"email_address\": ").append(email_address).append(",");
sb.append("}}"); sb.append("}");
return sb.toString(); return sb.toString();
} }
public static void Write(Contact acct) throws IOException { public void save() throws IOException {
Factory.save(this);
this.status = EnumStatus.STORED;
}
public void markDeleted() {
this.status = EnumStatus.DELETED;
} }
public Integer getId() { public Integer getId() {
@@ -124,11 +130,11 @@ public class Contact {
this.phone_number = phone_number; this.phone_number = phone_number;
} }
public Address getMailing_address() { public MailAddress getMailing_address() {
return mailing_address; return mailing_address;
} }
public void setMailing_address(Address mailing_address) { public void setMailing_address(MailAddress mailing_address) {
this.mailing_address = mailing_address; this.mailing_address = mailing_address;
} }
@@ -0,0 +1,105 @@
package edu.bookocontacts.model;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.sqlite.SQLiteDataSource;
public interface DATASET {
public static PreparedStatement getPreparedStatement(String sql) throws SQLException, IOException {
File rootDir = new File(String.format("%s", DataRepositoryConfig.getPath()));
Files.createDirectories(rootDir.toPath());
SQLiteDataSource dataSource = new SQLiteDataSource();
dataSource.setUrl(String.format("jdbc:sqlite:%ssample.db", DataRepositoryConfig.getPath()));
return dataSource.getConnection().prepareStatement(sql);
}
public static List<Contact> FINDDATA() {
ArrayList<Contact> list = new ArrayList<Contact>();
try {
PreparedStatement stmt = getPreparedStatement(String.format(
"SELECT ID, FIRST_NAME, LAST_NAME, EMAIL_ADDRESS, PHONE_NUMBER, MAIL_ADDRESS FROM CONTACT;"));
ResultSet rs = stmt.executeQuery();
while (rs.next()) {
Contact ct = Factory.createContact(rs.getInt("ID"),
rs.getString("FIRST_NAME"),
rs.getString("LAST_NAME"),
new EmailAddress(rs.getString("EMAIL_ADDRESS")),
new PhoneNumber(rs.getString("PHONE_NUMBER")));
ct.status = EnumStatus.STORED;
list.add(ct);
}
} catch (Exception ex) {
Logger.getLogger(DATASET.class.getName()).log(Level.SEVERE, null, ex);
}
return list;
}
public interface DataRepositoryConfig {
public static String getPath() {
String home = System.getenv("HOME") != null ? System.getenv("HOME")
: System.getenv("HOMEDRIVE") + System.getenv("HOMEPATH");
return home.replace('\\', '/') + "/workspace/bookocontacts/db/";
}
}
public static void UPDATESERT(Contact ct) {
try {
PreparedStatement stmt = getPreparedStatement(String.format(
"SELECT ID, FIRST_NAME, LAST_NAME, EMAIL_ADDRESS, PHONE_NUMBER, MAIL_ADDRESS FROM CONTACT WHERE ID=?;"));
stmt.setInt(1, ct.getId());
ResultSet rs = stmt.executeQuery();
if (rs.next()) {
stmt.close();
stmt = getPreparedStatement(String.format(
"UPDATE CONTACT SET FIRST_NAME=?, LAST_NAME=?, EMAIL_ADDRESS=?, PHONE_NUMBER=?, MAIL_ADDRESS=? WHERE ID=?;"));
stmt.setString(1, ct.getFirst_name());
stmt.setString(2, ct.getLast_name());
stmt.setString(3, ct.getEmail().getEmail_address());
stmt.setString(4, ct.getPhoneNo().getphone_number());
stmt.setString(5, ct.getMailing_address().getMailingAddress());
stmt.setInt(6, ct.getId());
stmt.execute();
stmt.close();
} else {
stmt.close();
stmt = getPreparedStatement(String.format(
"INSERT INTO CONTACT(ID, FIRST_NAME, LAST_NAME, EMAIL_ADDRESS, PHONE_NUMBER, MAIL_ADDRESS) "
+ "VALUES(?,?,?,?,?,?);"));
stmt.setInt(1, ct.getId());
stmt.setString(2, ct.getFirst_name());
stmt.setString(3, ct.getLast_name());
stmt.setString(4, ct.getEmail().getEmail_address());
stmt.setString(5, ct.getPhoneNo().getphone_number());
stmt.setString(6, ct.getMailing_address().getMailingAddress());
stmt.execute();
stmt.close();
}
} catch (Exception ex) {
Logger.getLogger(DATASET.class.getName()).log(Level.SEVERE, null, ex);
}
}
static void DELETE(Contact ct){
try {
PreparedStatement stmt = getPreparedStatement(String.format(
"DELETE FROM CONTACT WHERE ID=?;"));
stmt.setInt(1, ct.getId());
stmt.execute();
stmt.close();
} catch (Exception ex) {
Logger.getLogger(DATASET.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
@@ -2,8 +2,15 @@ package edu.bookocontacts.model;
public class EmailAddress{ public class EmailAddress{
String email_address; String email_address;
public EmailAddress(){
this("");
}
public EmailAddress(String email_address) { public EmailAddress(String email_address) {
if (email_address == null) {
email_address = "";
return;
}
this.email_address = email_address; this.email_address = email_address;
} }
@@ -43,15 +50,14 @@ public class EmailAddress{
@Override @Override
public String toString() { public String toString() {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("{ \"EmailAddress\":{");
sb.append("\"email\": \"" + email_address + "\""); sb.append("{\"email\": \"" + email_address + "\"");
sb.append("}}"); sb.append("}");
return sb.toString(); return sb.toString();
} }
public boolean isBlank() { public boolean isBlank() {
// TODO Auto-generated method stub return this.email_address == null || this.email_address.isBlank();
throw new UnsupportedOperationException("Unimplemented method 'isBlank'");
} }
} }
@@ -0,0 +1,5 @@
package edu.bookocontacts.model;
public enum EnumStatus {
STORED,NEW,DELETED;
}
@@ -4,62 +4,32 @@
*/ */
package edu.bookocontacts.model; package edu.bookocontacts.model;
import java.util.ArrayList; import java.io.IOException;
import java.util.List; import java.util.List;
/** /**
* *
*/ */
public class Factory { public interface Factory {
static int id=0;
public static List<Person> getAll(Person clazz){
return getAllPersons();
}
public static List<Contact> getAll(Contact clazz) { public static List<Contact> getAll(Contact clazz) {
return getAllContacts(); return DATASET.FINDDATA();
} }
public static List<Person> getAllPersons() { static Contact createContact(Integer id, String first_name, String last_name, EmailAddress email,
ArrayList<Person> list = new ArrayList<>(); PhoneNumber phone_number) {
list.add(createPerson("John", 40)); Contact c = new Contact(first_name, last_name, email, phone_number, new MailAddress());
list.add(createPerson("Daisy", 21));
list.add(createPerson("Martha", 34));
list.add(createPerson("Frodo", 16));
list.add(createPerson("Mickey", 22));
list.add(createPerson("Minnie", 19));
list.add(createPerson("Donald", 30));
list.add(createPerson("Goofy", 32));
list.add(createPerson("Pokoyo", 12));
list.add(createPerson("Dora", 16));
list.add(createPerson("Tintin", 25));
list.add(createPerson("John", 52));
list.add(createPerson("Daisy", 29));
list.add(createPerson("Martha Has a very Long Name", 18));
return list;
}
static Person createPerson(String _name, int _age) {
return new Person(Integer.toString(id++),_name, _age);
}
public static List<Contact> getAllContacts() {
ArrayList<Contact> list = new ArrayList<>();
list.add(createContact(1, "Jose", "Cezone", "cezon50@yahoo.com", "410-456-9876"));
list.add(createContact(2,"Jack", "Bolt", "jbolt100@hotmail.com", "443-266-9776"));
list.add(createContact(3,"David", "Rossi", null, "210-356-9876"));
list.add(createContact(4, "Sheila", "Philster", null, "410-356-5876"));
list.add(createContact(5, "Adam", "Zhaine", null, "410-456-1876"));
list.add(createContact(6, "Amanda", "Kelstone", null, "410-456-2876"));
return list;
}
static Contact createContact(Integer id, String first_name, String last_name, String email, String phone_number) {
Contact c = new Contact(first_name, last_name, new EmailAddress(email), new PhoneNumber(phone_number), (Address)null);
c.setId(id); c.setId(id);
return c; return c;
} }
public static Contact save(final Contact ct) throws IOException {
if(ct.status==EnumStatus.DELETED){
DATASET.DELETE(ct);
}else{
DATASET.UPDATESERT(ct);
}
return ct;
}
} }
@@ -1,16 +1,17 @@
package edu.bookocontacts.model; package edu.bookocontacts.model;
public final class Address{ public final class MailAddress{
String street; String street;
String city; String city;
String state; String state;
String zip; String zip;
public Address() { public MailAddress() {
this("", "", "", "");
} }
public Address(String street, String city, String state, String zip) { public MailAddress(String street, String city, String state, String zip) {
this.street = street; this.street = street;
this.city = city; this.city = city;
this.state = state; this.state = state;
@@ -49,14 +50,22 @@ public final class Address{
this.zip = zip; this.zip = zip;
} }
public String getMailingAddress(){
return String.format( "%s %s %s %s", formatField(this.street), formatField(this.city), this.state, this.zip );
}
private String formatField(String field){
return field == null || field.isBlank()? "": field.trim() + ",";
}
@Override @Override
public int hashCode() { public int hashCode() {
final int prime = 31; final int prime = 31;
int result = 1; int result = 1;
result = prime * result + ((street == null) ? 0 : street.hashCode()); result = prime * result + ((street.isBlank()) ? 0 : street.hashCode());
result = prime * result + ((city == null) ? 0 : city.hashCode()); result = prime * result + ((city.isBlank()) ? 0 : city.hashCode());
result = prime * result + ((state == null) ? 0 : state.hashCode()); result = prime * result + ((state.isBlank()) ? 0 : state.hashCode());
result = prime * result + ((zip == null) ? 0 : zip.hashCode()); result = prime * result + ((zip.isBlank()) ? 0 : zip.hashCode());
return result; return result;
} }
@@ -68,7 +77,7 @@ public final class Address{
return false; return false;
if (getClass() != obj.getClass()) if (getClass() != obj.getClass())
return false; return false;
Address other = (Address) obj; MailAddress other = (MailAddress) obj;
if (street == null) { if (street == null) {
if (other.street != null) if (other.street != null)
return false; return false;
@@ -95,7 +104,7 @@ public final class Address{
@Override @Override
public String toString() { public String toString() {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("{ \"Address\":{"); sb.append("{ \"MailAddress\":{");
sb.append("\"street\": \"" + street + "\","); sb.append("\"street\": \"" + street + "\",");
sb.append("\"city\": \"" + city + "\","); sb.append("\"city\": \"" + city + "\",");
sb.append("\"state\": \"" + state + "\","); sb.append("\"state\": \"" + state + "\",");
@@ -103,4 +112,15 @@ public final class Address{
sb.append("}}"); sb.append("}}");
return sb.toString(); return sb.toString();
} }
public Boolean isBlank() {
if(street.isBlank() && city.isBlank() && state.isBlank()) {
return true;
}
if( zip == null || zip.isBlank() ) {
return true;
}
return false;
}
} }
@@ -1,47 +0,0 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package edu.bookocontacts.model;
/**
*
*/
public class Person {
String Id; String Name; int Age;
public Person(final String Id, final String Name, final int Age) {
this.Id=Id;
this.Name = Name;
this.Age = Age;
}
public Person() {
this("", "", 0);
}
public String getId() {
return Id;
}
public void setId(final String id) {
Id = id;
}
public String getName() {
return Name;
}
public void setName(final String name) {
Name = name;
}
public int getAge() {
return Age;
}
public void setAge(final int age) {
Age = age;
}
}
@@ -29,30 +29,30 @@
</rowConstraints> </rowConstraints>
<children> <children>
<Label text="First Name:" /> <Label text="First Name:" />
<TextField id="txFirstName" promptText="First Name" GridPane.columnIndex="1" /> <TextField id="tfFirstName" fx:id="tfFirstName" promptText="First Name" GridPane.columnIndex="1" />
<Label text="Last Name:" GridPane.rowIndex="1" /> <Label text="Last Name:" GridPane.rowIndex="1" />
<TextField id="tfLastName" promptText="Last Name" GridPane.columnIndex="1" GridPane.rowIndex="1" /> <TextField id="tfLastName" fx:id="tfLastName" promptText="Last Name" GridPane.columnIndex="1" GridPane.rowIndex="1" />
<Label text="Phone No:" underline="true" GridPane.rowIndex="2"> <Label text="Phone No:" underline="true" GridPane.rowIndex="2">
<font> <font>
<Font name="System Bold" size="12.0" /> <Font name="System Bold" size="12.0" />
</font> </font>
</Label> </Label>
<TextField id="tfPhoneNo" promptText="Phone Number" GridPane.columnIndex="1" GridPane.rowIndex="2" /> <TextField id="tfPhoneNo" fx:id="tfPhoneNo" promptText="Phone Number" GridPane.columnIndex="1" GridPane.rowIndex="2" />
<Label text="Email:" GridPane.rowIndex="3" /> <Label text="Email:" GridPane.rowIndex="3" />
<TextField id="tfEmail" promptText="Email Address" GridPane.columnIndex="1" GridPane.rowIndex="3" /> <TextField id="tfEmail" fx:id="tfEmail" promptText="Email Address" GridPane.columnIndex="1" GridPane.rowIndex="3" />
<Label text="Address:" underline="true" GridPane.rowIndex="4"> <Label text="Address:" underline="true" GridPane.rowIndex="4">
<font> <font>
<Font name="System Bold" size="12.0" /> <Font name="System Bold" size="12.0" />
</font> </font>
</Label> </Label>
<Separator GridPane.columnIndex="1" GridPane.rowIndex="4" /> <Separator GridPane.columnIndex="1" GridPane.rowIndex="4" />
<TextField id="tfStreet" promptText="Street" GridPane.columnIndex="1" GridPane.rowIndex="4"> <TextField id="tfStreet" fx:id="tfStreet" promptText="Street" GridPane.columnIndex="1" GridPane.rowIndex="4">
<GridPane.margin> <GridPane.margin>
<Insets top="4.0" /> <Insets top="4.0" />
</GridPane.margin></TextField> </GridPane.margin></TextField>
<TextField id="tfCity" promptText="City" GridPane.columnIndex="1" GridPane.rowIndex="5" /> <TextField id="tfCity" fx:id="tfCity" promptText="City" GridPane.columnIndex="1" GridPane.rowIndex="5" />
<TextField id="tfState" promptText="State" GridPane.columnIndex="1" GridPane.rowIndex="6" /> <TextField id="tfState" fx:id="tfState" promptText="State" GridPane.columnIndex="1" GridPane.rowIndex="6" />
<TextField id="tfZip" promptText="Zip" GridPane.columnIndex="1" GridPane.rowIndex="7" /> <TextField id="tfZip" fx:id="tfZip" promptText="Zip" GridPane.columnIndex="1" GridPane.rowIndex="7" />
</children> </children>
</GridPane> </GridPane>
+10 -10
View File
@@ -12,25 +12,25 @@
<AnchorPane id="AnchorPane" prefHeight="383.0" prefWidth="565.0" xmlns="http://javafx.com/javafx/25" xmlns:fx="http://javafx.com/fxml/1" fx:controller="edu.bookocontacts.ViewController"> <AnchorPane id="AnchorPane" prefHeight="383.0" prefWidth="565.0" xmlns="http://javafx.com/javafx/25" xmlns:fx="http://javafx.com/fxml/1" fx:controller="edu.bookocontacts.ViewController">
<children> <children>
<TableView fx:id="personView" layoutX="1.0" layoutY="76.0" prefHeight="226.0" prefWidth="564.0"> <TableView fx:id="contactView" layoutX="1.0" layoutY="76.0" prefHeight="226.0" prefWidth="564.0">
<columns> <columns>
<TableColumn fx:id="personViewIdCol" maxWidth="5000.0" minWidth="10.0" prefWidth="116.0" resizable="true" /> <TableColumn fx:id="contactViewIdCol" maxWidth="5000.0" minWidth="10.0" prefWidth="116.0" resizable="true" text="Id"/>
<TableColumn fx:id="personViewNameCol" maxWidth="5000.0" minWidth="10.0" prefWidth="124.0" resizable="true" text="Name" /> <TableColumn fx:id="contactViewNameCol" maxWidth="5000.0" minWidth="10.0" prefWidth="124.0" resizable="true" text="Name" />
<TableColumn fx:id="personViewPhoneNoCol" maxWidth="5000.0" minWidth="10.0" prefWidth="93.0" resizable="true" text="Phone" /> <TableColumn fx:id="contactViewPhoneNoCol" maxWidth="5000.0" minWidth="10.0" prefWidth="93.0" resizable="true" text="Phone" />
</columns> </columns>
</TableView> </TableView>
<HBox layoutX="85.0" layoutY="308.0" prefHeight="64.0" prefWidth="377.0"> <HBox layoutX="85.0" layoutY="290.0" prefHeight="64.0" prefWidth="400.0">
<children> <children>
<Pagination fx:id="pagination" prefHeight="65.0" prefWidth="334.0" /> <Pagination fx:id="pagination" prefHeight="65.0" prefWidth="380.0" />
</children></HBox> </children></HBox>
<Button id="AddBtn" fx:id="save" layoutX="126.0" layoutY="35.0" mnemonicParsing="false" text="Add" textFill="#0052cc" textOverrun="CLIP" /> <Button id="btnAdd" fx:id="btnAdd" layoutX="126.0" layoutY="35.0" mnemonicParsing="false" text="Add" textFill="#0052cc" textOverrun="CLIP" />
<Text fill="#1400ff" layoutX="25.0" layoutY="33.0" scaleX="1.393175914330746" scaleY="1.5976504915765308" strokeType="OUTSIDE" strokeWidth="0.0" text="Contacts" wrappingWidth="85.3748550415039"> <Text fill="#1400ff" layoutX="25.0" layoutY="33.0" scaleX="1.393175914330746" scaleY="1.5976504915765308" strokeType="OUTSIDE" strokeWidth="0.0" text="Contacts" wrappingWidth="85.3748550415039">
<font> <font>
<Font name="System Bold" size="16.0" /> <Font name="System Bold" size="16.0" />
</font> </font>
</Text> </Text>
<TextField id="SrchTxt" layoutX="228.0" layoutY="36.0" prefHeight="25.0" prefWidth="187.0" promptText="Search" /> <TextField id="txtSrch" fx:id="txtSrch" layoutX="236.0" layoutY="36.0" prefHeight="25.0" prefWidth="187.0" promptText="Search" />
<Button id="DelBtn" fx:id="save1" layoutX="427.0" layoutY="36.0" mnemonicParsing="false" text="Del" textFill="#0052cc" textOverrun="CLIP" /> <Button id="btnDel" fx:id="btnDel" layoutX="427.0" layoutY="36.0" mnemonicParsing="false" text="Del" textFill="#0052cc" textOverrun="CLIP" />
<Button id="SrchBtn" fx:id="save2" layoutX="174.0" layoutY="35.0" mnemonicParsing="false" text="Search" textFill="#0052cc" textOverrun="CLIP" /> <Button id="btnSrch" fx:id="btnSrch" layoutX="174.0" layoutY="35.0" mnemonicParsing="false" text="Search" textFill="#0052cc" textOverrun="CLIP" />
</children> </children>
</AnchorPane> </AnchorPane>