Merge Person with SyncDirectory.

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

@ -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<String, SyncDirectory> entry : syncEntity.syncDirectories.entrySet()) {
for (Map.Entry<String, SyncDirectory> 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<String, SyncDirectory> entry : syncEntity.syncDirectories.entrySet()) {
for (Map.Entry<String, SyncDirectory> entry : syncMap.syncDirectories.entrySet()) {
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;
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());

@ -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<PersonTableData> data = FXCollections
.observableArrayList();
@FXML
private ObservableList<PersonTableData> data = FXCollections.observableArrayList();
@FXML
private TableColumn<PersonTableData, Date> dateOfBirthColumn;
@FXML
private TableColumn<PersonTableData, Double> salaryColumn;
@Override
@ -60,22 +59,24 @@ public class TableAppController implements Initializable {
}
private List<Person> retrieveData() {
private List<SyncDirectory> 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<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)));
@ -117,23 +118,16 @@ public class TableAppController implements Initializable {
salaryColumn.setCellFactory(
EditCell.<PersonTableData, Double>forTableColumn(
new MyDoubleStringConverter()));
EditCell.<PersonTableData, Double>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<PersonTableData, ?> focusedCell = table
.focusModelProperty().get().focusedCellProperty().get();
final TablePosition<PersonTableData, ?> 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<PersonTableData, ?> pos = table.getFocusModel()
.getFocusedCell();
TablePosition<PersonTableData, ?> 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()) {

@ -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<SyncFile> 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<String, SyncDirectory> otherEntry : syncEntity.syncDirectories.entrySet()) {
for (Map.Entry<String, SyncDirectory> 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<String, SyncDirectory> otherEntry : syncEntity.syncDirectories.entrySet()) {
for (Map.Entry<String, SyncDirectory> 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<String, SyncDirectory> otherEntry : syncEntity.syncDirectories.entrySet()) {
for (Map.Entry<String, SyncDirectory> 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";
}
}

@ -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.
* <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.
* @see SyncDirectory

@ -1,15 +1,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.cell.*?>
<?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">
<children>
<ScrollPane fitToHeight="true" fitToWidth="true" prefHeight="400.0" prefWidth="600.0">
@ -20,65 +13,41 @@
<content>
<GridPane>
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0"/>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0"/>
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
</rowConstraints>
<children>
<TableView fx:id="table" prefHeight="200.0" prefWidth="200.0" GridPane.columnSpan="2147483647">
<columns>
<TableColumn prefWidth="98.0" text="First Name">
<cellValueFactory>
<PropertyValueFactory property="firstName" />
<PropertyValueFactory property="firstName"/>
</cellValueFactory>
</TableColumn>
<TableColumn prefWidth="111.0" text="Surname">
<cellValueFactory>
<PropertyValueFactory property="surname" />
<PropertyValueFactory property="surname"/>
</cellValueFactory>
</TableColumn>
<TableColumn fx:id="dateOfBirthColumn" prefWidth="99.0" text="Date of Birth">
<cellValueFactory>
<PropertyValueFactory property="dateOfBirth" />
<PropertyValueFactory property="dateOfBirth"/>
</cellValueFactory>
</TableColumn>
<TableColumn prefWidth="106.0" text="Occupation">
<cellValueFactory>
<PropertyValueFactory property="occupation" />
<PropertyValueFactory property="occupation"/>
</cellValueFactory>
</TableColumn>
<TableColumn fx:id="salaryColumn" prefWidth="84.0" text="Salary">
<cellValueFactory>
<PropertyValueFactory property="salary" />
<PropertyValueFactory property="salary"/>
</cellValueFactory>
</TableColumn>
</columns>
</TableView>
@ -86,30 +55,30 @@
<children>
<GridPane layoutX="14.0" prefHeight="146.0" prefWidth="333.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="14.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="295.0" minWidth="10.0" prefWidth="85.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="507.0" minWidth="10.0" prefWidth="248.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="295.0" minWidth="10.0" prefWidth="85.0"/>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="507.0" minWidth="10.0" prefWidth="248.0"/>
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
</rowConstraints>
<children>
<Label text="First Name" />
<Label text="Surname" GridPane.rowIndex="1" />
<Label text="Date of Birth" GridPane.rowIndex="2" />
<Label text="Occupation" GridPane.rowIndex="3" />
<Label text="Salary" GridPane.rowIndex="4" />
<TextField fx:id="firstNameTextField" GridPane.columnIndex="1" />
<TextField fx:id="surnameTextField" GridPane.columnIndex="1" GridPane.rowIndex="1" />
<TextField fx:id="dateOfBirthTextField" GridPane.columnIndex="1" GridPane.rowIndex="2" />
<TextField fx:id="occupationTextField" GridPane.columnIndex="1" GridPane.rowIndex="3" />
<TextField fx:id="salaryTextField" GridPane.columnIndex="1" GridPane.rowIndex="4" />
<Label text="First Name"/>
<Label text="Surname" GridPane.rowIndex="1"/>
<Label text="Date of Birth" GridPane.rowIndex="2"/>
<Label text="Occupation" GridPane.rowIndex="3"/>
<Label text="Salary" GridPane.rowIndex="4"/>
<TextField fx:id="firstNameTextField" GridPane.columnIndex="1"/>
<TextField fx:id="surnameTextField" GridPane.columnIndex="1" GridPane.rowIndex="1"/>
<TextField fx:id="dateOfBirthTextField" GridPane.columnIndex="1" GridPane.rowIndex="2"/>
<TextField fx:id="occupationTextField" GridPane.columnIndex="1" GridPane.rowIndex="3"/>
<TextField fx:id="salaryTextField" GridPane.columnIndex="1" GridPane.rowIndex="4"/>
</children>
</GridPane>
<Button fx:id="submitButton" layoutX="371.0" layoutY="2.0" mnemonicParsing="false" onAction="#submit" text="Submit" AnchorPane.bottomAnchor="115.0" AnchorPane.leftAnchor="371.0" />
<Button fx:id="submitButton" layoutX="371.0" layoutY="2.0" mnemonicParsing="false" onAction="#submit" text="Submit" AnchorPane.bottomAnchor="115.0" AnchorPane.leftAnchor="371.0"/>
</children>
</AnchorPane>
</children>

Loading…
Cancel
Save