|
@@ -2,15 +2,20 @@ package com.moviesdb;
|
|
|
|
|
|
import javafx.fxml.FXML;
|
|
import javafx.fxml.FXML;
|
|
import javafx.fxml.FXMLLoader;
|
|
import javafx.fxml.FXMLLoader;
|
|
|
|
+import javafx.scene.Node;
|
|
import javafx.scene.control.Button;
|
|
import javafx.scene.control.Button;
|
|
import javafx.scene.control.ScrollPane;
|
|
import javafx.scene.control.ScrollPane;
|
|
import javafx.scene.control.TextArea;
|
|
import javafx.scene.control.TextArea;
|
|
import javafx.scene.control.TextField;
|
|
import javafx.scene.control.TextField;
|
|
import javafx.scene.layout.AnchorPane;
|
|
import javafx.scene.layout.AnchorPane;
|
|
|
|
+import javafx.scene.layout.HBox;
|
|
import javafx.scene.layout.VBox;
|
|
import javafx.scene.layout.VBox;
|
|
import javafx.stage.Modality;
|
|
import javafx.stage.Modality;
|
|
|
|
|
|
|
|
+import javax.enterprise.inject.New;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.List;
|
|
|
|
|
|
//For reading properties from .properties file
|
|
//For reading properties from .properties file
|
|
|
|
|
|
@@ -25,30 +30,30 @@ public class AddMovieController extends Controller {
|
|
VBox actorsGridAncor;
|
|
VBox actorsGridAncor;
|
|
|
|
|
|
@FXML
|
|
@FXML
|
|
- TextField urlTextBox;
|
|
|
|
|
|
+ TextField urlTextBox;
|
|
@FXML
|
|
@FXML
|
|
- TextField titleTextBox;
|
|
|
|
|
|
+ TextField titleTextBox;
|
|
@FXML
|
|
@FXML
|
|
- TextField genreTextBox;
|
|
|
|
|
|
+ TextField genreTextBox;
|
|
@FXML
|
|
@FXML
|
|
TextArea descriptionTextBox;
|
|
TextArea descriptionTextBox;
|
|
@FXML
|
|
@FXML
|
|
- TextField yearTextBox;
|
|
|
|
|
|
+ TextField yearTextBox;
|
|
@FXML
|
|
@FXML
|
|
- TextField timeTextBox;
|
|
|
|
|
|
+ TextField timeTextBox;
|
|
@FXML
|
|
@FXML
|
|
- TextField studioTextBox;
|
|
|
|
|
|
+ TextField studioTextBox;
|
|
@FXML
|
|
@FXML
|
|
- TextField directorTextBox;
|
|
|
|
|
|
+ TextField directorTextBox;
|
|
@FXML
|
|
@FXML
|
|
- TextField rateTextBox;
|
|
|
|
|
|
+ TextField rateTextBox;
|
|
|
|
|
|
Object caller;
|
|
Object caller;
|
|
|
|
|
|
public void open(Object caller) {
|
|
public void open(Object caller) {
|
|
prepare();
|
|
prepare();
|
|
stage.initModality(Modality.WINDOW_MODAL);
|
|
stage.initModality(Modality.WINDOW_MODAL);
|
|
- stage.initOwner(((BrowserController)caller).stage.getScene().getWindow());
|
|
|
|
|
|
+ stage.initOwner(((BrowserController) caller).stage.getScene().getWindow());
|
|
this.caller = caller;
|
|
this.caller = caller;
|
|
stage.setTitle("Log in");
|
|
stage.setTitle("Log in");
|
|
stage.show();
|
|
stage.show();
|
|
@@ -56,22 +61,20 @@ public class AddMovieController extends Controller {
|
|
addActor();
|
|
addActor();
|
|
}
|
|
}
|
|
|
|
|
|
- public void addActor(){
|
|
|
|
|
|
+ public void addActor() {
|
|
try {
|
|
try {
|
|
AnchorPane row = FXMLLoader.load(getClass().getResource("../../ActorRoleSegment.fxml"));
|
|
AnchorPane row = FXMLLoader.load(getClass().getResource("../../ActorRoleSegment.fxml"));
|
|
//row.setPrefWidth(actorsGrid.getWidth());
|
|
//row.setPrefWidth(actorsGrid.getWidth());
|
|
actorsGridAncor.getChildren().add(row);
|
|
actorsGridAncor.getChildren().add(row);
|
|
actorsGrid.setMinHeight(actorsGrid.getMinHeight() + 35);
|
|
actorsGrid.setMinHeight(actorsGrid.getMinHeight() + 35);
|
|
//actorsGrid.getChildren().add(row);
|
|
//actorsGrid.getChildren().add(row);
|
|
- }
|
|
|
|
- catch (IOException ex)
|
|
|
|
- {
|
|
|
|
-
|
|
|
|
|
|
+ } catch (IOException ex) {
|
|
|
|
+ ex.printStackTrace();
|
|
}
|
|
}
|
|
//System.out.println("LoginForm closed");
|
|
//System.out.println("LoginForm closed");
|
|
}
|
|
}
|
|
|
|
|
|
- public void addMovie(){
|
|
|
|
|
|
+ public void executeForm() {
|
|
//read all textboxes
|
|
//read all textboxes
|
|
Movie NewMovie = new Movie();
|
|
Movie NewMovie = new Movie();
|
|
NewMovie.setCover(urlTextBox.getText());
|
|
NewMovie.setCover(urlTextBox.getText());
|
|
@@ -84,28 +87,76 @@ public class AddMovieController extends Controller {
|
|
NewMovie.setRating(rateTextBox.getText());
|
|
NewMovie.setRating(rateTextBox.getText());
|
|
NewMovie.setDescription(descriptionTextBox.getText());
|
|
NewMovie.setDescription(descriptionTextBox.getText());
|
|
|
|
|
|
- try{
|
|
|
|
|
|
+
|
|
|
|
+ //TODO Сheck on id (if addMovie(...) = -1 movie not added)
|
|
|
|
+ NewMovie.setId(((BrowserController)caller).my_connector.addMovie(NewMovie));
|
|
|
|
+ System.out.println("Added Movie with ID: " + NewMovie.id());
|
|
|
|
+
|
|
|
|
+ List<Role> newMovieRoles = fetchRoles(NewMovie);
|
|
|
|
+ if (newMovieRoles.size() > 0) {
|
|
|
|
+ System.out.println("had something to add");
|
|
|
|
+ int counter = 0;
|
|
|
|
+ StringBuilder addedIDs = new StringBuilder();
|
|
|
|
+ for (Role element : newMovieRoles) {
|
|
|
|
+ element.setRoleId(((BrowserController) caller).my_connector.addRole(element));
|
|
|
|
+ if (element.id() != -1) {
|
|
|
|
+ addedIDs.append(" ").append(element.id()).append(",");
|
|
|
|
+ counter++;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ System.out.println("Added " + counter + " Roles with IDs:" + addedIDs);
|
|
|
|
+ } else {
|
|
|
|
+ System.out.println("nothing to add");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ private List<Role> fetchRoles(Movie targetMovie) {
|
|
|
|
+ List<Role> roles = new ArrayList<Role>();
|
|
|
|
+ try {
|
|
//AnchorPane row = (AnchorPane) actorsGrid.getChildren().get(1);
|
|
//AnchorPane row = (AnchorPane) actorsGrid.getChildren().get(1);
|
|
- /*
|
|
|
|
- for (Node row : actorsGrid.getChildren()) {
|
|
|
|
- System.out.println("Id: " + row.getId());
|
|
|
|
|
|
+
|
|
|
|
+ for (Node row : actorsGridAncor.getChildren()) {
|
|
|
|
+ System.out.println("Type: " + row.toString());
|
|
if (row instanceof AnchorPane) {
|
|
if (row instanceof AnchorPane) {
|
|
// clear
|
|
// clear
|
|
- for (Node node : ((AnchorPane)row).getChildren()) {
|
|
|
|
- System.out.println("Id: " + node.getId());
|
|
|
|
- if (node instanceof TextField) {
|
|
|
|
- // clear
|
|
|
|
- ((TextField)node).setText("I have access");
|
|
|
|
- }
|
|
|
|
|
|
+ String name = null;
|
|
|
|
+ String role = null;
|
|
|
|
+ for (Node hbox : ((AnchorPane) row).getChildren()) {
|
|
|
|
+ System.out.println("\t-Type: " + hbox.toString());
|
|
|
|
+
|
|
|
|
+ if (hbox instanceof HBox)
|
|
|
|
+ for (Node halfrow : ((HBox) hbox).getChildren()) {
|
|
|
|
+ System.out.println("\t\t-Type: " + halfrow.toString());
|
|
|
|
+
|
|
|
|
+ if (halfrow instanceof AnchorPane)
|
|
|
|
+ for (Node part : ((AnchorPane) halfrow).getChildren()) {
|
|
|
|
+ System.out.println("\t\t\t-Type: " + part.toString());
|
|
|
|
+
|
|
|
|
+ if (part instanceof TextField) {
|
|
|
|
+ System.out.println("\t\t\t\t Text: " + ((TextField) part).getText());
|
|
|
|
+ if (part.getId().equals("actorName")) {
|
|
|
|
+ name = ((TextField) part).getText();
|
|
|
|
+ }
|
|
|
|
+ if (part.getId().equals("actorRole")) {
|
|
|
|
+ role = ((TextField) part).getText();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (name != "" || role != "") {
|
|
|
|
+ Role rowRole = new Role(targetMovie.id(), name, role);
|
|
|
|
+ roles.add(rowRole);
|
|
|
|
+ System.out.println("Final: movieId=" + rowRole.movieId() + ", actorName=" + rowRole.actor() + ", actorRole=" + rowRole.role() + "\n");
|
|
|
|
+ System.out.println(rowRole.movieId());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- }
|
|
|
|
- */
|
|
|
|
- }
|
|
|
|
- catch (Exception ex)
|
|
|
|
- {
|
|
|
|
|
|
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception ex) {
|
|
|
|
+ ex.printStackTrace();
|
|
}
|
|
}
|
|
- ((BrowserController)caller).my_connector.addMovie(NewMovie);
|
|
|
|
|
|
+ return roles;
|
|
}
|
|
}
|
|
}
|
|
}
|