add showing photos per person and prepare for building
This commit is contained in:
parent
73a921e175
commit
779e456f23
13
pom.xml
13
pom.xml
@ -58,6 +58,19 @@
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifest>
|
||||
<addClasspath>true</addClasspath>
|
||||
<mainClass>dev.mateuszkowalczyk.ffm.Main</mainClass>
|
||||
</manifest>
|
||||
</archive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
|
@ -2,6 +2,7 @@ package dev.mateuszkowalczyk.ffm.app;
|
||||
|
||||
import dev.mateuszkowalczyk.ffm.app.cache.CacheService;
|
||||
import dev.mateuszkowalczyk.ffm.data.DatabaseService;
|
||||
import dev.mateuszkowalczyk.ffm.data.database.person.Person;
|
||||
import dev.mateuszkowalczyk.ffm.view.workspace.MainPageController;
|
||||
import dev.mateuszkowalczyk.ffm.view.workspace.elements.ImageContainerController;
|
||||
import javafx.application.Platform;
|
||||
@ -31,10 +32,12 @@ public class WorkspaceService {
|
||||
this.mainPageController = mainPageController;
|
||||
}
|
||||
|
||||
public void loadImages() {
|
||||
public void loadImages(Person person) {
|
||||
if (imagesContainerController != null) {
|
||||
Platform.runLater(() -> {this.imagesContainerController.clearImages();});
|
||||
var t = new Thread(WorkspaceWrapper.getInstance());
|
||||
var workspaceWrapper = WorkspaceWrapper.getInstance();
|
||||
workspaceWrapper.setPerson(person);
|
||||
var t = new Thread(workspaceWrapper);
|
||||
t.start();
|
||||
} else {
|
||||
System.out.println("Cannot load images if imagesContainerController isn't exists");
|
||||
|
@ -1,6 +1,7 @@
|
||||
package dev.mateuszkowalczyk.ffm.app;
|
||||
|
||||
import dev.mateuszkowalczyk.ffm.app.cache.ThumbnailCacheService;
|
||||
import dev.mateuszkowalczyk.ffm.data.database.person.Person;
|
||||
import dev.mateuszkowalczyk.ffm.data.database.photo.Photo;
|
||||
import dev.mateuszkowalczyk.ffm.data.database.photo.PhotoDAO;
|
||||
import javafx.scene.image.Image;
|
||||
@ -14,6 +15,7 @@ public class WorkspaceWrapper implements Runnable {
|
||||
private ThumbnailCacheService thumbnailCacheService = ThumbnailCacheService.getInstance();
|
||||
private WorkspaceService workspaceService = WorkspaceService.getInstance();
|
||||
private Thread directoryScannerThread;
|
||||
private Person person;
|
||||
|
||||
private WorkspaceWrapper () {}
|
||||
|
||||
@ -32,7 +34,12 @@ public class WorkspaceWrapper implements Runnable {
|
||||
}
|
||||
|
||||
private void setFromDatabase() {
|
||||
List<Photo> photoList = this.photoDAO.getAll();
|
||||
List<Photo> photoList;
|
||||
if (this.person == null) {
|
||||
photoList = this.photoDAO.getAll();
|
||||
} else {
|
||||
photoList = this.photoDAO.getAllForPerson(person);
|
||||
}
|
||||
|
||||
photoList.forEach(photo -> {
|
||||
var element = this.createImageViewElement(photo);
|
||||
@ -48,4 +55,7 @@ public class WorkspaceWrapper implements Runnable {
|
||||
}
|
||||
|
||||
|
||||
public void setPerson(Person person) {
|
||||
this.person = person;
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package dev.mateuszkowalczyk.ffm.data.database.photo;
|
||||
|
||||
import dev.mateuszkowalczyk.ffm.data.DatabaseService;
|
||||
import dev.mateuszkowalczyk.ffm.data.database.Dao;
|
||||
import dev.mateuszkowalczyk.ffm.data.database.person.Person;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
@ -124,4 +125,26 @@ public class PhotoDAO implements Dao<Photo> {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public List<Photo> getAllForPerson(Person person) {
|
||||
List<Photo> photoListForPerson = new ArrayList<>();
|
||||
|
||||
String sql = "SELECT * FROM photos p inner join face f on p.id == f.photoId WHERE f.personId = ?";
|
||||
|
||||
try {
|
||||
PreparedStatement preparedStatement = this.databaseService.getConnection().prepareStatement(sql);
|
||||
preparedStatement.setLong(1, person.getId());
|
||||
ResultSet resultSet = preparedStatement.executeQuery();
|
||||
|
||||
while (resultSet.next()) {
|
||||
var photo = new Photo(resultSet);
|
||||
|
||||
photoListForPerson.add(photo);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return photoListForPerson;
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ public class MainPageController implements Initializable {
|
||||
@FXML
|
||||
private ScrollPane mainContainer;
|
||||
private Person selectedPerson;
|
||||
private Person person;
|
||||
|
||||
public MainPageController() {
|
||||
this.workspaceService = WorkspaceService.getInstance();
|
||||
@ -39,6 +40,9 @@ public class MainPageController implements Initializable {
|
||||
Object controller = null;
|
||||
FXMLLoader fxmlLoader = new FXMLLoader();
|
||||
switch (element) {
|
||||
case ImagesContainerForPerson:
|
||||
controller = new ImageContainerController(this, this.person);
|
||||
break;
|
||||
case ImagesContainer:
|
||||
controller = new ImageContainerController(this);
|
||||
break;
|
||||
@ -69,4 +73,9 @@ public class MainPageController implements Initializable {
|
||||
this.selectedPerson = person;
|
||||
this.setElement(ElementsEnum.PersonFaceContainer);
|
||||
}
|
||||
|
||||
public void showPhotosForPerson(Person person) {
|
||||
this.person = person;
|
||||
this.setElement(ElementsEnum.ImagesContainerForPerson);
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package dev.mateuszkowalczyk.ffm.view.workspace.elements;
|
||||
|
||||
public enum ElementsEnum {
|
||||
ImagesContainer("templates/workspace/elements/image_container.fxml"),
|
||||
ImagesContainerForPerson("templates/workspace/elements/image_container.fxml"),
|
||||
PeopleContainer("templates/workspace/elements/people_container.fxml"),
|
||||
PersonFaceContainer("templates/workspace/elements/face_container.fxml");
|
||||
|
||||
|
@ -47,6 +47,10 @@ public class FaceContainerController implements Initializable {
|
||||
PersonDAO.getInstance().update(person);
|
||||
}
|
||||
|
||||
public void showPhotosForPerson(Event event) {
|
||||
this.mainPageController.showPhotosForPerson(this.person);
|
||||
}
|
||||
|
||||
public void refresh() {
|
||||
this.facesContainer.getChildren().clear();
|
||||
try {
|
||||
|
@ -1,6 +1,7 @@
|
||||
package dev.mateuszkowalczyk.ffm.view.workspace.elements;
|
||||
|
||||
import dev.mateuszkowalczyk.ffm.app.WorkspaceService;
|
||||
import dev.mateuszkowalczyk.ffm.data.database.person.Person;
|
||||
import dev.mateuszkowalczyk.ffm.data.database.photo.PhotoDAO;
|
||||
import dev.mateuszkowalczyk.ffm.view.workspace.MainPageController;
|
||||
import javafx.event.Event;
|
||||
@ -17,13 +18,20 @@ public class ImageContainerController implements Initializable {
|
||||
|
||||
@FXML
|
||||
private FlowPane imagesContainer;
|
||||
private Person person;
|
||||
|
||||
public ImageContainerController(MainPageController mainPageController) { }
|
||||
public ImageContainerController(MainPageController mainPageController) {
|
||||
this.person = null;
|
||||
}
|
||||
|
||||
public ImageContainerController(MainPageController mainPageController, Person person) {
|
||||
this.person = person;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(URL url, ResourceBundle resourceBundle) {
|
||||
workspaceService.setImagesContainerController(this);
|
||||
workspaceService.loadImages();
|
||||
workspaceService.loadImages(this.person);
|
||||
}
|
||||
|
||||
public void clearImages() {
|
||||
@ -34,7 +42,7 @@ public class ImageContainerController implements Initializable {
|
||||
|
||||
public void forceRefresh(Event event) {
|
||||
PhotoDAO.getInstance().getAll(true);
|
||||
this.workspaceService.loadImages();
|
||||
this.workspaceService.loadImages(this.person);
|
||||
}
|
||||
|
||||
public void addImage(ImageView imageView) {
|
||||
|
@ -14,7 +14,8 @@
|
||||
<ToolBar prefHeight="40.0" prefWidth="3485.0" BorderPane.alignment="CENTER">
|
||||
<items>
|
||||
<TextField fx:id="personName" />
|
||||
<Button mnemonicParsing="false" onAction="#updatePersonName" text="Button" />
|
||||
<Button mnemonicParsing="false" onAction="#updatePersonName" text="change" />
|
||||
<Button mnemonicParsing="false" onAction="#showPhotosForPerson" text="Show photos" />
|
||||
</items>
|
||||
</ToolBar>
|
||||
</top>
|
||||
|
Loading…
Reference in New Issue
Block a user