update project.

This commit is contained in:
2026-02-18 23:06:25 -05:00
parent 41dd1d00ab
commit e436b4a3c9
17 changed files with 69 additions and 62 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.
Binary file not shown.
Binary file not shown.
+6 -6
View File
@@ -1,13 +1,13 @@
arguments=--init-script C\:\\Users\\sherw\\AppData\\Roaming\\VSCodium\\User\\globalStorage\\redhat.java\\1.52.0\\config_win\\org.eclipse.osgi\\58\\0\\.cp\\gradle\\init\\init.gradle --init-script C\:\\Users\\sherw\\AppData\\Roaming\\VSCodium\\User\\globalStorage\\redhat.java\\1.52.0\\config_win\\org.eclipse.osgi\\58\\0\\.cp\\gradle\\protobuf\\init.gradle
auto.sync=true
arguments=
auto.sync=false
build.scans.enabled=false
connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER)
connection.project.dir=
eclipse.preferences.version=1
gradle.user.home=
java.home=C\:/Program Files/jdk-26
java.home=
jvm.arguments=
offline.mode=false
override.workspace.settings=true
show.console.view=true
show.executions.view=true
override.workspace.settings=false
show.console.view=false
show.executions.view=false
@@ -64,7 +64,7 @@ public class ControlDDXDialog extends Dialog<Contact> {
Callback<ButtonType, Contact> aRC = (buttonType) -> {
if (buttonType == ButtonType.OK) {
if (getFirstName().isBlank() && (getEmail().isBlank() || getPhoneNumber().isBlank())) {
if (getFirstName().isBlank() && (getEmail().isBlank() || getPhoneNo().isBlank())) {
return null;
}
if (getFirstName().isBlank() || getStreet().isEmpty() || getCity().isEmpty() || getState().isEmpty()
@@ -72,8 +72,8 @@ public class ControlDDXDialog extends Dialog<Contact> {
return null;
}
return new Contact(getFirstName(), getLastName(), new PhoneNumber(getPhoneNumber()),
new EmailAddress(getEmail()), new Address(getStreet(), getCity(), getState(), getZip()));
return new Contact(getFirstName(), getLastName(), new EmailAddress(getEmail()),
new PhoneNumber(getPhoneNo()), new Address(getStreet(), getCity(), getState(), getZip()));
}
return null;
};
@@ -88,7 +88,7 @@ public class ControlDDXDialog extends Dialog<Contact> {
return "";
}
private String getPhoneNumber() {
private String getPhoneNo() {
return "";
}
@@ -10,6 +10,7 @@ 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;
@@ -42,29 +43,24 @@ public class ViewController implements Initializable {
Logger logger = Logger.getLogger(getClass().getName());
@FXML
private TableView<Person> personView = new TableView<>();
private TableView<Contact> personView = new TableView<>();
@FXML
private TableColumn<Person, String> personViewIdCol;
private TableColumn<Contact, String> personViewIdCol;
@FXML
private TableColumn<Person, String> personViewNameCol;
private TableColumn<Contact, String> personViewNameCol;
@FXML
private TableColumn<Person, Integer> personViewAgeCol;
private TableColumn<Contact, PhoneNumber> personViewPhoneNoCol;
@FXML
Pagination pagination;
@FXML
private Button save;
@FXML
private TextField idTxt;
@FXML
private TextField nameTxt;
@FXML
private TextField ageTxt;
private Button id = new Button("ID");
private ImageView upImg = new ImageView(new Image("/media/up.png"));
private ImageView downImg = new ImageView(new Image("/media/down.png"));
private ObservableList<Person> persons = null;
private ObservableList<Contact> contacts = null;
private int pageCount = 5;
private int itemsPerPage = 4;
@@ -72,7 +68,7 @@ public class ViewController implements Initializable {
private boolean order = true;
private void log(String message) {
logger.log(Level.FINE, message);
logger.log(Level.INFO, message);
}
/**
@@ -80,12 +76,12 @@ public class ViewController implements Initializable {
*/
public void initialize(URL location, ResourceBundle resources) {
log("initialize");
persons = FXCollections.observableArrayList(Factory.getAll(new Person()));
log(String.format("Person size: %d", persons.size()));
contacts = FXCollections.observableArrayList(Factory.getAll(new Contact()));
log(String.format("Person size: %d", contacts.size()));
sort();
initializeTable();
pageCount = getPageCount(persons.size(), itemsPerPage);
pageCount = getPageCount(contacts.size(), itemsPerPage);
log("pageCount=" + pageCount);
pagination.setPageCount(pageCount);
@@ -108,9 +104,9 @@ public class ViewController implements Initializable {
Optional<Contact> result = dialog.showAndWait();
if (result.isPresent()) {
System.out.println("result is present.");
log("result is present.");
// add to storage
// persons.add((Address) result.get());
// contacts.add((Address) result.get());
// bind to model
// tvInventory.refresh();
//
@@ -126,9 +122,9 @@ public class ViewController implements Initializable {
public void handle(javafx.event.ActionEvent t) {
sort();
if (order) {
Collections.reverse(persons);
Collections.reverse(contacts);
}
log(" order = " + order + "; data = " + persons);
log(" order = " + order + "; data = " + contacts);
order = !order;
id.setGraphic((order) ? upImg : downImg);
updatePersonView();
@@ -138,9 +134,9 @@ public class ViewController implements Initializable {
}
private void sort() {
Collections.sort(persons, new Comparator<Person>() {
Collections.sort(contacts, new Comparator<Contact>() {
@Override
public int compare(Person t, Person t1) {
public int compare(Contact t, Contact t1) {
log(" comparator called");
return t.getId().compareTo(t1.getId());
}
@@ -148,20 +144,20 @@ public class ViewController implements Initializable {
}
public void updatePersonView() {
log("updatePersonView");
log("update View");
personView.getItems()
.setAll(persons.subList(currentPageIndex * itemsPerPage,
((currentPageIndex * itemsPerPage + itemsPerPage <= persons.size())
.setAll(contacts.subList(currentPageIndex * itemsPerPage,
((currentPageIndex * itemsPerPage + itemsPerPage <= contacts.size())
? currentPageIndex * itemsPerPage + itemsPerPage
: persons.size())));
: contacts.size())));
}
private void initializeTable() {
personViewIdCol.setCellValueFactory(new PropertyValueFactory<Person, String>("Id"));
personViewIdCol.setCellValueFactory(new PropertyValueFactory<Contact, String>("Id"));
id.setGraphic(upImg);
personViewIdCol.setGraphic(id);
personViewIdCol.setSortable(false);
personViewNameCol.setCellValueFactory(new PropertyValueFactory<Person, String>("Name"));
personViewNameCol.setCellValueFactory(new PropertyValueFactory<Contact, String>("Name"));
personViewNameCol.sortTypeProperty().addListener(new ChangeListener<SortType>() {
@Override
public void changed(ObservableValue<? extends SortType> paramObservableValue, SortType paramT1,
@@ -170,10 +166,10 @@ public class ViewController implements Initializable {
id.setGraphic(null);
}
});
personViewAgeCol.setCellValueFactory(new PropertyValueFactory<Person, Integer>("Age"));
personViewAgeCol.setText("AGE");
personViewAgeCol.setSortable(false);
personView.getItems().setAll(persons.subList(0, itemsPerPage));
personViewPhoneNoCol.setCellValueFactory(new PropertyValueFactory<Contact, PhoneNumber>("PhoneNo"));
personViewPhoneNoCol.setText("PhoneNo");
personViewPhoneNoCol.setSortable(false);
personView.getItems().setAll(contacts.subList(0, itemsPerPage));
}
public int getItemsPerPage() {
@@ -23,7 +23,7 @@ public class Contact {
this.last_name = last_name;
}
public Contact(String first_name, String last_name, PhoneNumber phone_number, EmailAddress email_address,
public Contact(String first_name, String last_name, EmailAddress email_address, PhoneNumber phone_number,
Address mailing_address)
throws IllegalArgumentException {
this.phone_number = phone_number;
@@ -33,14 +33,8 @@ public class Contact {
this.first_name = first_name;
this.last_name = last_name;
if (phone_number == null) {
throw new IllegalArgumentException(String.format("%s %s", "Contact: requires phone number"));
}
if (mailing_address == null) {
throw new IllegalArgumentException(String.format("%s %s", "Contact: requires mailing address"));
}
if (email_address == null) {
throw new IllegalArgumentException(String.format("%s %s", "Contact: requires email address"));
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"));
}
this.phone_number = phone_number;
@@ -122,7 +116,7 @@ public class Contact {
this.last_name = last_name;
}
public PhoneNumber getPhone_number() {
public PhoneNumber getPhoneNo() {
return phone_number;
}
@@ -138,11 +132,11 @@ public class Contact {
this.mailing_address = mailing_address;
}
public EmailAddress getEmail_address() {
public EmailAddress getEmail() {
return email_address;
}
public void setEmail_address(EmailAddress email_address) {
public void setEmail(EmailAddress email_address) {
this.email_address = email_address;
}
@@ -188,7 +182,7 @@ public class Contact {
}
public void update(Contact ct) {
this.setEmail_address(ct.email_address);
this.setEmail(ct.email_address);
this.setPhone_number(ct.phone_number);
this.setMailing_address(ct.mailing_address);
}
@@ -49,4 +49,9 @@ public class EmailAddress{
return sb.toString();
}
public boolean isBlank() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'isBlank'");
}
}
@@ -46,11 +46,20 @@ public class Factory {
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 Person createContact(String _name, int _age) {
return new Person(Integer.toString(id++),_name, _age);
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);
return c;
}
}
@@ -5,6 +5,9 @@ public class PhoneNumber {
public PhoneNumber(String phone_number) {
this.phone_number = phone_number;
if( phone_number == null ){
phone_number = "";
}
}
public String getphone_number() {
@@ -42,10 +45,10 @@ public class PhoneNumber {
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("{ \"PhoneNumber\":{");
sb.append("\"phone\": \"" + phone_number + "\"");
sb.append("}}");
return sb.toString();
return String.format("%s", phone_number);
}
public boolean isBlank() {
return this.phone_number == null || this.phone_number.isBlank();
}
}
+1 -1
View File
@@ -16,7 +16,7 @@
<columns>
<TableColumn fx:id="personViewIdCol" maxWidth="5000.0" minWidth="10.0" prefWidth="116.0" resizable="true" />
<TableColumn fx:id="personViewNameCol" maxWidth="5000.0" minWidth="10.0" prefWidth="124.0" resizable="true" text="Name" />
<TableColumn fx:id="personViewAgeCol" maxWidth="5000.0" minWidth="10.0" prefWidth="93.0" resizable="true" text="Age" />
<TableColumn fx:id="personViewPhoneNoCol" maxWidth="5000.0" minWidth="10.0" prefWidth="93.0" resizable="true" text="Phone" />
</columns>
</TableView>
<HBox layoutX="85.0" layoutY="308.0" prefHeight="64.0" prefWidth="377.0">