Commit 600601b7 authored by Hermann Owren Elton's avatar Hermann Owren Elton Committed by Olaf Rosendahl
Browse files

Disable buttons that should not be clickable

parent 9ddb3514
......@@ -37,7 +37,7 @@ public final class ApplicationManager {
if(stage == null && scene == null) {
stage = primaryStage;
stage.setOnCloseRequest(s -> {
//Makes is so that the program doesnt automatically close, gives the developer control of the exit mechanic
//Hinders the program closing
s.consume();
//Runs our close program instead
closeProgram();
......
......@@ -37,8 +37,8 @@ final class AlbumDetailsRoot extends SceneRoot {
private final VBox SCROLL_PANE_VBOX = new VBox();
private final ScrollPane SCROLL_PANE = new ScrollPane();
private final Button PDF_BUTTON = new Button("Generate PDF from album");
private final Button DELETE_ALBUM = new Button("Delete album");
private final Button DELETE_PHOTOS = new Button("Remove selected photos");
private final Button DELETE_ALBUM_BUTTON = new Button("Delete album");
private final Button DELETE_PHOTOS_BUTTON = new Button("Remove selected photos");
private Set<Photo> albumPhotoList;
private String albumName;
private final TextField SAVE_LOCATION = new TextField();
......@@ -65,11 +65,11 @@ final class AlbumDetailsRoot extends SceneRoot {
super.setGridPane();
super.getGridPane().add(SCROLL_PANE, 0, 2);
super.getGridPane().add(PDF_BUTTON, 0, 3);
super.getGridPane().add(DELETE_PHOTOS, 0, 4);
super.getGridPane().add(DELETE_ALBUM, 0, 5);
super.getGridPane().add(DELETE_PHOTOS_BUTTON, 0, 4);
super.getGridPane().add(DELETE_ALBUM_BUTTON, 0, 5);
super.getGridPane().setMaxWidth(700.0D);
PDF_BUTTON.setOnAction(s -> generatePdfPressed());
Css.setButton(700, 50, 18, PDF_BUTTON, DELETE_PHOTOS, DELETE_ALBUM);
Css.setButton(700, 50, 18, PDF_BUTTON, DELETE_PHOTOS_BUTTON, DELETE_ALBUM_BUTTON);
this.setupScrollPane();
}
......@@ -107,7 +107,6 @@ final class AlbumDetailsRoot extends SceneRoot {
Css.setButton(480, 20, 17, downloadPdf);
Css.setButton(150, 20, 17, fileExplorer);
fileExplorer.setOnAction(s -> {
try {
this.setSaveLocation(System.getProperty("user.home"), popupWindow.getDialogWindow());
......@@ -152,16 +151,15 @@ final class AlbumDetailsRoot extends SceneRoot {
} else {
showAlbumIsEmpty();
PDF_BUTTON.setDisable(true);
DELETE_PHOTOS_BUTTON.setDisable(true);
}
DELETE_ALBUM.setOnAction(e -> {
DELETE_ALBUM_BUTTON.setOnAction(e -> {
UserInfo.getUser().getAlbums().remove(album);
Hibernate.updateUser(UserInfo.getUser());
ApplicationManager.setRoot(new AlbumsRoot());
});
DELETE_PHOTOS.setOnAction(e -> deleteSelectedPhotos(album));
DELETE_PHOTOS_BUTTON.setOnAction(e -> deleteSelectedPhotos(album));
}
/**
......@@ -201,6 +199,7 @@ final class AlbumDetailsRoot extends SceneRoot {
}
if (albumPhotoList.isEmpty()) {
PDF_BUTTON.setDisable(true);
DELETE_PHOTOS_BUTTON.setDisable(true);
showAlbumIsEmpty();
}
}
......
......@@ -17,8 +17,11 @@ import javafx.scene.control.TextField;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;
import java.util.ArrayList;
import java.util.logging.Level;
import javafx.scene.text.TextAlignment;
/**
* Class for the albums root
......@@ -31,6 +34,7 @@ final class AlbumsRoot extends SceneRoot {
private final Button NEW_ALBUM_BUTTON = new Button("New album");
private final Button DELETE_ALBUM_BUTTON = new Button("Delete album");
private final ChoiceBox<String> CHOICE_BOX = new ChoiceBox();
private final Text feedbackText = new Text();
/**
* Constructor that initializes the albums root
......@@ -64,19 +68,36 @@ final class AlbumsRoot extends SceneRoot {
*/
private void addAlbumsScrollPane() {
try {
UserInfo.getUser().getAlbums().forEach(album -> {
Button albumButton = new Button(album.getName());
albumButton.setOnAction(e -> ApplicationManager.setRoot(new AlbumDetailsRoot(album)));
ALBUM_BUTTONS.add(albumButton);
Css.setButton(650, 50, 18, albumButton);
SCROLL_PANE_VBOX.getChildren().add(albumButton);
});
if (UserInfo.getUser().getAlbums().isEmpty()) {
showNoAlbum();
} else {
UserInfo.getUser().getAlbums().forEach(album -> {
Button albumButton = new Button(album.getName());
albumButton.setOnAction(e -> ApplicationManager.setRoot(new AlbumDetailsRoot(album)));
ALBUM_BUTTONS.add(albumButton);
Css.setButton(650, 50, 18, albumButton);
feedbackText.setDisable(true);
SCROLL_PANE_VBOX.getChildren().add(albumButton);
});
}
} catch (NullPointerException e) {
FileLogger.getLogger().log(Level.FINE, e.getMessage());
FileLogger.closeHandler();
}
}
/**
* Shows a message that tells the user that there no albums are created
*/
private void showNoAlbum() {
Css.setText(17, feedbackText);
SCROLL_PANE_VBOX.getChildren().add(feedbackText);
SCROLL_PANE_VBOX.setAlignment(Pos.CENTER);
feedbackText.setText("No albums registered: Add an album by pressing the add album button");
feedbackText.setTextAlignment(TextAlignment.RIGHT);
DELETE_ALBUM_BUTTON.setDisable(true);
}
/**
* Creates the scroll pane of the scene and adds it to the application
* Used in constructor
......@@ -139,11 +160,15 @@ final class AlbumsRoot extends SceneRoot {
popupWindow.getDialogVBox().getChildren().clear();
popupWindow.getDialogText().setText("Please enter the name of the album to be added:");
popupWindow.getDialogVBox().getChildren().addAll(popupWindow.getDialogText(), popupWindow.getDialogHBox());
DELETE_ALBUM_BUTTON.setDisable(false);
});
} else {
addAlbumButtonPressed(nameAlbumInput.getText().trim());
nameAlbumInput.clear();
popupWindow.getDialogWindow().close();
if (!ALBUM_BUTTONS.isEmpty()) {
DELETE_ALBUM_BUTTON.setDisable(false);
}
}
});
}
......@@ -153,6 +178,7 @@ final class AlbumsRoot extends SceneRoot {
* Used in createNewAlbumButtonPressed
*/
private void addAlbumButtonPressed(String albumName) {
SCROLL_PANE_VBOX.getChildren().remove(feedbackText);
Album album = new Album();
album.setUserId(UserInfo.getUser().getId());
album.setName(albumName);
......@@ -181,19 +207,6 @@ final class AlbumsRoot extends SceneRoot {
Css.setButton(500, 20, 17, deleteButton);
popupWindow.getDialogHBox().getChildren().addAll(CHOICE_BOX, deleteButton);
if (UserInfo.getUser().getAlbums().isEmpty()) {
popupWindow.getDialogText().setText("You don't have any albums");
popupWindow.getDialogVBox().getChildren().remove(popupWindow.getDialogHBox());
Button button = new Button("Ok");
popupWindow.getDialogVBox().getChildren().addAll(button);
Css.setButton(500, 20, 17, button);
button.setOnAction(event -> {
popupWindow.getDialogVBox().getChildren().remove(button);
popupWindow.getDialogVBox().getChildren().add(popupWindow.getDialogHBox());
popupWindow.getDialogWindow().close();
});
}
deleteButton.setOnAction(e -> {
deleteAlbum();
CHOICE_BOX.getItems().remove(CHOICE_BOX.getSelectionModel().getSelectedItem());
......@@ -220,6 +233,9 @@ final class AlbumsRoot extends SceneRoot {
return false;
});
}
if (UserInfo.getUser().getAlbums().isEmpty()) {
showNoAlbum();
}
}
/**
......
......@@ -95,11 +95,7 @@ final class PhotosRoot extends SceneRoot {
CHECKBOX_ARRAY_LIST.add(photoContainer.getCheckBox());
});
} else {
Text noPhotosText = new Text("No photos stored. You can upload photos in \"Upload\"");
Css.setText(17, noPhotosText);
SCROLL_PANE_VBOX.getChildren().add(noPhotosText);
SCROLL_PANE_VBOX.setAlignment(Pos.CENTER);
SELECT_ALL_HBOX.setDisable(true);
showNoPhotos();
}
SCROLL_PANE.setContent(SCROLL_PANE_VBOX);
SCROLL_PANE.setPrefHeight(Screen.getPrimary().getVisualBounds().getHeight());
......@@ -107,6 +103,19 @@ final class PhotosRoot extends SceneRoot {
SCROLL_PANE.hbarPolicyProperty().setValue(ScrollPane.ScrollBarPolicy.NEVER);
}
/**
* Shows a massage that tells the user that it has no photos
*/
private void showNoPhotos(){
Text noPhotosText = new Text("No photos stored. You can upload photos in \"Upload\"");
Css.setText(17, noPhotosText);
SCROLL_PANE_VBOX.getChildren().add(noPhotosText);
SCROLL_PANE_VBOX.setAlignment(Pos.CENTER);
SELECT_ALL_HBOX.setDisable(true);
DELETE_BUTTON.setDisable(true);
ADD_TO_ALBUM_BUTTON.setDisable(true);
}
/**
* Sets up the search bar and its functionality
* Used in setLayout
......@@ -145,6 +154,9 @@ final class PhotosRoot extends SceneRoot {
private void setupAlbumButtons() {
Css.setButton(700, 25, 20, ADD_TO_ALBUM_BUTTON);
ADD_TO_ALBUM_BUTTON.setOnAction(s -> createNewAlbumButtonPressed());
if (UserInfo.getUser().getAlbums().isEmpty()) {
ADD_TO_ALBUM_BUTTON.setDisable(true);
}
}
/**
......@@ -272,6 +284,9 @@ final class PhotosRoot extends SceneRoot {
Css.playFeedBackLabelTransition(FeedbackType.ERROR, "One or more photos could not be deleted", 13, FEEDBACK_LABEL);
}
}
if (UserInfo.getUser().getPhotos().isEmpty()) {
showNoPhotos();
}
}
/**
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment