implemente the import without error handeling
This commit is contained in:
parent
a87c20208e
commit
4fcda75290
@ -1,23 +1,27 @@
|
|||||||
package at.ionas999.questioncatalog.controller;
|
package at.ionas999.questioncatalog.controller;
|
||||||
|
|
||||||
import at.ionas999.questioncatalog.Utils;
|
import at.ionas999.questioncatalog.Utils;
|
||||||
|
import at.ionas999.questioncatalog.model.Question;
|
||||||
import at.ionas999.questioncatalog.model.QuestionCatalog;
|
import at.ionas999.questioncatalog.model.QuestionCatalog;
|
||||||
import at.ionas999.questioncatalog.services.QuestionCatalogService;
|
import at.ionas999.questioncatalog.services.QuestionCatalogService;
|
||||||
import javafx.beans.property.ObjectProperty;
|
import at.ionas999.questioncatalog.services.QuestionService;
|
||||||
import javafx.beans.property.SimpleObjectProperty;
|
|
||||||
import javafx.collections.FXCollections;
|
import javafx.collections.FXCollections;
|
||||||
import javafx.collections.ObservableList;
|
import javafx.collections.ObservableList;
|
||||||
import javafx.event.ActionEvent;
|
import javafx.event.ActionEvent;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.scene.control.Button;
|
import javafx.scene.control.*;
|
||||||
import javafx.scene.control.Label;
|
import javafx.stage.FileChooser;
|
||||||
import javafx.scene.control.ListView;
|
|
||||||
import javafx.scene.control.TextField;
|
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.IOException;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
public class UploadController {
|
public class UploadController {
|
||||||
|
public TextArea csvContentArea;
|
||||||
@FXML
|
@FXML
|
||||||
private Button deleteCatalogButton;
|
private Button deleteCatalogButton;
|
||||||
@FXML
|
@FXML
|
||||||
@ -35,37 +39,49 @@ public class UploadController {
|
|||||||
|
|
||||||
ObservableList<QuestionCatalog> catalogs;
|
ObservableList<QuestionCatalog> catalogs;
|
||||||
|
|
||||||
private ObjectProperty<QuestionCatalog> currentCatalog = new SimpleObjectProperty<>();
|
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private void initialize() throws SQLException {
|
private void initialize() throws SQLException {
|
||||||
currentCatalog.bind(catalogListViw.getSelectionModel().selectedItemProperty());
|
catalogs = FXCollections.observableList(QuestionCatalogService.GetCatalogsWithoutQuestions());
|
||||||
catalogs = FXCollections.observableList(QuestionCatalogService.GetCatalogsWithoutQuestions());
|
catalogListViw.setItems(catalogs);
|
||||||
catalogListViw.setItems(catalogs);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private void onAddNewCatalogBtnClick(ActionEvent actionEvent) throws SQLException {
|
private void onAddNewCatalogBtnClick(ActionEvent actionEvent) throws SQLException {
|
||||||
String name = newCatalogField.getText();
|
String name = newCatalogField.getText();
|
||||||
QuestionCatalog c = new QuestionCatalog(-1, name, null);
|
QuestionCatalog c = new QuestionCatalog(-1, name, null);
|
||||||
System.out.println(c);
|
|
||||||
QuestionCatalogService.AddQuestionCatalogToDb(c);
|
QuestionCatalogService.AddQuestionCatalogToDb(c);
|
||||||
this.catalogs.add(c);
|
this.catalogs.add(c);
|
||||||
catalogListViw.refresh();
|
catalogListViw.refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private void onDeleteCatalogBtnClick(ActionEvent actionEvent) {
|
private void onDeleteCatalogBtnClick(ActionEvent actionEvent) {
|
||||||
QuestionCatalog c = currentCatalog.get();
|
QuestionCatalog c = (QuestionCatalog) catalogListViw.getSelectionModel().getSelectedItem();
|
||||||
boolean result = Utils.showConfirmationButton("Do you want to proceed with deleting a catalog with all questions contained?");
|
if (c == null) {
|
||||||
|
|
||||||
if(!result)
|
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
boolean result = Utils.showConfirmationButton("Do you want to proceed with deleting a catalog with all questions contained?");
|
||||||
|
if (!result) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
QuestionCatalogService.DeleteQuestionCatalog(c.getId());
|
QuestionCatalogService.DeleteQuestionCatalog(c.getId());
|
||||||
catalogs.remove(c);
|
catalogs.remove(c);
|
||||||
catalogListViw.refresh();
|
catalogListViw.refresh();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private void onImportBtnClick(ActionEvent actionEvent) {
|
||||||
|
QuestionCatalog c = (QuestionCatalog) catalogListViw.getSelectionModel().getSelectedItem();
|
||||||
|
String csvContent = csvContentArea.getText();
|
||||||
|
String[] lines = csvContent.split("\n");
|
||||||
|
|
||||||
|
for(String line : lines)
|
||||||
|
{
|
||||||
|
String[] segments = line.split(";");
|
||||||
|
Question q = new Question(-1, segments[0], segments[1], c.getId());
|
||||||
|
QuestionService.AddQuestionToDb(q);
|
||||||
|
}
|
||||||
|
csvContentArea.setText("");
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -23,11 +23,11 @@
|
|||||||
</padding>
|
</padding>
|
||||||
<Label text="Select Catalog:"/>
|
<Label text="Select Catalog:"/>
|
||||||
<ListView fx:id="catalogListViw" VBox.vgrow="ALWAYS"/>
|
<ListView fx:id="catalogListViw" VBox.vgrow="ALWAYS"/>
|
||||||
<HBox spacing="5">
|
<HBox spacing="5">
|
||||||
<TextField fx:id="newCatalogField" promptText="New Catalog Name" HBox.hgrow="ALWAYS"/>
|
<TextField fx:id="newCatalogField" promptText="New Catalog Name" HBox.hgrow="ALWAYS"/>
|
||||||
<Button fx:id="addCatalogButton" text="+" onAction="#onAddNewCatalogBtnClick"/>
|
<Button fx:id="addCatalogButton" text="+" onAction="#onAddNewCatalogBtnClick"/>
|
||||||
<Button fx:id="deleteCatalogButton" text="-" onAction="#onDeleteCatalogBtnClick"/>
|
<Button fx:id="deleteCatalogButton" text="-" onAction="#onDeleteCatalogBtnClick"/>
|
||||||
</HBox>
|
</HBox>
|
||||||
</VBox>
|
</VBox>
|
||||||
</left>
|
</left>
|
||||||
|
|
||||||
@ -36,10 +36,9 @@
|
|||||||
<padding>
|
<padding>
|
||||||
<Insets top="10" right="10" bottom="10" left="10"/>
|
<Insets top="10" right="10" bottom="10" left="10"/>
|
||||||
</padding>
|
</padding>
|
||||||
<Label text="Upload CSV File"/>
|
<Label text="Paste CSV Content Below:"/>
|
||||||
<Button fx:id="uploadButton" text="Choose File"/>
|
<TextArea fx:id="csvContentArea" promptText="Paste your CSV content here..." prefHeight="200.0"/>
|
||||||
<Label fx:id="fileNameLabel" text="No file selected"/>
|
<Button fx:id="importButton" text="Import Questions" onAction="#onImportBtnClick"/>
|
||||||
<Button fx:id="importButton" text="Import Questions" disable="true"/>
|
|
||||||
</VBox>
|
</VBox>
|
||||||
</center>
|
</center>
|
||||||
</BorderPane>
|
</BorderPane>
|
||||||
@ -1,37 +1,36 @@
|
|||||||
<?import javafx.geometry.Insets?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<?import javafx.geometry.*?>
|
||||||
<?import javafx.scene.control.*?>
|
<?import javafx.scene.control.*?>
|
||||||
<?import javafx.scene.layout.*?>
|
<?import javafx.scene.layout.*?>
|
||||||
|
|
||||||
<BorderPane xmlns="http://javafx.com/javafx"
|
<BorderPane prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/17.0.12" xmlns:fx="http://javafx.com/fxml/1" fx:controller="at.ionas999.questioncatalog.controller.ViewController">
|
||||||
xmlns:fx="http://javafx.com/fxml"
|
|
||||||
fx:controller="at.ionas999.questioncatalog.controller.ViewController"
|
|
||||||
prefHeight="400.0" prefWidth="600.0">
|
|
||||||
|
|
||||||
<top>
|
<top>
|
||||||
<HBox alignment="TOP_RIGHT" spacing="10.0">
|
<HBox alignment="TOP_RIGHT" spacing="10.0">
|
||||||
<padding>
|
<padding>
|
||||||
<Insets top="10.0" right="10.0" bottom="0.0" left="10.0"/>
|
<Insets bottom="0.0" left="10.0" right="10.0" top="10.0" />
|
||||||
</padding>
|
</padding>
|
||||||
<ComboBox fx:id="selectBox" promptText="Select an Catalog" />
|
<ComboBox fx:id="selectBox" promptText="Select an Catalog" />
|
||||||
</HBox>
|
</HBox>
|
||||||
</top>
|
</top>
|
||||||
|
|
||||||
<left>
|
<left>
|
||||||
<ListView fx:id="questionListView" prefWidth="200.0" />
|
<ListView fx:id="questionListView" prefHeight="364.0" prefWidth="209.0" />
|
||||||
</left>
|
</left>
|
||||||
|
|
||||||
<center>
|
<center>
|
||||||
<VBox spacing="10.0">
|
<VBox spacing="10.0">
|
||||||
<padding>
|
<padding>
|
||||||
<Insets top="10.0" right="10.0" bottom="10.0" left="10.0"/>
|
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
|
||||||
</padding>
|
</padding>
|
||||||
<TextField fx:id="questionField" editable="false" />
|
<TextField fx:id="questionField" editable="false" />
|
||||||
<TextField fx:id="answerField" promptText="Answer" editable="false" />
|
<TextField fx:id="answerField" editable="false" promptText="Answer" />
|
||||||
<HBox spacing="10.0" alignment="BOTTOM_RIGHT">
|
<HBox alignment="BOTTOM_RIGHT" spacing="10.0">
|
||||||
<Button fx:id="deleteButton" onAction="#deleteQuestion" text="Delete" />
|
<Button fx:id="deleteButton" onAction="#deleteQuestion" text="Delete" />
|
||||||
<Button fx:id="editButton" text="Edit" onAction="#editQuestion" />
|
<Button fx:id="editButton" onAction="#editQuestion" text="Edit" />
|
||||||
</HBox>
|
</HBox>
|
||||||
</VBox>
|
</VBox>
|
||||||
</center>
|
</center>
|
||||||
|
|
||||||
</BorderPane>
|
</BorderPane>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user