package at.fos.ermodel.gui; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.geometry.Insets; import javafx.scene.Cursor; import javafx.scene.Scene; import javafx.scene.control.*; import javafx.scene.input.KeyCode; import javafx.scene.input.MouseButton; import javafx.scene.layout.*; import javafx.stage.FileChooser; import javafx.stage.Modality; import javafx.stage.Stage; import java.io.*; import java.nio.charset.StandardCharsets; import java.util.Objects; import java.util.Optional; public class A8 extends Stage { private final A8 thisActionMessageDialog; private final TextField nameTF; private final CheckBox createColumnCB; private final TextField columnNameTF; private final TextField columnPostfixTF; private final TextField datatypeTF; private final CheckBox isAutoincrementCB; private final TextField autoincrementStartAtTF; private final CheckBox isKeyCB; private final CheckBox isNullableCB; private final CheckBox isUniqueCB; private final ComboBox dataGenerationTypeCoB; private final Label par1LBL; private final TextField par1TF; private final Label par2LBL; private final TextField par2TF; private final Button okBTN; private final String holdName; private final boolean holdcreateColumn; private final String holdcolumnName; private final String holdcolumnPostfix; private final String holddatatype; private final boolean holdisAutoincrement; private final long holdAutoincrementStartAt; private final boolean holdisKey; private final boolean holdisNullable; private final boolean holdisUnique; private final String holddatagenerationtype; private final String holdpar1_label; private final String holdpar1; private final String holdpar2_label; private final String holdpar2; private Button cancelBTN; public A8(final A3 canvas, double xPos, double yPos, String name, boolean createColumn, String columnName, String columnPostfix, String datatype, boolean isWeakKey, boolean isAutoincrement, long autoincrementStartAt, boolean isKey, boolean isNullable, boolean isUnique, String dataGenerationType, String par1, String par1_label, String par2, String par2_label) { String title = "Attribute Transformation"; this.holdName = name; this.holdcreateColumn = createColumn; this.holdcolumnName = columnName; this.holdcolumnPostfix = columnPostfix; this.holddatatype = datatype; this.holdisAutoincrement = isAutoincrement; this.holdAutoincrementStartAt = autoincrementStartAt; this.holdisKey = isKey; this.holdisNullable = isNullable; this.holdisUnique = isUnique; this.holddatagenerationtype = dataGenerationType; this.holdpar1_label = par1_label; this.holdpar1 = par1; this.holdpar2_label = par2_label; this.holdpar2 = par2; this.thisActionMessageDialog = this; setTitle(title); initModality(Modality.APPLICATION_MODAL); this.nameTF = new TextField(name); this.nameTF.setPrefWidth(150.0D); this.nameTF.setMaxWidth(150.0D); this.nameTF.setDisable(true); this.createColumnCB = new CheckBox(); this.createColumnCB.setSelected(false); if (createColumn) this.createColumnCB.setSelected(true); this.createColumnCB.setOnMouseEntered(event -> T3.fdssdf4354(A8.this.createColumnCB, C2.MouseSelectedColor)); this.createColumnCB.setOnMouseExited(event -> A8.this.createColumnCB.setEffect(null)); this.columnPostfixTF = new TextField(columnPostfix); this.columnPostfixTF.setPrefWidth(150.0D); this.columnPostfixTF.setMaxWidth(150.0D); this.columnPostfixTF.setOnMouseEntered(event -> T3.fdssdf4354(A8.this.columnPostfixTF, C2.MouseSelectedColor)); this.columnPostfixTF.setOnMouseExited(event -> A8.this.columnPostfixTF.setEffect(null)); this.columnNameTF = new TextField(columnName); this.columnNameTF.setPrefWidth(150.0D); this.columnNameTF.setMaxWidth(150.0D); this.columnNameTF.setOnMouseEntered(event -> T3.fdssdf4354(A8.this.columnNameTF, C2.MouseSelectedColor)); this.columnNameTF.setOnMouseExited(event -> A8.this.columnNameTF.setEffect(null)); this.datatypeTF = new TextField(datatype); this.datatypeTF.setPrefWidth(150.0D); this.datatypeTF.setMaxWidth(150.0D); this.datatypeTF.setOnMouseEntered(event -> T3.fdssdf4354(A8.this.datatypeTF, C2.MouseSelectedColor)); this.datatypeTF.setOnMouseExited(event -> A8.this.datatypeTF.setEffect(null)); this.isAutoincrementCB = new CheckBox(); this.isAutoincrementCB.setSelected(false); if (isAutoincrement) this.isAutoincrementCB.setSelected(true); this.isAutoincrementCB.setDisable(true); if (isKey && !isWeakKey) this.isAutoincrementCB.setDisable(false); this.isAutoincrementCB.setOnMouseEntered(event -> T3.fdssdf4354(A8.this.isAutoincrementCB, C2.MouseSelectedColor)); this.isAutoincrementCB.setOnMouseExited(event -> A8.this.isAutoincrementCB.setEffect(null)); this.isAutoincrementCB.setOnAction(event -> { if (A8.this.isAutoincrementCB.isSelected()) { A8.this.datatypeTF.setText("bigint"); A8.this.autoincrementStartAtTF.setDisable(false); A8.this.autoincrementStartAtTF.setText("1"); A8.this.datatypeTF.setDisable(true); A8.this.dataGenerationTypeCoB.setDisable(true); A8.this.par1TF.setDisable(true); A8.this.par2TF.setDisable(true); } else { A8.this.datatypeTF.setDisable(false); A8.this.autoincrementStartAtTF.setDisable(true); A8.this.dataGenerationTypeCoB.setDisable(false); A8.this.par1TF.setDisable(false); A8.this.par2TF.setDisable(false); } }); if (!isAutoincrement) autoincrementStartAt = 1L; this.autoincrementStartAtTF = new TextField(String.valueOf(autoincrementStartAt)); this.autoincrementStartAtTF.setPrefWidth(100.0D); this.autoincrementStartAtTF.setMaxWidth(100.0D); this.autoincrementStartAtTF.setDisable(true); if (isAutoincrement) this.autoincrementStartAtTF.setDisable(false); this.autoincrementStartAtTF.setOnMouseEntered(event -> T3.fdssdf4354(A8.this.autoincrementStartAtTF, C2.MouseSelectedColor)); this.autoincrementStartAtTF.setOnMouseExited(event -> A8.this.autoincrementStartAtTF.setEffect(null)); this.isKeyCB = new CheckBox(); this.isKeyCB.setSelected(false); if (isKey) this.isKeyCB.setSelected(true); this.isKeyCB.setOnMouseEntered(event -> T3.fdssdf4354(A8.this.isKeyCB, C2.MouseSelectedColor)); this.isKeyCB.setOnMouseExited(event -> A8.this.isKeyCB.setEffect(null)); this.isNullableCB = new CheckBox(); this.isNullableCB.setSelected(false); if (isNullable) this.isNullableCB.setSelected(true); this.isNullableCB.setOnMouseEntered(event -> T3.fdssdf4354(A8.this.isNullableCB, C2.MouseSelectedColor)); this.isNullableCB.setOnMouseExited(event -> A8.this.isNullableCB.setEffect(null)); this.isUniqueCB = new CheckBox(); this.isUniqueCB.setSelected(false); if (isUnique) this.isUniqueCB.setSelected(true); this.isUniqueCB.setOnMouseEntered(event -> T3.fdssdf4354(A8.this.isUniqueCB, C2.MouseSelectedColor)); this.isUniqueCB.setOnMouseExited(event -> A8.this.isUniqueCB.setEffect(null)); ObservableList possibleGenerations = FXCollections.observableArrayList(T3.dsfsdfsdf4353534); this.dataGenerationTypeCoB = new ComboBox<>(possibleGenerations); if (dataGenerationType == null) { this.dataGenerationTypeCoB.getSelectionModel().select(0); this.par1TF = new TextField(""); this.par1TF.setDisable(true); this.par1LBL = new Label(""); this.par2TF = new TextField(""); this.par2TF.setDisable(true); this.par2LBL = new Label(""); } else { this.dataGenerationTypeCoB.getSelectionModel().select(dataGenerationType); this.par1TF = new TextField(par1); this.par1TF.setDisable(true); this.par1LBL = new Label(par1_label); this.par2TF = new TextField(par2); this.par2TF.setDisable(true); this.par2LBL = new Label(par2_label); setVisibilityForGenerationtype(); } this.par2TF.setOnMousePressed(event -> { if (!A8.this.dataGenerationTypeCoB.getSelectionModel().getSelectedItem().equals("Extern")) return; if (event.getButton() == MouseButton.SECONDARY) { event.consume(); FileChooser fc = new FileChooser(); fc.setInitialDirectory(new File(System.getProperty("user.home"))); fc.getExtensionFilters().add(new FileChooser.ExtensionFilter("*.txt", "*.TXT")); File file = fc.showOpenDialog(A8.this.thisActionMessageDialog); if (file != null) { A8.this.par2TF.setText(file.getAbsolutePath()); } } A8.this.getScene().getRoot().setCursor(Cursor.HAND); T3.fdssdf4354(A8.this.okBTN, C2.MouseSelectedColor); }); this.dataGenerationTypeCoB.setOnAction(event -> A8.this.setSelectionForGenerationtype()); this.okBTN = new Button("Ok"); this.okBTN.setBackground(new Background(new BackgroundFill(C2.ButtonBackgroundColor, new CornerRadii(5.0D), Insets.EMPTY))); this.okBTN.setOnMouseEntered(event -> { A8.this.getScene().getRoot().setCursor(Cursor.HAND); T3.fdssdf4354(A8.this.okBTN, C2.MouseSelectedColor); }); this.okBTN.setOnMouseExited(event -> { A8.this.getScene().getRoot().setCursor(Cursor.DEFAULT); A8.this.okBTN.setEffect(null); if (A8.this.okBTN.isFocused()) T3.fdssdf4354(A8.this.okBTN, C2.FocusOnComponentColor); }); this.okBTN.focusedProperty().addListener((obs, oldVal, newVal) -> { if (this.okBTN.isFocused()) { T3.fdssdf4354(this.okBTN, C2.FocusOnComponentColor); this.columnPostfixTF.setEffect(null); this.cancelBTN.setEffect(null); } else { this.okBTN.setEffect(null); } }); this.okBTN.setOnAction(event -> { A8.this.setDataAndLeave(); if (!canvas.getTabWithCanvas().getText().contains("*")) canvas.getTabWithCanvas().setText(canvas.getTabWithCanvas().getText() + "*"); }); this.okBTN.setOnKeyPressed(event -> { if (Objects.requireNonNull(event.getCode()) == KeyCode.ENTER) { A8.this.setDataAndLeave(); if (!canvas.getTabWithCanvas().getText().contains("*")) canvas.getTabWithCanvas().setText(canvas.getTabWithCanvas().getText() + "*"); } }); this.cancelBTN = new Button("Cancel"); this.cancelBTN.setBackground(new Background(new BackgroundFill(C2.ButtonBackgroundColor, new CornerRadii(5.0D), Insets.EMPTY))); this.cancelBTN.setOnMouseEntered(event -> { A8.this.getScene().getRoot().setCursor(Cursor.HAND); T3.fdssdf4354(A8.this.cancelBTN, C2.MouseSelectedColor); }); this.cancelBTN.setOnMouseExited(event -> { A8.this.getScene().getRoot().setCursor(Cursor.DEFAULT); A8.this.cancelBTN.setEffect(null); if (A8.this.cancelBTN.isFocused()) T3.fdssdf4354(A8.this.cancelBTN, C2.FocusOnComponentColor); }); this.cancelBTN.focusedProperty().addListener((obs, oldVal, newVal) -> { if (this.cancelBTN.isFocused()) { T3.fdssdf4354(this.cancelBTN, C2.FocusOnComponentColor); this.columnPostfixTF.setEffect(null); this.okBTN.setEffect(null); } else { this.cancelBTN.setEffect(null); } }); this.cancelBTN.setOnAction(event -> A8.this.setNothingAndLeave()); this.cancelBTN.setOnKeyPressed(event -> { if (Objects.requireNonNull(event.getCode()) == KeyCode.ENTER) { A8.this.setNothingAndLeave(); } }); if (isKey) { this.isKeyCB.setDisable(true); this.isUniqueCB.setDisable(true); this.createColumnCB.setDisable(true); this.isNullableCB.setDisable(true); } else { this.isKeyCB.setDisable(true); } GridPane gridPane = new GridPane(); gridPane.setPadding(new Insets(10.0D, 10.0D, 10.0D, 10.0D)); gridPane.setVgap(4.0D); gridPane.setHgap(4.0D); Label lbl = new Label("Name:"); lbl.setPrefWidth(100.0D); lbl.setMinWidth(100.0D); gridPane.add(lbl, 0, 0); gridPane.add(this.nameTF, 1, 0); lbl = new Label("Create column:"); lbl.setPrefWidth(100.0D); lbl.setMinWidth(100.0D); gridPane.add(lbl, 0, 1); gridPane.add(this.createColumnCB, 1, 1); lbl = new Label("Column name:"); lbl.setPrefWidth(100.0D); lbl.setMinWidth(100.0D); gridPane.add(lbl, 0, 2); gridPane.add(this.columnNameTF, 1, 2); lbl = new Label("Column postfix:"); lbl.setPrefWidth(100.0D); lbl.setMinWidth(100.0D); gridPane.add(lbl, 0, 3); gridPane.add(this.columnPostfixTF, 1, 3); lbl = new Label("Column datatype:"); lbl.setPrefWidth(100.0D); lbl.setMinWidth(100.0D); gridPane.add(lbl, 0, 4); gridPane.add(this.datatypeTF, 1, 4); lbl = new Label("Key:"); lbl.setPrefWidth(100.0D); lbl.setMinWidth(100.0D); gridPane.add(lbl, 0, 5); gridPane.add(this.isKeyCB, 1, 5); lbl = new Label("Autoincrement:"); lbl.setPrefWidth(100.0D); lbl.setMinWidth(100.0D); gridPane.add(lbl, 0, 6); FlowPane fp = new FlowPane(); fp.getChildren().add(this.isAutoincrementCB); fp.getChildren().add(this.autoincrementStartAtTF); gridPane.add(fp, 1, 6); lbl = new Label("Nullable:"); lbl.setPrefWidth(100.0D); lbl.setMinWidth(100.0D); gridPane.add(lbl, 0, 7); gridPane.add(this.isNullableCB, 1, 7); lbl = new Label("Unique:"); lbl.setPrefWidth(100.0D); lbl.setMinWidth(100.0D); gridPane.add(lbl, 0, 8); gridPane.add(this.isUniqueCB, 1, 8); lbl = new Label("Data generation:"); lbl.setPrefWidth(100.0D); lbl.setMinWidth(100.0D); gridPane.add(lbl, 0, 9); gridPane.add(this.dataGenerationTypeCoB, 1, 9); GridPane parameterGP = new GridPane(); this.par1LBL.setPrefWidth(150.0D); this.par2LBL.setMaxWidth(150.0D); this.par1TF.setPrefWidth(150.0D); this.par2TF.setMaxWidth(150.0D); parameterGP.add(this.par1LBL, 0, 0); parameterGP.add(this.par2LBL, 1, 0); parameterGP.add(this.par1TF, 0, 1); parameterGP.add(this.par2TF, 1, 1); gridPane.add(parameterGP, 0, 10, 2, 1); fp = new FlowPane(); fp.setHgap(10.0D); fp.getChildren().addAll(this.okBTN, this.cancelBTN); gridPane.add(fp, 0, 11, 2, 1); Scene scene = new Scene(gridPane, 280.0D, 355.0D); setScene(scene); setX(xPos); setY(yPos); if (yPos + scene.getHeight() > canvas.getView().getHeight() - 5.0D) { setY(yPos - scene.getHeight() - 20.0D); } if (xPos + scene.getWidth() > canvas.getView().getWidth() - 5.0D) { setX(xPos - scene.getWidth() - 20.0D); } sizeToScene(); this.columnNameTF.requestFocus(); if (isAutoincrement) { this.dataGenerationTypeCoB.setDisable(true); this.par1TF.setDisable(true); this.par2TF.setDisable(true); } showAndWait(); } private void setDataAndLeave() { if (this.createColumnCB.isSelected()) { if (this.columnNameTF.getText() == null || this.columnNameTF.getText().length() == 0) { return; } if (this.datatypeTF.getText() == null || this.datatypeTF.getText().length() == 0) { return; } } if (this.dataGenerationTypeCoB.getSelectionModel().getSelectedItem().equals("Extern")) { BufferedReader br = C2.randomDataFilesExtern.get(this.par1TF.getText()); if (br == null) { try { BufferedReader fr = new BufferedReader(new InputStreamReader(new FileInputStream(this.par2TF.getText()), StandardCharsets.UTF_8)); C2.randomDataFilesExtern.put(this.par1TF.getText(), fr); this.thisActionMessageDialog.close(); } catch (FileNotFoundException ignored) { } } else { C1 alert = new C1(null, Alert.AlertType.CONFIRMATION, "Input Transformation Data", "", "Key exists: " + this.par1TF.getText(), Boolean.TRUE, C2.applicationImageIconAsICO, "OK", "Cancel", C2.ButtonBackgroundColor, C2.MouseSelectedColor, C2.FocusOnComponentColor); Optional result = alert.getResult(); if (result.isPresent() && result.get() == ButtonType.OK) { this.thisActionMessageDialog.close(); } } } else { this.thisActionMessageDialog.close(); } } private void setNothingAndLeave() { this.nameTF.setText(this.holdName); this.createColumnCB.setSelected(this.holdcreateColumn); this.columnNameTF.setText(this.holdcolumnName); this.columnPostfixTF.setText(this.holdcolumnPostfix); this.datatypeTF.setText(this.holddatatype); this.isAutoincrementCB.setSelected(this.holdisAutoincrement); this.autoincrementStartAtTF.setText(String.valueOf(this.holdAutoincrementStartAt)); this.isKeyCB.setSelected(this.holdisKey); this.isNullableCB.setSelected(this.holdisNullable); this.isUniqueCB.setSelected(this.holdisUnique); this.dataGenerationTypeCoB.getSelectionModel().select(this.holddatagenerationtype); this.par1LBL.setText(this.holdpar1_label); this.par1TF.setText(this.holdpar1); this.par2LBL.setText(this.holdpar2_label); this.par2TF.setText(this.holdpar2); this.thisActionMessageDialog.close(); } public CheckBox getCreateColumnCB() { return this.createColumnCB; } public TextField getColumnNameTF() { return this.columnNameTF; } public TextField getColumnPostfixTF() { return this.columnPostfixTF; } public TextField getDatatypeTF() { return this.datatypeTF; } public CheckBox getIsAutoincrementCB() { return this.isAutoincrementCB; } public CheckBox getIsKeyCB() { return this.isKeyCB; } public CheckBox getIsNullableCB() { return this.isNullableCB; } public CheckBox getIsUniqueCB() { return this.isUniqueCB; } public ComboBox getDataGenerationTypeCoB() { return this.dataGenerationTypeCoB; } public Label getPar1LBL() { return this.par1LBL; } public TextField getPar1TF() { return this.par1TF; } public Label getPar2LBL() { return this.par2LBL; } public TextField getPar2TF() { return this.par2TF; } public TextField getAutoincrementStartAtTF() { return this.autoincrementStartAtTF; } private void setSelectionForGenerationtype() { if (this.dataGenerationTypeCoB.getSelectionModel().getSelectedItem() == null) return; String str; switch ((str = this.dataGenerationTypeCoB.getSelectionModel().getSelectedItem()).hashCode()) { case -1601184309 -> { if (!str.equals("Random Boolean")) { break; } this.par1TF.setText(""); this.par1LBL.setText(""); this.par1TF.setDisable(true); this.par2TF.setText(""); this.par2LBL.setText(""); this.par2TF.setDisable(true); this.datatypeTF.setText("boolean"); return; } case -123632396 -> { if (!str.equals("Random Decimal")) break; this.par1TF.setText("5"); this.par1LBL.setText("Before[.]"); this.par1TF.setDisable(false); this.par2TF.setText("2"); this.par2LBL.setText("After[.]"); this.par2TF.setDisable(false); this.datatypeTF.setText("decimal(7,2)"); return; } case 2529 -> { if (!str.equals("No")) break; this.par1TF.setText(""); this.par1LBL.setText(""); this.par1TF.setDisable(true); this.par2TF.setText(""); this.par2LBL.setText(""); this.par2TF.setDisable(true); return; } case 292156129 -> { if (!str.equals("Random Integer")) break; this.par1TF.setText("0"); this.par1LBL.setText("From"); this.par1TF.setDisable(false); this.par2TF.setText("1000"); this.par2LBL.setText("Till"); this.par2TF.setDisable(false); this.datatypeTF.setText("int"); return; } case 908695787 -> { if (!str.equals("Random Date")) break; this.par1TF.setText("1.1.1940"); this.par1LBL.setText("From"); this.par1TF.setDisable(false); this.par2TF.setText("31.12.2020"); this.par2LBL.setText("Till"); this.par2TF.setDisable(false); this.datatypeTF.setText("date"); return; } case 909176426 -> { if (!str.equals("Random Text")) break; this.par1TF.setText("100"); this.par1LBL.setText("Text length"); this.par1TF.setDisable(false); this.par2TF.setText(""); this.par2LBL.setText(""); this.par2TF.setDisable(true); this.datatypeTF.setText("varchar(100)"); return; } case 1599784748 -> { if (!str.equals("Incremented Integer")) break; this.par1TF.setText("0"); this.par1LBL.setText("From"); this.par1TF.setDisable(false); this.par2TF.setText(""); this.par2LBL.setText(""); this.par2TF.setDisable(true); this.datatypeTF.setText("int"); return; } case 2089790400 -> { if (!str.equals("Extern")) break; this.par1TF.setText(""); this.par1LBL.setText("Key"); this.par1TF.setDisable(false); this.par2TF.setText(""); this.par2LBL.setText("Path/File"); this.par2TF.setDisable(false); return; } } this.par1TF.setText(""); this.par1LBL.setText(""); this.par1TF.setDisable(true); this.par2TF.setText(""); this.par2LBL.setText(""); this.par2TF.setDisable(true); } private void setVisibilityForGenerationtype() { String str; switch ((str = this.dataGenerationTypeCoB.getSelectionModel().getSelectedItem()).hashCode()) { case -123632396 -> { if (!str.equals("Random Decimal")) { break; } this.par1LBL.setText("Before[.]"); this.par1TF.setDisable(false); this.par2LBL.setText("After[.]"); this.par2TF.setDisable(false); return; } case 2529 -> { if (!str.equals("No")) break; this.par1TF.setDisable(true); this.par2TF.setDisable(true); return; } case 292156129 -> { if (!str.equals("Random Integer")) break; this.par1LBL.setText("From"); this.par1TF.setDisable(false); this.par2LBL.setText("Till"); this.par2TF.setDisable(false); return; } case 908695787 -> { if (!str.equals("Random Date")) break; this.par1LBL.setText("From"); this.par1TF.setDisable(false); this.par2LBL.setText("Till"); this.par2TF.setDisable(false); return; } case 909176426 -> { if (!str.equals("Random Text")) break; this.par1LBL.setText("Text length"); this.par1TF.setDisable(false); this.par2LBL.setText(""); this.par2TF.setDisable(true); return; } case 1599784748 -> { if (!str.equals("Incremented Integer")) break; this.par1LBL.setText("From"); this.par1TF.setDisable(false); this.par2LBL.setText(""); this.par2TF.setDisable(true); return; } case 2089790400 -> { if (!str.equals("Extern")) break; this.par1LBL.setText("Key"); this.par1TF.setDisable(false); this.par2LBL.setText("Path/File"); this.par2TF.setDisable(false); return; } } this.par1TF.setText(""); this.par1LBL.setText(""); this.par1TF.setDisable(true); this.par2TF.setText(""); this.par2LBL.setText(""); this.par2TF.setDisable(true); } }