From a497b0fcbbfe3ccfeebab619f1ea153896467a8f Mon Sep 17 00:00:00 2001 From: Ivan Olexyn Date: Sat, 7 Mar 2020 03:50:20 +0100 Subject: [PATCH] Merge Person with SyncDirectory. --- src/com/olexyn/ensync/Flow.java | 16 +- src/com/olexyn/ensync/Person.java | 44 ---- src/com/olexyn/ensync/PersonTableData.java | 3 +- src/com/olexyn/ensync/TableAppController.java | 53 ++--- .../ensync/artifacts/SyncDirectory.java | 58 ++++- .../{SyncEntity.java => SyncMap.java} | 10 +- src/com/olexyn/ensync/layout.fxml | 205 ++++++++---------- 7 files changed, 164 insertions(+), 225 deletions(-) delete mode 100644 src/com/olexyn/ensync/Person.java rename src/com/olexyn/ensync/artifacts/{SyncEntity.java => SyncMap.java} (79%) diff --git a/src/com/olexyn/ensync/Flow.java b/src/com/olexyn/ensync/Flow.java index d95a968..5e04fd2 100644 --- a/src/com/olexyn/ensync/Flow.java +++ b/src/com/olexyn/ensync/Flow.java @@ -1,11 +1,9 @@ package com.olexyn.ensync; import com.olexyn.ensync.artifacts.SyncDirectory; -import com.olexyn.ensync.artifacts.SyncEntity; -import com.olexyn.ensync.artifacts.SyncFile; +import com.olexyn.ensync.artifacts.SyncMap; import java.io.File; -import java.util.List; import java.util.Map; public class Flow { @@ -26,13 +24,13 @@ public class Flow { Execute x = new Execute(); - SyncEntity syncEntity = new SyncEntity("test"); - syncEntity.addDirectory("/home/user/test/a"); - syncEntity.addDirectory("/home/user/test/b"); - //syncEntity.addDirectory("/home/user/test/c"); + SyncMap syncMap = new SyncMap("test"); + syncMap.addDirectory("/home/user/test/a"); + syncMap.addDirectory("/home/user/test/b"); + //syncMap.addDirectory("/home/user/test/c"); - for (Map.Entry entry : syncEntity.syncDirectories.entrySet()) { + for (Map.Entry entry : syncMap.syncDirectories.entrySet()) { SyncDirectory syncDirectory = entry.getValue(); String path = syncDirectory.path; String stateFilePath = syncDirectory.stateFilePath(path); @@ -47,7 +45,7 @@ public class Flow { while (true) { - for (Map.Entry entry : syncEntity.syncDirectories.entrySet()) { + for (Map.Entry entry : syncMap.syncDirectories.entrySet()) { SyncDirectory syncDirectory = entry.getValue(); diff --git a/src/com/olexyn/ensync/Person.java b/src/com/olexyn/ensync/Person.java deleted file mode 100644 index f28f266..0000000 --- a/src/com/olexyn/ensync/Person.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.olexyn.ensync; - -import java.util.Date; - -public class Person { - - private String firstName; - private String surname; - private Date date; - private String occupation; - private double salary; - - - - - Person(String firstName, String surname, Date date, String occupation, double salary){ - this.firstName = firstName; - this.surname = surname; - this.date = date; - this.occupation = occupation; - this.salary = salary; - - } - - public double getSalary(){ - return 0.0; - } - - public Date getDateOfBirth(){ - return null; - } - - public String getFirstName(){ - return "firstName"; - } - - public String getSurname(){ - return "surname"; - } - - public String getOccupation(){ - return "occupation"; - } -} diff --git a/src/com/olexyn/ensync/PersonTableData.java b/src/com/olexyn/ensync/PersonTableData.java index 1cb0ec2..675c0ca 100644 --- a/src/com/olexyn/ensync/PersonTableData.java +++ b/src/com/olexyn/ensync/PersonTableData.java @@ -1,5 +1,6 @@ package com.olexyn.ensync; +import com.olexyn.ensync.artifacts.SyncDirectory; import javafx.beans.property.SimpleDoubleProperty; import javafx.beans.property.SimpleObjectProperty; import javafx.beans.property.SimpleStringProperty; @@ -21,7 +22,7 @@ public class PersonTableData { // added to create the model from the Person object, which might be data retrieved from a database - public PersonTableData(Person person) { + public PersonTableData(SyncDirectory person) { this.firstName = new SimpleStringProperty(person.getFirstName()); diff --git a/src/com/olexyn/ensync/TableAppController.java b/src/com/olexyn/ensync/TableAppController.java index 3847236..42388ba 100644 --- a/src/com/olexyn/ensync/TableAppController.java +++ b/src/com/olexyn/ensync/TableAppController.java @@ -1,5 +1,6 @@ package com.olexyn.ensync; +import com.olexyn.ensync.artifacts.SyncDirectory; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.event.ActionEvent; @@ -32,15 +33,13 @@ public class TableAppController implements Initializable { private TextField salaryTextField; @FXML private Button submitButton; - private ObservableList data = FXCollections - .observableArrayList(); - @FXML + private ObservableList data = FXCollections.observableArrayList(); + @FXML private TableColumn dateOfBirthColumn; @FXML - private TableColumn salaryColumn; @Override @@ -60,22 +59,24 @@ public class TableAppController implements Initializable { } - private List retrieveData() { + private List retrieveData() { try { + SyncDirectory sd1 = new SyncDirectory("Dan", "Newton", DATE_FORMATTER.parse("06/01/1994"), "Java Developer", 22000); + SyncDirectory sd2 = new SyncDirectory("George", "Newton", DATE_FORMATTER.parse("24/01/1995"), "Bro", 15021); + return Arrays.asList(sd1, sd2); - return Arrays.asList(new Person("Dan", "Newton", DATE_FORMATTER.parse("06/01/1994"), "Java Developer", 22000), new Person("George", "Newton", DATE_FORMATTER.parse("24/01/1995"), "Bro", 15021), new Person("Laura", "So", DATE_FORMATTER.parse("24/04/1995"), "Student", 0), new Person("Jamie", "Harwood", DATE_FORMATTER.parse("15/12/9999"), "Java Developer", 30000), new Person("Michael", "Collins", DATE_FORMATTER.parse("01/01/0001"), "Developer", 299), new Person("Stuart", "Kerrigan", DATE_FORMATTER.parse("06/10/1894"), "Teaching Fellow", 100000)); } catch (ParseException e) { e.printStackTrace(); } - return new ArrayList(); + return new ArrayList(); } - private void populate(final List people) { + private void populate(final List people) { people.forEach(p -> data.add(new PersonTableData(p))); @@ -117,23 +118,16 @@ public class TableAppController implements Initializable { salaryColumn.setCellFactory( - EditCell.forTableColumn( - - new MyDoubleStringConverter())); + EditCell.forTableColumn(new MyDoubleStringConverter())); // updates the salary field on the com.olexyn.ensync.PersonTableData object to the // committed value salaryColumn.setOnEditCommit(event -> { + final Double value = event.getNewValue() != null ? event.getNewValue() : event.getOldValue(); - final Double value = event.getNewValue() != null ? - - event.getNewValue() : event.getOldValue(); - - ((PersonTableData) event.getTableView().getItems() - - .get(event.getTablePosition().getRow())).setSalary(value); + ((PersonTableData) event.getTableView().getItems().get(event.getTablePosition().getRow())).setSalary(value); table.refresh(); @@ -188,19 +182,15 @@ public class TableAppController implements Initializable { } @SuppressWarnings("unchecked") - private void editFocusedCell() { - final TablePosition focusedCell = table - - .focusModelProperty().get().focusedCellProperty().get(); + final TablePosition focusedCell = table.focusModelProperty().get().focusedCellProperty().get(); table.edit(focusedCell.getRow(), focusedCell.getTableColumn()); } @SuppressWarnings("unchecked") - private void selectPrevious() { if (table.getSelectionModel().isCellSelectionEnabled()) { @@ -209,27 +199,17 @@ public class TableAppController implements Initializable { // right-to-left, and then wrapping to the end of the previous line - TablePosition pos = table.getFocusModel() - - .getFocusedCell(); + TablePosition pos = table.getFocusModel().getFocusedCell(); if (pos.getColumn() - 1 >= 0) { // go to previous row - - table.getSelectionModel().select(pos.getRow(), - - getTableColumn(pos.getTableColumn(), -1)); + table.getSelectionModel().select(pos.getRow(), getTableColumn(pos.getTableColumn(), -1)); } else if (pos.getRow() < table.getItems().size()) { // wrap to end of previous row - - table.getSelectionModel().select(pos.getRow() - 1, - - table.getVisibleLeafColumn( - - table.getVisibleLeafColumns().size() - 1)); + table.getSelectionModel().select(pos.getRow() - 1, table.getVisibleLeafColumn(table.getVisibleLeafColumns().size() - 1)); } @@ -264,7 +244,6 @@ public class TableAppController implements Initializable { } @FXML - private void submit(final ActionEvent event) { if (allFieldsValid()) { diff --git a/src/com/olexyn/ensync/artifacts/SyncDirectory.java b/src/com/olexyn/ensync/artifacts/SyncDirectory.java index 831a488..62bbf41 100644 --- a/src/com/olexyn/ensync/artifacts/SyncDirectory.java +++ b/src/com/olexyn/ensync/artifacts/SyncDirectory.java @@ -4,15 +4,18 @@ import com.olexyn.ensync.Execute; import com.olexyn.ensync.Tools; import java.io.File; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; public class SyncDirectory { + private String firstName; + private String surname; + private Date date; + private String occupation; + private double salary; - private SyncEntity syncEntity; + + private SyncMap syncMap; public String path = null; public List listCreated = new ArrayList<>(); @@ -26,13 +29,22 @@ public class SyncDirectory { /** * Create a SyncDirectory from realPath. * - * @see SyncEntity + * @see SyncMap */ public SyncDirectory(String path, - SyncEntity syncEntity) { + SyncMap syncMap) { this.path = path; - this.syncEntity = syncEntity; + this.syncMap = syncMap; + + } + + public SyncDirectory(String firstName, String surname, Date date, String occupation, double salary){ + this.firstName = firstName; + this.surname = surname; + this.date = date; + this.occupation = occupation; + this.salary = salary; } @@ -240,7 +252,7 @@ public class SyncDirectory { if (createdFile.isFile()) { - for (Map.Entry otherEntry : syncEntity.syncDirectories.entrySet()) { + for (Map.Entry otherEntry : syncMap.syncDirectories.entrySet()) { SyncDirectory otherSyncDirectory = otherEntry.getValue(); if (!this.equals(otherSyncDirectory)) { @@ -263,7 +275,7 @@ public class SyncDirectory { for (SyncFile deletedFile : listDeleted) { - for (Map.Entry otherEntry : syncEntity.syncDirectories.entrySet()) { + for (Map.Entry otherEntry : syncMap.syncDirectories.entrySet()) { SyncDirectory otherSyncDirectory = otherEntry.getValue(); if (!this.equals(otherSyncDirectory)) { @@ -292,7 +304,7 @@ public class SyncDirectory { if (modifiedFile.isFile()) { - for (Map.Entry otherEntry : syncEntity.syncDirectories.entrySet()) { + for (Map.Entry otherEntry : syncMap.syncDirectories.entrySet()) { SyncDirectory otherSyncDirectory = otherEntry.getValue(); if (!this.equals(otherSyncDirectory)) { @@ -329,4 +341,28 @@ public class SyncDirectory { } } + + public double getSalary(){ + return 0.0; + } + + public Date getDateOfBirth(){ + return null; + } + + public String getFirstName(){ + return "firstName"; + } + + public String getSurname(){ + return "surname"; + } + + public String getOccupation(){ + return "occupation"; + } + + } + + diff --git a/src/com/olexyn/ensync/artifacts/SyncEntity.java b/src/com/olexyn/ensync/artifacts/SyncMap.java similarity index 79% rename from src/com/olexyn/ensync/artifacts/SyncEntity.java rename to src/com/olexyn/ensync/artifacts/SyncMap.java index 4b13bc4..5f2d7f3 100644 --- a/src/com/olexyn/ensync/artifacts/SyncEntity.java +++ b/src/com/olexyn/ensync/artifacts/SyncMap.java @@ -8,10 +8,10 @@ import java.util.HashMap; import java.util.Map; /** - * A SyncEntity is a collection of SyncDirectories, + * A SyncMap is a collection of SyncDirectories, * that are supposed to be kept in sync. */ -public class SyncEntity { +public class SyncMap { public String name; public int syncInterval = 3600; @@ -20,16 +20,16 @@ public class SyncEntity { Tools tools = new Tools(); /** - * @see SyncEntity + * @see SyncMap */ - public SyncEntity(String name) { + public SyncMap(String name) { this.name = name; } /** * Creates a new Syncdirectory. *

- * Adds the created SyncDirectory to this SyncEntity. + * Adds the created SyncDirectory to this SyncMap. * * @param realPath the path from which the Syncdirectory is created. * @see SyncDirectory diff --git a/src/com/olexyn/ensync/layout.fxml b/src/com/olexyn/ensync/layout.fxml index 28b57c3..63633c9 100644 --- a/src/com/olexyn/ensync/layout.fxml +++ b/src/com/olexyn/ensync/layout.fxml @@ -1,124 +1,93 @@ - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -