diff --git a/.classpath b/.classpath index 5dea8e9..ba36a3e 100644 --- a/.classpath +++ b/.classpath @@ -1,12 +1,12 @@ - + - + diff --git a/.gradle/9.3.1/executionHistory/executionHistory.bin b/.gradle/9.3.1/executionHistory/executionHistory.bin index 22f042b..82e44fe 100755 Binary files a/.gradle/9.3.1/executionHistory/executionHistory.bin and b/.gradle/9.3.1/executionHistory/executionHistory.bin differ diff --git a/.gradle/9.3.1/executionHistory/executionHistory.lock b/.gradle/9.3.1/executionHistory/executionHistory.lock index 6d9f647..88bcc6e 100755 Binary files a/.gradle/9.3.1/executionHistory/executionHistory.lock and b/.gradle/9.3.1/executionHistory/executionHistory.lock differ diff --git a/.gradle/9.3.1/fileHashes/fileHashes.bin b/.gradle/9.3.1/fileHashes/fileHashes.bin index 761bfc0..52eb60d 100755 Binary files a/.gradle/9.3.1/fileHashes/fileHashes.bin and b/.gradle/9.3.1/fileHashes/fileHashes.bin differ diff --git a/.gradle/9.3.1/fileHashes/fileHashes.lock b/.gradle/9.3.1/fileHashes/fileHashes.lock index 260adc6..aa5238a 100755 Binary files a/.gradle/9.3.1/fileHashes/fileHashes.lock and b/.gradle/9.3.1/fileHashes/fileHashes.lock differ diff --git a/.gradle/9.3.1/fileHashes/resourceHashesCache.bin b/.gradle/9.3.1/fileHashes/resourceHashesCache.bin index 0755d68..6d9592e 100755 Binary files a/.gradle/9.3.1/fileHashes/resourceHashesCache.bin and b/.gradle/9.3.1/fileHashes/resourceHashesCache.bin differ diff --git a/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/.gradle/buildOutputCleanup/buildOutputCleanup.lock index bae36ae..1d3ff0a 100755 Binary files a/.gradle/buildOutputCleanup/buildOutputCleanup.lock and b/.gradle/buildOutputCleanup/buildOutputCleanup.lock differ diff --git a/.gradle/file-system.probe b/.gradle/file-system.probe index 0058cb9..80b0e7d 100755 Binary files a/.gradle/file-system.probe and b/.gradle/file-system.probe differ diff --git a/.settings/org.eclipse.buildship.core.prefs b/.settings/org.eclipse.buildship.core.prefs index e479558..8e50e0f 100644 --- a/.settings/org.eclipse.buildship.core.prefs +++ b/.settings/org.eclipse.buildship.core.prefs @@ -1,13 +1,13 @@ -arguments= -auto.sync=false +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=true build.scans.enabled=false connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER) connection.project.dir= eclipse.preferences.version=1 gradle.user.home= -java.home= +java.home=/usr/lib/jvm/java-25-openjdk jvm.arguments= offline.mode=false -override.workspace.settings=false -show.console.view=false -show.executions.view=false +override.workspace.settings=true +show.console.view=true +show.executions.view=true diff --git a/.vscode/launch.json b/.vscode/launch.json index 0f3c80c..8c2a506 100755 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -4,18 +4,25 @@ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ + { + "type": "java", + "name": "View", + "request": "launch", + "mainClass": "edu.bookocontacts.AppSceneView", + "projectName": "bookocontacts" + }, { "type": "java", "name": "Windows Current File", "request": "launch", - "mainClass": "${file}", + "mainClass": "edu.bookocontacts.AppSceneView", "vmArgs": " --module-path 'C://Program Files//javafx-25//lib' --add-modules ALL-MODULE-PATH --enable-native-access=javafx.graphics" }, { "type": "java", "name": "Linux Current File", "request": "launch", - "mainClass": "${file}", + "mainClass": "edu.bookocontacts.AppSceneView", "vmArgs": " --module-path '/home/sherwinp/workspace/javafx-sdk/lib/' --add-modules ALL-MODULE-PATH --enable-native-access=javafx.graphics" } ] diff --git a/build.gradle b/build.gradle index 66b3107..95429ef 100755 --- a/build.gradle +++ b/build.gradle @@ -23,7 +23,7 @@ repositories { } application { - mainClass = 'edu.bookocontacts.View' + mainClass = 'edu.bookocontacts.AppSceneView' } sourceSets { @@ -44,9 +44,12 @@ dependencies { implementation("ch.qos.logback:logback-classic:1.5.26") implementation("org.aspectj:aspectjrt:1.9.25") - implementation 'org.openjfx:javafx-base:25.0.2' - implementation 'org.openjfx:javafx-fxml:25.0.2' - implementation 'org.openjfx:javafx-controls:25.0.2' + implementation 'org.xerial:sqlite-jdbc:3.51.2.0' + implementation 'jakarta.activation:jakarta.activation-api:2.1.4' + + implementation 'org.openjfx:javafx-base:25.0.2' + implementation 'org.openjfx:javafx-fxml:25.0.2' + implementation 'org.openjfx:javafx-controls:25.0.2' } diff --git a/db/sample.db b/db/sample.db new file mode 100644 index 0000000..e69de29 diff --git a/src/main/java/edu/bookocontacts/View.java b/src/main/java/edu/bookocontacts/AppSceneView.java similarity index 94% rename from src/main/java/edu/bookocontacts/View.java rename to src/main/java/edu/bookocontacts/AppSceneView.java index 5669337..7b79ba8 100755 --- a/src/main/java/edu/bookocontacts/View.java +++ b/src/main/java/edu/bookocontacts/AppSceneView.java @@ -15,7 +15,7 @@ import javafx.stage.Stage; /** * */ -public class View extends Application { +public class AppSceneView extends Application { private Stage stage; @Override @@ -47,6 +47,9 @@ public class View extends Application { in.close(); } } + + DATASET.FINDDATA(); + } catch (Exception ex) { Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex); } diff --git a/src/main/java/edu/bookocontacts/ControlDDXDialog.java b/src/main/java/edu/bookocontacts/ControlDDXDialog.java new file mode 100644 index 0000000..fb28502 --- /dev/null +++ b/src/main/java/edu/bookocontacts/ControlDDXDialog.java @@ -0,0 +1,79 @@ +package edu.bookocontacts; + +import java.io.IOException; +import java.util.logging.Level; +import java.util.logging.Logger; + +import javafx.fxml.FXML; +import javafx.fxml.FXMLLoader; +import javafx.scene.control.ButtonType; +import javafx.scene.control.Dialog; +import javafx.scene.control.TextField; +import javafx.util.Callback; + +import edu.bookocontacts.model.Address; + +public class ControlDDXDialog extends Dialog
{ + + @FXML + private TextField tfStreet; + @FXML + private TextField tfCity; + @FXML + private TextField tfState; + @FXML + private TextField tfZip; + + public ControlDDXDialog() { + super(); + String fxml = "/media/ControlAddressDDXDialog.fxml"; + FXMLLoader fxmlLoader = new FXMLLoader(getClass().getClassLoader().getResource(fxml)); + fxmlLoader.setController(this); + fxmlLoader.setLocation(getClass().getResource(fxml)); + try { + fxmlLoader.load(); + } catch (IOException exception) { + throw new RuntimeException(exception); + } + getDialogPane().setContent(fxmlLoader.getRoot()); + getDialogPane().getButtonTypes().addAll(ButtonType.OK, ButtonType.CANCEL); + setTitle("Contact Address Dialog"); + setHeaderText("Enter Details"); + setPropertyBindings(); + setResultConverter(); + } + + private void setPropertyBindings() { + Logger.getLogger(getClass().getName()).log(Level.INFO, "setPropertyBindings called."); + } + + private void setResultConverter() { + Logger.getLogger(getClass().getName()).log(Level.INFO, "setResultConverter called."); + Callback aRC = (buttonType) -> { + if (buttonType == ButtonType.OK) { + if (getStreet().isEmpty() || getCity().isEmpty() || getState().isEmpty() || getZip().isEmpty()) { + return null; + } + return new Address(getStreet(), getCity(), getState(), getZip()); + } + return null; + }; + setResultConverter(aRC); + } + + private String getZip() { + return tfZip.getText(); + } + + private String getState() { + return tfState.getText(); + } + + private String getCity() { + return tfCity.getText(); + } + + private String getStreet() { + return tfStreet.getText(); + } +} diff --git a/src/main/java/edu/bookocontacts/DATASET.java b/src/main/java/edu/bookocontacts/DATASET.java new file mode 100644 index 0000000..4d27d93 --- /dev/null +++ b/src/main/java/edu/bookocontacts/DATASET.java @@ -0,0 +1,38 @@ +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 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/"; + } + } +} diff --git a/src/main/java/edu/bookocontacts/ViewController.java b/src/main/java/edu/bookocontacts/ViewController.java index bb37565..0dcec57 100755 --- a/src/main/java/edu/bookocontacts/ViewController.java +++ b/src/main/java/edu/bookocontacts/ViewController.java @@ -7,12 +7,15 @@ 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.PersonFactory; +import edu.bookocontacts.model.Address; +import edu.bookocontacts.model.Contact; import java.net.URL; import java.util.Collections; import java.util.Comparator; +import java.util.Optional; import java.util.ResourceBundle; import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; @@ -68,18 +71,17 @@ public class ViewController implements Initializable { private int currentPageIndex = 0; private boolean order = true; - private void log(String message){ + private void log(String message) { logger.log(Level.FINE, message); } /** * Initializes the controller class. */ - @Override - public void initialize(URL url, ResourceBundle rb) { + public void initialize(URL location, ResourceBundle resources) { log("initialize"); - persons = FXCollections.observableArrayList(PersonFactory.getAllPersons()); - log(String.format("Person size: %d" , persons.size())); + persons = FXCollections.observableArrayList(Factory.getAll(new Person())); + log(String.format("Person size: %d", persons.size())); sort(); initializeTable(); @@ -100,12 +102,22 @@ public class ViewController implements Initializable { save.setOnAction(new javafx.event.EventHandler() { @Override public void handle(javafx.event.ActionEvent t) { - persons.add(new Person(idTxt.getText(), nameTxt.getText(), Integer.valueOf(ageTxt.getText()))); - sort(); - updatePersonView(); - idTxt.setText(null); - nameTxt.setText(null); - ageTxt.setText(null); + + ControlDDXDialog dialog = new ControlDDXDialog(); + + Optional
result = dialog.showAndWait(); + + if (result.isPresent()) { + System.out.println("result is present."); + // add to storage + // persons.add((Address) result.get()); + // bind to model + // tvInventory.refresh(); + // + // sort(); + // updatePersonView(); + + } } }); @@ -137,7 +149,11 @@ public class ViewController implements Initializable { public void updatePersonView() { log("updatePersonView"); - personView.getItems().setAll(persons.subList(currentPageIndex * itemsPerPage, ((currentPageIndex * itemsPerPage + itemsPerPage <= persons.size()) ? currentPageIndex * itemsPerPage + itemsPerPage : persons.size()))); + personView.getItems() + .setAll(persons.subList(currentPageIndex * itemsPerPage, + ((currentPageIndex * itemsPerPage + itemsPerPage <= persons.size()) + ? currentPageIndex * itemsPerPage + itemsPerPage + : persons.size()))); } private void initializeTable() { @@ -148,7 +164,8 @@ public class ViewController implements Initializable { personViewNameCol.setCellValueFactory(new PropertyValueFactory("Name")); personViewNameCol.sortTypeProperty().addListener(new ChangeListener() { @Override - public void changed(ObservableValue paramObservableValue, SortType paramT1, SortType paramT2) { + public void changed(ObservableValue paramObservableValue, SortType paramT1, + SortType paramT2) { log("NAME Clicked -- sortType = " + paramT1 + ", SortType=" + paramT2); id.setGraphic(null); } @@ -181,4 +198,5 @@ public class ViewController implements Initializable { log("floatCount=" + floatCount + ", intCount=" + intCount); return ((floatCount > intCount) ? ++intCount : intCount); } + } diff --git a/src/main/java/edu/bookocontacts/model/PersonFactory.java b/src/main/java/edu/bookocontacts/model/Factory.java similarity index 70% rename from src/main/java/edu/bookocontacts/model/PersonFactory.java rename to src/main/java/edu/bookocontacts/model/Factory.java index 6339ecf..60855f9 100755 --- a/src/main/java/edu/bookocontacts/model/PersonFactory.java +++ b/src/main/java/edu/bookocontacts/model/Factory.java @@ -10,8 +10,16 @@ import java.util.List; /** * */ -public class PersonFactory { +public class Factory { static int id=0; + + public static List getAll(Person clazz){ + return getAllPersons(); + } + + public static List getAll(Contact clazz){ + return getAllContacts(); + } public static List getAllPersons() { ArrayList list = new ArrayList<>(); @@ -31,8 +39,18 @@ public class PersonFactory { 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 getAllContacts() { + ArrayList list = new ArrayList<>(); + return list; + } + + static Person createContact(String _name, int _age) { + return new Person(Integer.toString(id++),_name, _age); + } + } diff --git a/src/main/java/edu/bookocontacts/model/Person.java b/src/main/java/edu/bookocontacts/model/Person.java index c7fa868..930c91c 100755 --- a/src/main/java/edu/bookocontacts/model/Person.java +++ b/src/main/java/edu/bookocontacts/model/Person.java @@ -8,49 +8,40 @@ package edu.bookocontacts.model; * */ public class Person { - String id; - String name; - int age; + 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 Person(String id, String name, int age) { - this.id = id; - this.name = name; - this.age = age; - } - - public String getId() { - return id; + return Id; } - public void setId(String id) { - this.id = id; + public void setId(final String id) { + Id = id; } public String getName() { - return name; + return Name; } - public void setName(String name) { - this.name = name; + public void setName(final String name) { + Name = name; } public int getAge() { - return age; + return Age; } - public void setAge(int age) { - this.age = age; + public void setAge(final int age) { + Age = age; } - @Override - public String toString() { - return "Person{" + "id=" + id + ", name=" + name + ", age=" + age + '}'; - } - - - -} +} \ No newline at end of file diff --git a/src/main/resources/media/ControlAddressDDXDialog.fxml b/src/main/resources/media/ControlAddressDDXDialog.fxml new file mode 100644 index 0000000..7e5f1b5 --- /dev/null +++ b/src/main/resources/media/ControlAddressDDXDialog.fxml @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + + + + + + + + + + +