Merge Person with SyncDirectory.

pull/1/head
Ivan Olexyn 5 years ago
parent b71b0cce49
commit a497b0fcbb

@ -1,11 +1,9 @@
package com.olexyn.ensync; package com.olexyn.ensync;
import com.olexyn.ensync.artifacts.SyncDirectory; import com.olexyn.ensync.artifacts.SyncDirectory;
import com.olexyn.ensync.artifacts.SyncEntity; import com.olexyn.ensync.artifacts.SyncMap;
import com.olexyn.ensync.artifacts.SyncFile;
import java.io.File; import java.io.File;
import java.util.List;
import java.util.Map; import java.util.Map;
public class Flow { public class Flow {
@ -26,13 +24,13 @@ public class Flow {
Execute x = new Execute(); Execute x = new Execute();
SyncEntity syncEntity = new SyncEntity("test"); SyncMap syncMap = new SyncMap("test");
syncEntity.addDirectory("/home/user/test/a"); syncMap.addDirectory("/home/user/test/a");
syncEntity.addDirectory("/home/user/test/b"); syncMap.addDirectory("/home/user/test/b");
//syncEntity.addDirectory("/home/user/test/c"); //syncMap.addDirectory("/home/user/test/c");
for (Map.Entry<String, SyncDirectory> entry : syncEntity.syncDirectories.entrySet()) { for (Map.Entry<String, SyncDirectory> entry : syncMap.syncDirectories.entrySet()) {
SyncDirectory syncDirectory = entry.getValue(); SyncDirectory syncDirectory = entry.getValue();
String path = syncDirectory.path; String path = syncDirectory.path;
String stateFilePath = syncDirectory.stateFilePath(path); String stateFilePath = syncDirectory.stateFilePath(path);
@ -47,7 +45,7 @@ public class Flow {
while (true) { while (true) {
for (Map.Entry<String, SyncDirectory> entry : syncEntity.syncDirectories.entrySet()) { for (Map.Entry<String, SyncDirectory> entry : syncMap.syncDirectories.entrySet()) {
SyncDirectory syncDirectory = entry.getValue(); SyncDirectory syncDirectory = entry.getValue();

@ -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";
}
}

@ -1,5 +1,6 @@
package com.olexyn.ensync; package com.olexyn.ensync;
import com.olexyn.ensync.artifacts.SyncDirectory;
import javafx.beans.property.SimpleDoubleProperty; import javafx.beans.property.SimpleDoubleProperty;
import javafx.beans.property.SimpleObjectProperty; import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty; 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 // 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()); this.firstName = new SimpleStringProperty(person.getFirstName());

@ -1,5 +1,6 @@
package com.olexyn.ensync; package com.olexyn.ensync;
import com.olexyn.ensync.artifacts.SyncDirectory;
import javafx.collections.FXCollections; import javafx.collections.FXCollections;
import javafx.collections.ObservableList; import javafx.collections.ObservableList;
import javafx.event.ActionEvent; import javafx.event.ActionEvent;
@ -32,15 +33,13 @@ public class TableAppController implements Initializable {
private TextField salaryTextField; private TextField salaryTextField;
@FXML @FXML
private Button submitButton; private Button submitButton;
private ObservableList<PersonTableData> data = FXCollections
.observableArrayList(); private ObservableList<PersonTableData> data = FXCollections.observableArrayList();
@FXML
@FXML
private TableColumn<PersonTableData, Date> dateOfBirthColumn; private TableColumn<PersonTableData, Date> dateOfBirthColumn;
@FXML @FXML
private TableColumn<PersonTableData, Double> salaryColumn; private TableColumn<PersonTableData, Double> salaryColumn;
@Override @Override
@ -60,22 +59,24 @@ public class TableAppController implements Initializable {
} }
private List<Person> retrieveData() { private List<SyncDirectory> retrieveData() {
try { 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) { } catch (ParseException e) {
e.printStackTrace(); e.printStackTrace();
} }
return new ArrayList<Person>(); return new ArrayList<SyncDirectory>();
} }
private void populate(final List<Person> people) { private void populate(final List<SyncDirectory> people) {
people.forEach(p -> data.add(new PersonTableData(p))); people.forEach(p -> data.add(new PersonTableData(p)));
@ -117,23 +118,16 @@ public class TableAppController implements Initializable {
salaryColumn.setCellFactory( salaryColumn.setCellFactory(
EditCell.<PersonTableData, Double>forTableColumn( EditCell.<PersonTableData, Double>forTableColumn(new MyDoubleStringConverter()));
new MyDoubleStringConverter()));
// updates the salary field on the com.olexyn.ensync.PersonTableData object to the // updates the salary field on the com.olexyn.ensync.PersonTableData object to the
// committed value // committed value
salaryColumn.setOnEditCommit(event -> { salaryColumn.setOnEditCommit(event -> {
final Double value = event.getNewValue() != null ? event.getNewValue() : event.getOldValue();
final Double value = event.getNewValue() != null ? ((PersonTableData) event.getTableView().getItems().get(event.getTablePosition().getRow())).setSalary(value);
event.getNewValue() : event.getOldValue();
((PersonTableData) event.getTableView().getItems()
.get(event.getTablePosition().getRow())).setSalary(value);
table.refresh(); table.refresh();
@ -188,19 +182,15 @@ public class TableAppController implements Initializable {
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private void editFocusedCell() { private void editFocusedCell() {
final TablePosition<PersonTableData, ?> focusedCell = table final TablePosition<PersonTableData, ?> focusedCell = table.focusModelProperty().get().focusedCellProperty().get();
.focusModelProperty().get().focusedCellProperty().get();
table.edit(focusedCell.getRow(), focusedCell.getTableColumn()); table.edit(focusedCell.getRow(), focusedCell.getTableColumn());
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private void selectPrevious() { private void selectPrevious() {
if (table.getSelectionModel().isCellSelectionEnabled()) { 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 // right-to-left, and then wrapping to the end of the previous line
TablePosition<PersonTableData, ?> pos = table.getFocusModel() TablePosition<PersonTableData, ?> pos = table.getFocusModel().getFocusedCell();
.getFocusedCell();
if (pos.getColumn() - 1 >= 0) { if (pos.getColumn() - 1 >= 0) {
// go to previous row // 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()) { } else if (pos.getRow() < table.getItems().size()) {
// wrap to end of previous row // 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 @FXML
private void submit(final ActionEvent event) { private void submit(final ActionEvent event) {
if (allFieldsValid()) { if (allFieldsValid()) {

@ -4,15 +4,18 @@ import com.olexyn.ensync.Execute;
import com.olexyn.ensync.Tools; import com.olexyn.ensync.Tools;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class SyncDirectory { 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 String path = null;
public List<SyncFile> listCreated = new ArrayList<>(); public List<SyncFile> listCreated = new ArrayList<>();
@ -26,13 +29,22 @@ public class SyncDirectory {
/** /**
* Create a SyncDirectory from realPath. * Create a SyncDirectory from realPath.
* *
* @see SyncEntity * @see SyncMap
*/ */
public SyncDirectory(String path, public SyncDirectory(String path,
SyncEntity syncEntity) { SyncMap syncMap) {
this.path = path; 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()) { if (createdFile.isFile()) {
for (Map.Entry<String, SyncDirectory> otherEntry : syncEntity.syncDirectories.entrySet()) { for (Map.Entry<String, SyncDirectory> otherEntry : syncMap.syncDirectories.entrySet()) {
SyncDirectory otherSyncDirectory = otherEntry.getValue(); SyncDirectory otherSyncDirectory = otherEntry.getValue();
if (!this.equals(otherSyncDirectory)) { if (!this.equals(otherSyncDirectory)) {
@ -263,7 +275,7 @@ public class SyncDirectory {
for (SyncFile deletedFile : listDeleted) { for (SyncFile deletedFile : listDeleted) {
for (Map.Entry<String, SyncDirectory> otherEntry : syncEntity.syncDirectories.entrySet()) { for (Map.Entry<String, SyncDirectory> otherEntry : syncMap.syncDirectories.entrySet()) {
SyncDirectory otherSyncDirectory = otherEntry.getValue(); SyncDirectory otherSyncDirectory = otherEntry.getValue();
if (!this.equals(otherSyncDirectory)) { if (!this.equals(otherSyncDirectory)) {
@ -292,7 +304,7 @@ public class SyncDirectory {
if (modifiedFile.isFile()) { if (modifiedFile.isFile()) {
for (Map.Entry<String, SyncDirectory> otherEntry : syncEntity.syncDirectories.entrySet()) { for (Map.Entry<String, SyncDirectory> otherEntry : syncMap.syncDirectories.entrySet()) {
SyncDirectory otherSyncDirectory = otherEntry.getValue(); SyncDirectory otherSyncDirectory = otherEntry.getValue();
if (!this.equals(otherSyncDirectory)) { 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";
}
}

@ -8,10 +8,10 @@ import java.util.HashMap;
import java.util.Map; 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. * that are supposed to be kept in sync.
*/ */
public class SyncEntity { public class SyncMap {
public String name; public String name;
public int syncInterval = 3600; public int syncInterval = 3600;
@ -20,16 +20,16 @@ public class SyncEntity {
Tools tools = new Tools(); Tools tools = new Tools();
/** /**
* @see SyncEntity * @see SyncMap
*/ */
public SyncEntity(String name) { public SyncMap(String name) {
this.name = name; this.name = name;
} }
/** /**
* Creates a new Syncdirectory. * Creates a new Syncdirectory.
* <p> * <p>
* Adds the created SyncDirectory to this SyncEntity. * Adds the created SyncDirectory to this SyncMap.
* *
* @param realPath the path from which the Syncdirectory is created. * @param realPath the path from which the Syncdirectory is created.
* @see SyncDirectory * @see SyncDirectory

@ -1,15 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.cell.*?>
<?import java.lang.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?> <?import javafx.scene.control.*?>
<?import javafx.scene.control.cell.*?>
<?import javafx.scene.layout.*?> <?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<?import javafx.scene.control.cell.PropertyValueFactory?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.olexyn.ensync.TableAppController"> <AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.olexyn.ensync.TableAppController">
<children> <children>
<ScrollPane fitToHeight="true" fitToWidth="true" prefHeight="400.0" prefWidth="600.0"> <ScrollPane fitToHeight="true" fitToWidth="true" prefHeight="400.0" prefWidth="600.0">
@ -32,53 +25,29 @@
<TableView fx:id="table" prefHeight="200.0" prefWidth="200.0" GridPane.columnSpan="2147483647"> <TableView fx:id="table" prefHeight="200.0" prefWidth="200.0" GridPane.columnSpan="2147483647">
<columns> <columns>
<TableColumn prefWidth="98.0" text="First Name"> <TableColumn prefWidth="98.0" text="First Name">
<cellValueFactory> <cellValueFactory>
<PropertyValueFactory property="firstName"/> <PropertyValueFactory property="firstName"/>
</cellValueFactory> </cellValueFactory>
</TableColumn> </TableColumn>
<TableColumn prefWidth="111.0" text="Surname"> <TableColumn prefWidth="111.0" text="Surname">
<cellValueFactory> <cellValueFactory>
<PropertyValueFactory property="surname"/> <PropertyValueFactory property="surname"/>
</cellValueFactory> </cellValueFactory>
</TableColumn> </TableColumn>
<TableColumn fx:id="dateOfBirthColumn" prefWidth="99.0" text="Date of Birth"> <TableColumn fx:id="dateOfBirthColumn" prefWidth="99.0" text="Date of Birth">
<cellValueFactory> <cellValueFactory>
<PropertyValueFactory property="dateOfBirth"/> <PropertyValueFactory property="dateOfBirth"/>
</cellValueFactory> </cellValueFactory>
</TableColumn> </TableColumn>
<TableColumn prefWidth="106.0" text="Occupation"> <TableColumn prefWidth="106.0" text="Occupation">
<cellValueFactory> <cellValueFactory>
<PropertyValueFactory property="occupation"/> <PropertyValueFactory property="occupation"/>
</cellValueFactory> </cellValueFactory>
</TableColumn> </TableColumn>
<TableColumn fx:id="salaryColumn" prefWidth="84.0" text="Salary"> <TableColumn fx:id="salaryColumn" prefWidth="84.0" text="Salary">
<cellValueFactory> <cellValueFactory>
<PropertyValueFactory property="salary"/> <PropertyValueFactory property="salary"/>
</cellValueFactory> </cellValueFactory>
</TableColumn> </TableColumn>
</columns> </columns>
</TableView> </TableView>

Loading…
Cancel
Save