Skip to content
Snippets Groups Projects

Need valdig title at album

Merged Lars Brodin Østby requested to merge needValdigTitleAtAlbum into dev
1 unresolved thread
Files
3
@@ -24,7 +24,6 @@ import javafx.scene.layout.GridPane;
@@ -24,7 +24,6 @@ import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import javafx.scene.layout.VBox;
import org.hibernate.boot.jaxb.internal.stax.HbmEventReader;
import javax.persistence.EntityManager;
import javax.persistence.EntityManager;
import java.io.IOException;
import java.io.IOException;
@@ -38,159 +37,212 @@ import java.util.stream.Collectors;
@@ -38,159 +37,212 @@ import java.util.stream.Collectors;
/**
/**
* Controls the buttons and changeable elements on create_album.fxml,
* Controls the buttons and changeable elements on create_album.fxml,
* a page where you create albums
* a page where you create albums
 
*
* @version 1.0 22.03.2020
* @version 1.0 22.03.2020
*/
*/
public class CreateAlbum implements Initializable {
public class CreateAlbum implements Initializable {
public TextField tbar_search;
public TextField tbar_search;
public ImageView tbar_logo;
public ImageView tbar_logo;
public Button tbar_explore;
public Button tbar_explore;
public Button tbar_map;
public Button tbar_map;
public Button tbar_upload;
public Button tbar_upload;
public TextField album_title_field;
public TextField album_title_field;
public TextField album_tag_field;
public TextField album_tag_field;
public TextArea album_desc_field;
public TextArea album_desc_field;
public Pane metadata_pane;
public Pane metadata_pane;
public GridPane image_grid;
public GridPane image_grid;
public Button add_images_button;
public Button add_images_button;
public Button create_album_button;
public Button create_album_button;
public Button tbar_albums;
public Button tbar_albums;
public Button tbar_searchBtn;
public Button tbar_searchBtn;
public VBox fileContainer;
public VBox fileContainer;
private AlbumService albumService;
private AlbumService albumService;
private ImageService imageService;
private ImageService imageService;
public CreateAlbum() {
public CreateAlbum() {
EntityManager entityManager = App.ex.getEntityManager();
EntityManager entityManager = App.ex.getEntityManager();
albumService = new AlbumService(entityManager);
albumService = new AlbumService(entityManager);
imageService = new ImageService(entityManager);
imageService = new ImageService(entityManager);
 
}
 
 
@Override
 
public void initialize(URL url, ResourceBundle resourceBundle) {
 
List<Image> allImages = imageService.getImageFromUser(ApplicationState.getCurrentUser());
 
for (Image image : allImages) {
 
javafx.scene.image.Image convertedImage = ImageUtil.convertToFXImage(image);
 
HBox container = new HBox();
 
container.setPrefWidth(450);
 
container.setAlignment(Pos.TOP_CENTER);
 
ImageView imageView = new ImageView();
 
imageView.setFitHeight(200);
 
imageView.setFitWidth(350);
 
imageView.setPickOnBounds(true);
 
imageView.setPreserveRatio(true);
 
imageView.setImage(convertedImage);
 
CheckBox checkBox = new CheckBox();
 
checkBox.setId(image.getId().toString());
 
container.getChildren().addAll(imageView, checkBox);
 
fileContainer.getChildren().add(container);
}
}
}
@Override
public void initialize(URL url, ResourceBundle resourceBundle) {
/**
List<Image> allImages = imageService.getImageFromUser(ApplicationState.getCurrentUser());
* Method that changes stage to Main page
for (Image image : allImages){
*
javafx.scene.image.Image convertedImage = ImageUtil.convertToFXImage(image);
* @param mouseEvent
HBox container = new HBox();
* @throws IOException
container.setPrefWidth(450);
*/
container.setAlignment(Pos.TOP_CENTER);
public void switchToMain(MouseEvent mouseEvent) throws IOException {
ImageView imageView = new ImageView();
App.setRoot("main");
imageView.setFitHeight(200);
}
imageView.setFitWidth(350);
imageView.setPickOnBounds(true);
/**
imageView.setPreserveRatio(true);
* Method that changes stage to Search page. It reads the value of the search
imageView.setImage(convertedImage);
* field and if not empty it is passed to dataexchange
CheckBox checkBox = new CheckBox();
*
checkBox.setId(image.getId().toString());
* @param actionEvent
container.getChildren().addAll(imageView, checkBox);
* @throws IOException
fileContainer.getChildren().add(container);
*/
}
public void switchToSearch(ActionEvent actionEvent) throws IOException {
}
if (!tbar_search.getText().isEmpty()) {
App.ex.setSearchField(tbar_search.getText());
/**
* Method that changes stage to Main page
* @param mouseEvent
* @throws IOException
*/
public void switchToMain(MouseEvent mouseEvent) throws IOException {
App.setRoot("main");
}
/**
* Method that changes stage to Search page. It reads the value of the search
* field and if not empty it is passed to dataexchange
* @param actionEvent
* @throws IOException
*/
public void switchToSearch(ActionEvent actionEvent) throws IOException {
if (!tbar_search.getText().isEmpty()){
App.ex.setSearchField(tbar_search.getText());
}
App.setRoot("search");
}
/**
* Method that changes stage to Explore page
* @param actionEvent
* @throws IOException
*/
public void switchToExplore(ActionEvent actionEvent) throws IOException {
App.setRoot("explore");
}
/**
* Method that changes stage to Albums page
* @param actionEvent
* @throws IOException
*/
public void switchToAlbums(ActionEvent actionEvent) throws IOException {
App.setRoot("explore_albums");
}
}
App.setRoot("search");
/**
}
* Method that changes stage to Map page
* @param actionEvent
/**
* @throws IOException
* Method that changes stage to Explore page
*/
*
public void switchToMap(ActionEvent actionEvent) throws IOException {
* @param actionEvent
App.setRoot("map");
* @throws IOException
 
*/
 
public void switchToExplore(ActionEvent actionEvent) throws IOException {
 
App.setRoot("explore");
 
}
 
 
/**
 
* Method that changes stage to Albums page
 
*
 
* @param actionEvent
 
* @throws IOException
 
*/
 
public void switchToAlbums(ActionEvent actionEvent) throws IOException {
 
App.setRoot("explore_albums");
 
}
 
 
/**
 
* Method that changes stage to Map page
 
*
 
* @param actionEvent
 
* @throws IOException
 
*/
 
public void switchToMap(ActionEvent actionEvent) throws IOException {
 
App.setRoot("map");
 
}
 
 
/**
 
* Method that changes stage to Upload page
 
*
 
* @param actionEvent the mouse has done something
 
* @throws IOException this page does not exist
 
*/
 
public void switchToUpload(ActionEvent actionEvent) throws IOException {
 
App.setRoot("upload");
 
}
 
 
/**
 
* Method that creates album based on the user input and checked images
 
*
 
* @param actionEvent
 
*/
 
public void createAlbum(ActionEvent actionEvent) {
 
String title = album_title_field.getText();
 
String description = album_desc_field.getText();
 
String tags = album_tag_field.getText();
 
<<<<<<< HEAD
 
 
if (tags.isEmpty()){ tags = " "; }
 
 
List<Tag> tagsToAdd = TagService.getTagsFromString(tags);
 
User user = ApplicationState.getCurrentUser();
 
 
//temporary solution for the toString problem with album log creation, along with the if(tag) above
 
if (description.isEmpty()) {
 
description = "No desripton added";
 
}
 
=======
 
List<Tag> tagsToAdd = TagService.getTagsFromString(tags);
 
User user = ApplicationState.getCurrentUser();
 
 
//temporary solution for the toString problem with album log creation
 
if (description.isEmpty()) {
 
description = "No desripton";
 
} if (tags.isEmpty()){
 
tags = " ";
}
}
>>>>>>> needValdigTitleAtAlbum
/**
* Method that changes stage to Upload page
List<Node> imageContainers = new ArrayList<>(fileContainer.getChildren());
* @param actionEvent the mouse has done something
List<String> checkedImagesId = new ArrayList<>();
* @throws IOException this page does not exist
//Each image and checkbox has an hbox container
*/
imageContainers.forEach(hbox ->
public void switchToUpload(ActionEvent actionEvent) throws IOException {
((HBox) hbox).getChildren().stream()
App.setRoot("upload");
//Filter children that is a checked checkbox
 
.filter(child -> child instanceof CheckBox && ((CheckBox) child).isSelected())
 
//Adds all checked image id
 
.forEach(checked -> checkedImagesId.add(checked.getId()))
 
);
 
 
 
if (validateInpid()) {
 
//Find the users images and makes a filter on the checked images
 
List<Image> albumImages = imageService.getImageFromUser(user).stream().filter(image -> checkedImagesId.contains(image.getId().toString())).collect(Collectors.toList());
 
 
if (albumImages.size() > 0) {
 
Optional<Album> createdAlbum = albumService.createAlbum(title, description, user, tagsToAdd, albumImages);
 
createdAlbum.ifPresent(album -> {
 
App.ex.setChosenAlbumId(album.getId());
 
try {
 
<<<<<<< HEAD
 
App.setRoot("view_album");
 
=======
 
App.setRoot("main");
 
>>>>>>> needValdigTitleAtAlbum
 
} catch (IOException e) {
 
e.printStackTrace();
 
}
 
});
 
} else {
 
Optional<Album> createdAlbum = albumService.createEmptyAlbum(title, description, user, tagsToAdd);
 
createdAlbum.ifPresent(album -> {
 
App.ex.setChosenAlbumId(album.getId());
 
try {
 
<<<<<<< HEAD
 
App.setRoot("view_album");
 
=======
 
App.setRoot("main");
 
>>>>>>> needValdigTitleAtAlbum
 
} catch (IOException e) {
 
e.printStackTrace();
 
}
 
});
 
}
}
}
}
/**
* Method that creates album based on the user input and checked images
/**
* @param actionEvent
* Makes sure that user gave the album a title
*/
* @return
public void createAlbum(ActionEvent actionEvent){
*/
String title = album_title_field.getText();
private boolean validateInpid() {
String description = album_desc_field.getText();
boolean check = true;
String tags = album_tag_field.getText();
if (album_title_field.getText().isEmpty()) {
List<Tag> tagsToAdd = TagService.getTagsFromString(tags);
album_title_field.clear();
User user = ApplicationState.getCurrentUser();
album_title_field.setStyle("-fx-prompt-text-fill: red");
album_title_field.setPromptText("* Please enter a title for the album");
List<Node> imageContainers = new ArrayList<>(fileContainer.getChildren());
check = false;
List<String> checkedImagesId = new ArrayList<>();
//Each image and checkbox has an hbox container
imageContainers.forEach(hbox ->
((HBox) hbox).getChildren().stream()
//Filter children that is a checked checkbox
.filter(child -> child instanceof CheckBox && ((CheckBox) child).isSelected())
//Adds all checked image id
.forEach(checked -> checkedImagesId.add(checked.getId()))
);
//Find the users images and makes a filter on the checked images
List<Image> albumImages = imageService.getImageFromUser(user).stream().filter(image -> checkedImagesId.contains(image.getId().toString())).collect(Collectors.toList());
if (albumImages.size() > 0){
Optional<Album> createdAlbum = albumService.createAlbum(title, description, user, tagsToAdd, albumImages);
createdAlbum.ifPresent(album -> {
App.ex.setChosenAlbumId(album.getId());
try {
App.setRoot("view_album");
} catch (IOException e) {
e.printStackTrace();
}
});
}
else {
Optional<Album> createdAlbum = albumService.createEmptyAlbum(title, description, user, tagsToAdd);
createdAlbum.ifPresent(album -> {
App.ex.setChosenAlbumId(album.getId());
try {
App.setRoot("view_album");
} catch (IOException e) {
e.printStackTrace();
}
});
}
}
}
 
return check;
 
}
}
}
Loading