package at.fos.ermodel.gui;

import javafx.application.Platform;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.embed.swing.SwingFXUtils;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.geometry.Side;
import javafx.scene.Cursor;
import javafx.scene.Scene;
import javafx.scene.SnapshotParameters;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuBar;
import javafx.scene.control.MenuItem;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.TextField;
import javafx.scene.control.*;
import javafx.scene.image.ImageView;
import javafx.scene.image.WritableImage;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyCombination;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.*;
import javafx.scene.paint.Color;
import javafx.scene.paint.Paint;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.stage.FileChooser;
import javafx.stage.Stage;

import javax.imageio.ImageIO;
import java.awt.*;
import java.io.*;
import java.net.URISyntaxException;
import java.net.URL;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Objects;

public class B3
        extends Stage {
    public final TabPane tabPane;
    public final TabPane infoTabPane;
    public final CheckBox showAttributeCB;
    public final ToggleButton treeOpenBTN;
    public final FlowPane fptree;
    public final Label creationModelabel;
    public final ToggleGroup creation_selection_group;
    public final RadioButton selectModeBTN;
    public final GridPane buttonPane;
    public final RadioButton textElemBTN;
    public final RadioButton textWithoutBorderElemBTN;
    public final RadioButton esBTN;
    public final RadioButton esWeakBTN;
    public final RadioButton esAssociativeBTN;
    public final RadioButton rsBTN;
    public final RadioButton rsIDBTN;
    public final RadioButton rsISABTN;
    public final RadioButton attrOneBTN;
    public final RadioButton attrDerivedOneBTN;
    public final RadioButton attrMultiBTN;
    public final RadioButton attrDerivedMultiBTN;
    public final RadioButton attrKeyBTN;
    public final RadioButton attrWeakKeyBTN;
    public final RadioButton attrToAttrBTN;
    public final RadioButton attrToESBTN;
    public final RadioButton attrToRSBTN;
    public final RadioButton rsToESBTN;
    public final RadioButton rsidToESWeakBTN;
    public final RadioButton rsidToESBTN;
    public final RadioButton rsisaGeToESBTN;
    public final RadioButton rsisaSpToESBTN;
    public final ToggleGroup sqlStyleGroup;
    public final RadioButton mySqlStyle;
    public final RadioButton msSqlStyle;
    public final CheckBox generateRelationalModelCB;
    public final Button saveSQLScriptBTN;
    public final Button saveCSScriptBTN;
    public final CheckBox generateInsertsCB;
    public final CheckBox singleInsertStatementCB;
    public final CheckBox addCurrentDateToDatabaseNameCB;
    public final TextField statusInformation;
    public final MenuItem menuCutMI;
    public final MenuItem menuCopyMI;
    public final MenuItem menuPasteMI;
    public final MenuItem menuUndoMI;
    public final MenuItem menuSelectAllMI;
    public final MenuItem menuReadMI;
    public final MenuItem menuSaveMI;
    public final MenuItem menuSaveAsMI;
    public final MenuItem menuExportMI;
    public final MenuItem menuExitMI;
    public final MenuItem menuNewMI;
    public final MenuItem menuRedrawMI;
    public final MenuItem menuVersionMI;
    public final MenuItem menuDownloadMI;
    public final Menu menuVisibility;
    public final RadioMenuItem menuVisibilityAllRMI;
    public final RadioMenuItem menuVisibilityES_RSRMI;
    public final RadioMenuItem menuVisibilityES_RS_KEYRMI;
    public final RadioMenuItem menuVisibilityTEXTRMI;
    public final MenuItem mergeModelsMI;
    public final A2 controller;
    public final C2 properties;
    public RadioButton lastCreationSelected;
    public BorderPane treeBorderPane;
    public TreeItem<T1> rootTableNode;
    public TreeView<T1> treeTableView;
    public TreeItem<C3> rootColumnNode;
    public TreeView<C3> treeColumnView;
    public VBox verticalBox;
    public ListView<Graphic_Main_Elem> graphicElemLV;
    B3 thisERMViewFX;
    BorderPane borderPane;
    private U1 currentTab;
    private ArrayList<Graphic_Main_Elem> toCopyElements;
    private V1 progress;

    public B3() {
        this.thisERMViewFX = this;


        this.properties = new C2();

        this.treeBorderPane = new BorderPane();

        treeBorderPane.setBackground(C2.AppBackground);


        this.verticalBox = new VBox();

        verticalBox.setBackground(C2.AppBackground);


        this.controller = new A2(this);


        this.tabPane = new TabPane();

        tabPane.setBackground(C2.AppBackground);

        this.tabPane.setSide(Side.TOP);
        this.tabPane.setTabClosingPolicy(TabPane.TabClosingPolicy.SELECTED_TAB);


        this.infoTabPane = new TabPane();

        infoTabPane.setBackground(C2.AppBackground);

        this.infoTabPane.setSide(Side.TOP);
        this.infoTabPane.setTabClosingPolicy(TabPane.TabClosingPolicy.UNAVAILABLE);


        this.showAttributeCB = new CheckBox("Check data generation");
        this.showAttributeCB.setTooltip(new Tooltip("Check data generation"));
        this.showAttributeCB.setPrefWidth(40.0D);
        this.showAttributeCB.setMinWidth(40.0D);

        this.showAttributeCB.setOnAction(new EventHandler<>() {
            public void handle(ActionEvent event) {
                if (B3.this.showAttributeCB.isSelected()) {
                    if (!B3.this.selectModeBTN.isSelected()) {
                        B3.this.showAttributeCB.setSelected(false);
                        return;
                    }
                    B3.this.currentTab.canvas.sortGraphicElementsByName();
                    B3.this.graphicElemLV.getItems().clear();
                    B3.this.graphicElemLV.getItems().addAll(B3.this.currentTab.canvas.getAttributeElements());
                } else {
                    B3.this.graphicElemLV.getItems().clear();
                    B3.this.graphicElemLV.getItems().addAll(B3.this.currentTab.canvas.sddsfsfsdf45645645());
                }
            }
        });


        this.infoTabPane.setOnMouseClicked(arg0 -> B3.this.showAttributeCB.setDisable(B3.this.infoTabPane.getSelectionModel().getSelectedIndex() != 0));


        this.tabPane.getSelectionModel().selectedItemProperty().addListener(
                new ChangeListener<>() {

                    public void changed(ObservableValue<? extends Tab> ov, Tab t, Tab t1) {
                        B3.this.currentTab = (U1) B3.this.tabPane.getSelectionModel().getSelectedItem();

                        if (B3.this.currentTab != null && B3.this.currentTab.canvas != null) {
                            B3.this.graphicElemLV.getItems().clear();

                            if (B3.this.showAttributeCB.isSelected()) {
                                B3.this.graphicElemLV.getItems().addAll(B3.this.currentTab.canvas.getAttributeElements());
                            } else {
                                B3.this.graphicElemLV.getItems().addAll(B3.this.currentTab.canvas.sddsfsfsdf45645645());
                            }
                            if (B3.this.generateRelationalModelCB.isSelected()) {
                                B3.this.currentTab.canvas.dsfdsdfssdf45645re();
                            }
                            B3.this.currentTab.canvas.modelVisibility();
                            B3.this.currentTab.canvas.sdfsdfds3465er(true);
                        } else {

                            B3.this.verticalBox.getChildren().clear();
                            B3.this.graphicElemLV.getItems().clear();
                        }
                    }
                });


        VBox vBox = new VBox();

        this.creation_selection_group = new ToggleGroup();


        this.buttonPane = new GridPane();
        this.buttonPane.setPadding(new Insets(5.0D, 5.0D, 5.0D, 5.0D));
        this.buttonPane.setVgap(5.0D);
        this.buttonPane.setHgap(5.0D);
        buttonPane.setBackground(new Background(new BackgroundFill(C2.ERMForegroundColor, CornerRadii.EMPTY, Insets.EMPTY)));


        ImageView imageView = new ImageView(C2.treeOpenImage);
        imageView.setFitHeight(10.0D);
        imageView.setFitWidth(8.0D);
        this.treeOpenBTN = new ToggleButton();
        this.treeOpenBTN.setTooltip(new Tooltip("Click to expand info area"));
        this.treeOpenBTN.setOnMouseEntered(event -> {
            B3.this.getScene().getRoot().setCursor(Cursor.HAND);
            T3.asdasda345435ertretr(B3.this.treeOpenBTN.getGraphic(), 1.3D, 1.3D, 0.3D, 0.2D, 0.4D, -0.2D);
        });
        this.treeOpenBTN.setOnMouseExited(event -> {
            B3.this.getScene().getRoot().setCursor(Cursor.DEFAULT);
            T3.buttonMouseExited(B3.this.treeOpenBTN.getGraphic());
        });
        this.treeOpenBTN.setOnAction(new EventHandler<>() {
            public void handle(ActionEvent event) {
                if (B3.this.treeOpenBTN.isSelected()) {
                    ImageView imageView = new ImageView(C2.treeCloseImage);
                    imageView.setFitHeight(10.0D);
                    imageView.setFitWidth(8.0D);
                    B3.this.treeOpenBTN.setGraphic(imageView);
                    B3.this.treeBorderPane.setPrefWidth(200.0D);
                    B3.this.showAttributeCB.setVisible(true);
                    B3.this.fptree.setPrefWidth(50.0D);
                    B3.this.showAttributeCB.setMinWidth(150.0D);
                    B3.this.showAttributeCB.setMaxWidth(150.0D);
                    B3.this.showAttributeCB.setPrefWidth(150.0D);
                    B3.this.treeOpenBTN.setTooltip(new Tooltip("Click to close"));
                } else {

                    ImageView imageView = new ImageView(C2.treeOpenImage);
                    imageView.setFitHeight(10.0D);
                    imageView.setFitWidth(8.0D);
                    B3.this.treeOpenBTN.setGraphic(imageView);
                    B3.this.treeBorderPane.setPrefWidth(8.0D);
                    B3.this.showAttributeCB.setVisible(false);
                    B3.this.showAttributeCB.setPrefWidth(0.0D);
                    B3.this.treeOpenBTN.setTooltip(new Tooltip("Click to expand"));
                }
            }
        });


        this.treeOpenBTN.setBackground(new Background(new BackgroundFill(Color.LIGHTGRAY, CornerRadii.EMPTY, Insets.EMPTY)));


        this.treeOpenBTN.setGraphic(imageView);
        this.treeBorderPane.setBackground(new Background(new BackgroundFill(Color.LIGHTGRAY, CornerRadii.EMPTY, Insets.EMPTY)));
        this.treeBorderPane.setPrefWidth(10.0D);


        this.fptree = new FlowPane();
        this.fptree.getChildren().add(this.treeOpenBTN);
        this.fptree.getChildren().add(this.showAttributeCB);
        this.showAttributeCB.setPrefWidth(0.0D);
        this.showAttributeCB.setVisible(false);
        this.treeBorderPane.setTop(this.fptree);


        this.graphicElemLV = new ListView<>();
        graphicElemLV.setBackground(C2.AppBackground);
        this.graphicElemLV.setPrefHeight(300.0D);
        this.graphicElemLV.setTooltip(new Tooltip("To delete an element press DEL-Key"));
        this.graphicElemLV.setCellFactory(p -> new ListCell<>() {
            protected void updateItem(Graphic_Main_Elem item, boolean empty) {
                super.updateItem(item, empty);
                if (!empty && item != null) {
                    if (B3.this.showAttributeCB.isSelected()) {

                        setStyle("-fx-text-fill:  red;");
                        String doneString = "";
                        if (item instanceof Graphic_RS_ISA_Elem ||
                                item instanceof Graphic_ES_Weak_Elem) {
                            doneString = "... ok";
                            setStyle("-fx-text-fill:  green;");
                        } else {

                            if (item instanceof Graphic_ATTR_Elem) {
                                if (((Graphic_ATTR_Elem) item).dataGenerationType == null)
                                    ((Graphic_ATTR_Elem) item).dataGenerationType = "No";
                                if (!((Graphic_ATTR_Elem) item).dataGenerationType.equals("No")) {
                                    doneString = "... ok";
                                    setStyle("-fx-text-fill:  green;");
                                }
                                if (!((Graphic_ATTR_Elem) item).createColumn || ((Graphic_ATTR_Elem) item).isAutoincrement) {
                                    doneString = "... ok";
                                    setStyle("-fx-text-fill:  green;");
                                }

                                if (((Graphic_ATTR_Elem) item).isNullable) {
                                    doneString = "... ok";
                                    setStyle("-fx-text-fill:  green;");
                                }
                            }

                            if (item instanceof Graphic_ES_Main_Elem &&
                                    ((Graphic_ES_Main_Elem) item).createInserts && ((Graphic_ES_Main_Elem) item).numberRowsToInsert > 0L) {
                                doneString = "... ok";
                                setStyle("-fx-text-fill:  green;");
                            }

                            if (item instanceof Graphic_RS_Main_Elem &&
                                    ((Graphic_RS_Main_Elem) item).createInserts && ((Graphic_RS_Main_Elem) item).numberRowsToInsert > 0L) {
                                doneString = "... ok";
                                setStyle("-fx-text-fill:  green;");
                            }
                        }

                        setText(item.sdfsdfsd32234243() + " " + doneString);
                        return;
                    }
                    setText("[" + item.sdfsdfsdfd() + "]" + item.sdfsdfsd32234243());


                    if (!isSelected()) {

                        setStyle(null);
                    }
                } else {
                    setText(null);
                    setStyle(null);
                }
            }
        });

        this.graphicElemLV.setOnMouseClicked(event -> {
            Graphic_Main_Elem selectedItem = B3.this.graphicElemLV.getSelectionModel().getSelectedItem();
            if (selectedItem != null) {
                B3.this.currentTab.canvas.sdfsdfds3465er(true);
                B3.this.currentTab.canvas.dsfdsfsdf43543refds(selectedItem.graphicMainElemID);
            }
        });


        this.graphicElemLV.setOnKeyPressed(new EventHandler<>() {
            public void handle(KeyEvent event) {
                Graphic_Main_Elem selectedItem;
                if (Objects.requireNonNull(event.getCode()) == KeyCode.DELETE) {
                    if (!B3.this.selectModeBTN.isSelected()) {
                        return;
                    }


                    selectedItem = B3.this.graphicElemLV.getSelectionModel().getSelectedItem();
                    if (selectedItem != null) {
                        B3.this.graphicElemLV.getItems().remove(selectedItem);
                        selectedItem.dsfsdfsfd();

                        if (selectedItem instanceof Graphic_Figure_Elem) {
                            ArrayList<Graphic_LINE_Elem> linesAsEnd = B3.this.currentTab.canvas.sdfsdfds23432rwefsd(selectedItem);
                            ArrayList<Graphic_LINE_Elem> linesAsStart = B3.this.currentTab.canvas.dsfdsfdsjhkj456456(selectedItem);

                            for (Graphic_LINE_Elem gle : linesAsEnd) {
                                gle.dsfsdfsfd();
                                B3.this.currentTab.canvas.fsdfdsfds1231278().remove(gle);
                            }
                            for (Graphic_LINE_Elem gle : linesAsStart) {
                                gle.dsfsdfsfd();
                                B3.this.currentTab.canvas.fsdfdsfds1231278().remove(gle);
                            }
                        }

                        B3.this.currentTab.canvas.fsdfdsfds1231278().remove(selectedItem);
                    }
                }


            }
        });
        this.graphicElemLV.setOnKeyReleased(event -> {
            Graphic_Main_Elem selectedItem = B3.this.graphicElemLV.getSelectionModel().getSelectedItem();
            if (selectedItem != null) {
                B3.this.currentTab.canvas.sdfsdfds3465er(true);
                B3.this.currentTab.canvas.dsfdsfsdf43543refds(selectedItem.graphicMainElemID);
            }
        });


        this.infoTabPane.getTabs().add(new Tab("Elem", this.graphicElemLV));
        this.infoTabPane.getTabs().add(new Tab("R-Model", this.verticalBox));


        this.treeBorderPane.setCenter(this.infoTabPane);


        this.selectModeBTN = new RadioButton("Selection Mode");
        this.selectModeBTN.setFont(Font.font(null, FontWeight.BOLD, 11.0D));
        this.selectModeBTN.setStyle("-fx-text-fill:white");
        this.selectModeBTN.addEventHandler(ActionEvent.ACTION, this.controller);
        this.selectModeBTN.setSelected(true);
        this.selectModeBTN.setToggleGroup(this.creation_selection_group);
        this.selectModeBTN.setTooltip(new Tooltip("Selection Mode - F1-Key Selection mode <-> Creation Mode"));
        setMouseHandler(this.selectModeBTN);


        imageView = new ImageView(C2.textImage);
        imageView.setFitHeight(C2.imageHeight);
        imageView.setFitWidth(C2.imageWidth);
        this.textElemBTN = new RadioButton();
        this.textElemBTN.setPrefWidth(30.0D);
        this.textElemBTN.setGraphic(imageView);

        this.textElemBTN.addEventHandler(ActionEvent.ACTION, this.controller);
        this.textElemBTN.setSelected(false);
        this.textElemBTN.setToggleGroup(this.creation_selection_group);
        this.textElemBTN.setTooltip(new Tooltip("Text with border"));
        setMouseHandler(this.textElemBTN);


        imageView = new ImageView(C2.textWithoutBorderImage);
        imageView.setFitHeight(C2.imageHeight);
        imageView.setFitWidth(C2.imageWidth);
        this.textWithoutBorderElemBTN = new RadioButton();
        this.textWithoutBorderElemBTN.setPrefWidth(30.0D);
        this.textWithoutBorderElemBTN.setGraphic(imageView);

        this.textWithoutBorderElemBTN.addEventHandler(ActionEvent.ACTION, this.controller);
        this.textWithoutBorderElemBTN.setSelected(false);
        this.textWithoutBorderElemBTN.setToggleGroup(this.creation_selection_group);
        this.textWithoutBorderElemBTN.setTooltip(new Tooltip("Text without border"));
        setMouseHandler(this.textWithoutBorderElemBTN);


        imageView = new ImageView(C2.esImage);
        imageView.setFitHeight(C2.imageHeight);
        imageView.setFitWidth(C2.imageWidth);
        this.esBTN = new RadioButton();
        this.esBTN.setPrefWidth(30.0D);
        this.esBTN.setGraphic(imageView);
        setMouseHandler(this.esBTN);

        this.esBTN.addEventHandler(ActionEvent.ACTION, this.controller);
        this.esBTN.setSelected(true);
        this.lastCreationSelected = this.esBTN;
        this.esBTN.setToggleGroup(this.creation_selection_group);
        this.esBTN.setTooltip(new Tooltip("Entity set"));


        imageView = new ImageView(C2.es_weakImage);
        imageView.setFitHeight(C2.imageHeight);
        imageView.setFitWidth(C2.imageWidth);
        this.esWeakBTN = new RadioButton();
        this.esWeakBTN.setPrefWidth(30.0D);
        this.esWeakBTN.setGraphic(imageView);
        setMouseHandler(this.esWeakBTN);

        this.esWeakBTN.addEventHandler(ActionEvent.ACTION, this.controller);
        this.esWeakBTN.setToggleGroup(this.creation_selection_group);
        this.esWeakBTN.setTooltip(new Tooltip("Weak entity set"));


        imageView = new ImageView(C2.es_associativeImage);
        imageView.setFitHeight(C2.imageHeight);
        imageView.setFitWidth(C2.imageWidth);
        this.esAssociativeBTN = new RadioButton();
        this.esAssociativeBTN.setPrefWidth(30.0D);
        this.esAssociativeBTN.setGraphic(imageView);
        setMouseHandler(this.esAssociativeBTN);

        this.esAssociativeBTN.addEventHandler(ActionEvent.ACTION, this.controller);
        this.esAssociativeBTN.setToggleGroup(this.creation_selection_group);
        this.esAssociativeBTN.setTooltip(new Tooltip("Associative entity set"));


        imageView = new ImageView(C2.rsImage);
        imageView.setFitHeight(C2.imageHeight);
        imageView.setFitWidth(C2.imageWidth);
        this.rsBTN = new RadioButton();
        this.rsBTN.setPrefWidth(30.0D);
        this.rsBTN.setGraphic(imageView);
        setMouseHandler(this.rsBTN);

        this.rsBTN.addEventHandler(ActionEvent.ACTION, this.controller);
        this.rsBTN.setToggleGroup(this.creation_selection_group);
        this.rsBTN.setTooltip(new Tooltip("Relationship"));


        imageView = new ImageView(C2.rs_idImage);
        imageView.setFitHeight(C2.imageHeight);
        imageView.setFitWidth(C2.imageWidth);
        this.rsIDBTN = new RadioButton();
        this.rsIDBTN.setPrefWidth(30.0D);
        this.rsIDBTN.setGraphic(imageView);
        setMouseHandler(this.rsIDBTN);

        this.rsIDBTN.addEventHandler(ActionEvent.ACTION, this.controller);
        this.rsIDBTN.setToggleGroup(this.creation_selection_group);
        this.rsIDBTN.setTooltip(new Tooltip("Identifying-relationship: used together with a weak-entity-set"));


        imageView = new ImageView(C2.rs_isaImage);
        imageView.setFitHeight(C2.imageHeight);
        imageView.setFitWidth(C2.imageWidth);
        this.rsISABTN = new RadioButton();
        this.rsISABTN.setPrefWidth(30.0D);
        this.rsISABTN.setGraphic(imageView);
        setMouseHandler(this.rsISABTN);

        this.rsISABTN.addEventHandler(ActionEvent.ACTION, this.controller);
        this.rsISABTN.setToggleGroup(this.creation_selection_group);
        this.rsISABTN.setTooltip(new Tooltip("ISA relationship - generalization/specialization"));


        imageView = new ImageView(C2.attr_one_valueImage);
        imageView.setFitHeight(C2.imageHeight);
        imageView.setFitWidth(C2.imageWidth);
        this.attrOneBTN = new RadioButton();
        this.attrOneBTN.setPrefWidth(30.0D);
        this.attrOneBTN.setGraphic(imageView);
        setMouseHandler(this.attrOneBTN);

        this.attrOneBTN.addEventHandler(ActionEvent.ACTION, this.controller);
        this.attrOneBTN.setToggleGroup(this.creation_selection_group);
        this.attrOneBTN.setTooltip(new Tooltip("One value attribute"));


        imageView = new ImageView(C2.attr_multi_valueImage);
        imageView.setFitHeight(C2.imageHeight);
        imageView.setFitWidth(C2.imageWidth);
        this.attrMultiBTN = new RadioButton();
        this.attrMultiBTN.setPrefWidth(30.0D);
        this.attrMultiBTN.setGraphic(imageView);
        setMouseHandler(this.attrMultiBTN);

        this.attrMultiBTN.addEventHandler(ActionEvent.ACTION, this.controller);
        this.attrMultiBTN.setToggleGroup(this.creation_selection_group);
        this.attrMultiBTN.setTooltip(new Tooltip("Multivalue attribute"));


        imageView = new ImageView(C2.attr_key_valueImage);
        imageView.setFitHeight(C2.imageHeight);
        imageView.setFitWidth(C2.imageWidth);
        this.attrKeyBTN = new RadioButton();
        this.attrKeyBTN.setPrefWidth(30.0D);
        this.attrKeyBTN.setGraphic(imageView);
        setMouseHandler(this.attrKeyBTN);

        this.attrKeyBTN.addEventHandler(ActionEvent.ACTION, this.controller);
        this.attrKeyBTN.setToggleGroup(this.creation_selection_group);
        this.attrKeyBTN.setTooltip(new Tooltip("Primary key attribute"));


        imageView = new ImageView(C2.attr_weak_key_valueImage);
        imageView.setFitHeight(C2.imageHeight);
        imageView.setFitWidth(C2.imageWidth);
        this.attrWeakKeyBTN = new RadioButton();
        this.attrWeakKeyBTN.setPrefWidth(30.0D);
        this.attrWeakKeyBTN.setGraphic(imageView);
        setMouseHandler(this.attrWeakKeyBTN);

        this.attrWeakKeyBTN.addEventHandler(ActionEvent.ACTION, this.controller);
        this.attrWeakKeyBTN.setToggleGroup(this.creation_selection_group);
        this.attrWeakKeyBTN.setTooltip(new Tooltip("Weak key attribute"));


        imageView = new ImageView(C2.attr_derived_one_valueImage);
        imageView.setFitHeight(C2.imageHeight);
        imageView.setFitWidth(C2.imageWidth);
        this.attrDerivedOneBTN = new RadioButton();
        this.attrDerivedOneBTN.setPrefWidth(30.0D);
        this.attrDerivedOneBTN.setGraphic(imageView);
        setMouseHandler(this.attrDerivedOneBTN);

        this.attrDerivedOneBTN.addEventHandler(ActionEvent.ACTION, this.controller);
        this.attrDerivedOneBTN.setToggleGroup(this.creation_selection_group);
        this.attrDerivedOneBTN.setTooltip(new Tooltip("Derived one-value-attribute"));


        imageView = new ImageView(C2.attr_derived_multi_valueImage);
        imageView.setFitHeight(C2.imageHeight);
        imageView.setFitWidth(C2.imageWidth);
        this.attrDerivedMultiBTN = new RadioButton();
        this.attrDerivedMultiBTN.setPrefWidth(30.0D);
        this.attrDerivedMultiBTN.setGraphic(imageView);
        setMouseHandler(this.attrDerivedMultiBTN);

        this.attrDerivedMultiBTN.addEventHandler(ActionEvent.ACTION, this.controller);
        this.attrDerivedMultiBTN.setToggleGroup(this.creation_selection_group);
        this.attrDerivedMultiBTN.setTooltip(new Tooltip("Derived multi-value-attribute"));


        imageView = new ImageView(C2.attr_conn_attrImage);
        imageView.setFitHeight(C2.imageHeight);
        imageView.setFitWidth(C2.imageWidth);
        this.attrToAttrBTN = new RadioButton();
        this.attrToAttrBTN.setPrefWidth(30.0D);
        this.attrToAttrBTN.setGraphic(imageView);
        setMouseHandler(this.attrToAttrBTN);

        this.attrToAttrBTN.addEventHandler(ActionEvent.ACTION, this.controller);
        this.attrToAttrBTN.setToggleGroup(this.creation_selection_group);
        this.attrToAttrBTN.setTooltip(new Tooltip("Connect attribute with attribute (to create composite-attribute)"));


        imageView = new ImageView(C2.attr_conn_esImage);
        imageView.setFitHeight(C2.imageHeight);
        imageView.setFitWidth(C2.imageWidth);
        this.attrToESBTN = new RadioButton();
        this.attrToESBTN.setPrefWidth(30.0D);
        this.attrToESBTN.setGraphic(imageView);
        setMouseHandler(this.attrToESBTN);

        this.attrToESBTN.addEventHandler(ActionEvent.ACTION, this.controller);
        this.attrToESBTN.setToggleGroup(this.creation_selection_group);
        this.attrToESBTN.setTooltip(new Tooltip("Connect attribute with entity-set"));


        imageView = new ImageView(C2.attr_conn_rsImage);
        imageView.setFitHeight(C2.imageHeight);
        imageView.setFitWidth(C2.imageWidth);
        this.attrToRSBTN = new RadioButton();
        this.attrToRSBTN.setPrefWidth(30.0D);
        this.attrToRSBTN.setGraphic(imageView);
        setMouseHandler(this.attrToRSBTN);

        this.attrToRSBTN.addEventHandler(ActionEvent.ACTION, this.controller);
        this.attrToRSBTN.setToggleGroup(this.creation_selection_group);
        this.attrToRSBTN.setTooltip(new Tooltip("Connect attribute with relationship"));


        imageView = new ImageView(C2.rs_conn_esImage);
        imageView.setFitHeight(C2.imageHeight);
        imageView.setFitWidth(C2.imageWidth);
        this.rsToESBTN = new RadioButton();
        this.rsToESBTN.setPrefWidth(30.0D);
        this.rsToESBTN.setGraphic(imageView);
        setMouseHandler(this.rsToESBTN);

        this.rsToESBTN.addEventHandler(ActionEvent.ACTION, this.controller);
        this.rsToESBTN.setToggleGroup(this.creation_selection_group);
        this.rsToESBTN.setTooltip(new Tooltip("Connect entity-set with relationship"));


        imageView = new ImageView(C2.rs_id_conn_es_weakImage);
        imageView.setFitHeight(C2.imageHeight);
        imageView.setFitWidth(C2.imageWidth);
        this.rsidToESWeakBTN = new RadioButton();
        this.rsidToESWeakBTN.setPrefWidth(30.0D);
        this.rsidToESWeakBTN.setGraphic(imageView);
        setMouseHandler(this.rsidToESWeakBTN);

        this.rsidToESWeakBTN.addEventHandler(ActionEvent.ACTION, this.controller);
        this.rsidToESWeakBTN.setToggleGroup(this.creation_selection_group);
        this.rsidToESWeakBTN.setTooltip(new Tooltip("Connect weak-entity-set with identifying-relationship"));


        imageView = new ImageView(C2.rs_id_conn_esImage);
        imageView.setFitHeight(C2.imageHeight);
        imageView.setFitWidth(C2.imageWidth);
        this.rsidToESBTN = new RadioButton();
        this.rsidToESBTN.setPrefWidth(30.0D);
        this.rsidToESBTN.setGraphic(imageView);
        setMouseHandler(this.rsidToESBTN);

        this.rsidToESBTN.addEventHandler(ActionEvent.ACTION, this.controller);
        this.rsidToESBTN.setToggleGroup(this.creation_selection_group);
        this.rsidToESBTN.setTooltip(new Tooltip("Connect entity-set with identifying-relationship"));


        imageView = new ImageView(C2.rs_isa_conn_general_esImage);
        imageView.setFitHeight(C2.imageHeight);
        imageView.setFitWidth(C2.imageWidth);
        this.rsisaGeToESBTN = new RadioButton();
        this.rsisaGeToESBTN.setPrefWidth(30.0D);
        this.rsisaGeToESBTN.setGraphic(imageView);
        setMouseHandler(this.rsisaGeToESBTN);

        this.rsisaGeToESBTN.addEventHandler(ActionEvent.ACTION, this.controller);
        this.rsisaGeToESBTN.setToggleGroup(this.creation_selection_group);
        this.rsisaGeToESBTN.setTooltip(new Tooltip("Connect isa-relationship with entity-set (generalization)"));


        imageView = new ImageView(C2.rs_isa_conn_special_esImage);
        imageView.setFitHeight(C2.imageHeight);
        imageView.setFitWidth(C2.imageWidth);
        this.rsisaSpToESBTN = new RadioButton();
        this.rsisaSpToESBTN.setPrefWidth(30.0D);
        this.rsisaSpToESBTN.setGraphic(imageView);
        setMouseHandler(this.rsisaSpToESBTN);

        this.rsisaSpToESBTN.addEventHandler(ActionEvent.ACTION, this.controller);
        this.rsisaSpToESBTN.setToggleGroup(this.creation_selection_group);
        this.rsisaSpToESBTN.setTooltip(new Tooltip("Connect isa-relationship with entity-set (specialization)"));


        this.generateRelationalModelCB = new CheckBox("Generate Relational Model");
        this.generateRelationalModelCB.setTooltip(new Tooltip("To check the relational model open the area right to the working area"));
        this.generateRelationalModelCB.setSelected(false);
        generateRelationalModelCB.setStyle("-fx-text-fill: #ffffff;");

        setMouseHandler(this.generateRelationalModelCB);
        this.generateRelationalModelCB.setOnAction(arg0 -> {
            if (B3.this.generateRelationalModelCB.isSelected()) {
                if (!B3.this.selectModeBTN.isSelected()) {
                    B3.this.generateRelationalModelCB.setSelected(false);
                    return;
                }
                if (B3.this.currentTab != null && B3.this.currentTab.canvas != null)
                    B3.this.currentTab.canvas.dsfdsdfssdf45645re();

            } else {

                B3.this.verticalBox.getChildren().clear();
            }
        });


        this.saveSQLScriptBTN = new Button("Generate/Save DDL script");
        this.saveSQLScriptBTN.setTooltip(new Tooltip("The ddl-script will be generated and saved into a file"));
        this.saveSQLScriptBTN.setMaxWidth(Double.MAX_VALUE);
        setMouseHandler(this.saveSQLScriptBTN);
        GridPane.setFillWidth(this.saveSQLScriptBTN, Boolean.TRUE);
        this.saveSQLScriptBTN.setBackground(new Background(new BackgroundFill(C2.ButtonBackgroundColor, CornerRadii.EMPTY, Insets.EMPTY)));

        this.saveSQLScriptBTN.setOnAction(arg0 -> {
            if (B3.this.generateRelationalModelCB.isSelected()) {
                try {
                    B3.this.saveSQLScript();
                } catch (ZZ20 ignored) {
                }
            }
        });

        this.saveCSScriptBTN = new Button("Generate/Save C# script");
        this.saveCSScriptBTN.setTooltip(new Tooltip("The ddl-script will be generated and saved into a file"));
        this.saveCSScriptBTN.setMaxWidth(Double.MAX_VALUE);
        setMouseHandler(this.saveCSScriptBTN);
        GridPane.setFillWidth(this.saveCSScriptBTN, Boolean.TRUE);
        this.saveCSScriptBTN.setBackground(new Background(new BackgroundFill(C2.ButtonBackgroundColor, CornerRadii.EMPTY, Insets.EMPTY)));

        this.saveCSScriptBTN.setOnAction(arg0 -> {
            if (B3.this.generateRelationalModelCB.isSelected()) {
                try {
                    B3.this.saveCSScript();
                } catch (ZZ20 ignored) {
                }
            }
        });


        this.generateInsertsCB = new CheckBox("Generate insert statement");
        this.generateInsertsCB.setTooltip(new Tooltip("If selected, insert statements are generated in the ddl-script"));
        setMouseHandler(this.generateInsertsCB);
        this.generateInsertsCB.setFont(Font.font(null, FontWeight.NORMAL, 11.0D));
        this.generateInsertsCB.setSelected(false);
        this.singleInsertStatementCB = new CheckBox("-> as multiple insert statements");
        this.singleInsertStatementCB.setTooltip(new Tooltip("If selected, all inserts are seperated statements"));
        setMouseHandler(this.singleInsertStatementCB);
        this.singleInsertStatementCB.setFont(Font.font(null, FontWeight.NORMAL, 11.0D));
        this.singleInsertStatementCB.setSelected(false);

        this.addCurrentDateToDatabaseNameCB = new CheckBox("Add current date to db-name");
        this.addCurrentDateToDatabaseNameCB.setTooltip(new Tooltip("If selected, the current date will be added to the db-name"));
        setMouseHandler(this.addCurrentDateToDatabaseNameCB);
        this.addCurrentDateToDatabaseNameCB.setFont(Font.font(null, FontWeight.NORMAL, 11.0D));
        this.addCurrentDateToDatabaseNameCB.setSelected(false);


        this.sqlStyleGroup = new ToggleGroup();
        this.mySqlStyle = new RadioButton("MySQL");
        this.mySqlStyle.setTooltip(new Tooltip("Creates a MySQL style script"));
        this.mySqlStyle.setToggleGroup(this.sqlStyleGroup);
        this.mySqlStyle.setSelected(true);
        setMouseHandler(this.mySqlStyle);
        this.msSqlStyle = new RadioButton("MSSQL");
        this.msSqlStyle.setTooltip(new Tooltip("Creates a Microsoft-SQL-Server style script"));
        this.msSqlStyle.setToggleGroup(this.sqlStyleGroup);
        setMouseHandler(this.msSqlStyle);
        FlowPane sqlStylePane = new FlowPane();
        sqlStylePane.setPrefWidth(40.0D);
        sqlStylePane.getChildren().add(this.mySqlStyle);
        sqlStylePane.getChildren().add(this.msSqlStyle);


        int ci = 0, ri = 0;


        this.buttonPane.add(this.selectModeBTN, ci, ri++, 2, 1);


        Label crLBL = new Label("Creation Mode");
        crLBL.setFont(Font.font(null, FontWeight.BOLD, 11.0D));

        HBox labeledSeparator = new HBox();
        this.creationModelabel = new Label(" Creation mode ");
        this.creationModelabel.setStyle("-fx-text-fill:red");
        this.creationModelabel.setFont(Font.font(null, FontWeight.BOLD, 11.0D));
        Separator leftSeparator = new Separator();
        leftSeparator.setPrefWidth(42.0D);
        Separator rightSeparator = new Separator();
        rightSeparator.setPrefWidth(42.0D);
        labeledSeparator.getChildren().add(leftSeparator);
        labeledSeparator.getChildren().add(this.creationModelabel);
        labeledSeparator.getChildren().add(rightSeparator);
        labeledSeparator.setAlignment(Pos.CENTER);

        FlowPane fp = new FlowPane(crLBL);
        fp.setPrefWidth(40.0D);
        fp.setAlignment(Pos.CENTER);
        this.buttonPane.add(labeledSeparator, 0, ri++, 2, 1);


        VBox vbox0 = new VBox(10.0D);
        HBox hbox0 = new HBox(10.0D);
        hbox0.getChildren().addAll(this.textElemBTN, this.textWithoutBorderElemBTN);
        vbox0.getChildren().addAll(hbox0);
        TitledPane textElement = new TitledPane("Text element", vbox0);
        Accordion accorTextelement = new Accordion();
        accorTextelement.getPanes().add(textElement);
        this.buttonPane.add(accorTextelement, 0, ri++, 2, 1);

        vbox0 = new VBox(10.0D);
        hbox0 = new HBox(10.0D);
        hbox0.getChildren().addAll(this.esBTN, this.esWeakBTN);
        HBox hbox1 = new HBox(10.0D);
        hbox1.getChildren().addAll(this.esAssociativeBTN);
        vbox0.getChildren().addAll(hbox0, hbox1);
        TitledPane entitysetType = new TitledPane("Entity-set type", vbox0);
        this.buttonPane.add(entitysetType, 0, ri++, 2, 1);
        entitysetType.setBackground(C2.AppForeground);

        vbox0 = new VBox(10.0D);
        hbox0 = new HBox(10.0D);
        hbox0.getChildren().addAll(this.rsBTN, this.rsIDBTN);
        hbox1 = new HBox(10.0D);
        hbox1.getChildren().addAll(this.rsISABTN);
        vbox0.getChildren().addAll(hbox0, hbox1);
        TitledPane relationshipType = new TitledPane("Relationship type", vbox0);
        this.buttonPane.add(relationshipType, 0, ri++, 2, 1);
        relationshipType.setBackground(C2.AppForeground);

        vbox0 = new VBox(10.0D);
        hbox0 = new HBox(10.0D);
        hbox0.getChildren().addAll(this.rsToESBTN);
        hbox1 = new HBox(10.0D);
        hbox1.getChildren().addAll(this.rsidToESBTN, this.rsidToESWeakBTN);
        HBox hbox2 = new HBox(10.0D);
        hbox2.getChildren().addAll(this.rsisaGeToESBTN, this.rsisaSpToESBTN);
        vbox0.getChildren().addAll(hbox0, hbox1, hbox2);
        TitledPane connectESRS = new TitledPane("Connect ES-RS", vbox0);

        this.buttonPane.add(connectESRS, 0, ri++, 2, 1);
        connectESRS.setBackground(C2.AppForeground);

        vbox0 = new VBox(10.0D);
        hbox0 = new HBox(10.0D);
        hbox0.getChildren().addAll(this.attrKeyBTN, this.attrWeakKeyBTN);
        hbox1 = new HBox(10.0D);
        hbox1.getChildren().addAll(this.attrOneBTN, this.attrMultiBTN);
        hbox2 = new HBox(10.0D);
        hbox2.getChildren().addAll(this.attrDerivedOneBTN, this.attrDerivedMultiBTN);
        vbox0.getChildren().addAll(hbox0, hbox1, hbox2);
        TitledPane attributeTypes = new TitledPane("Attribute type", vbox0);
        attributeTypes.setExpanded(false);
        this.buttonPane.add(attributeTypes, 0, ri++, 2, 1);
        attributeTypes.setBackground(C2.AppForeground);

        vbox0 = new VBox(10.0D);
        hbox0 = new HBox(10.0D);
        hbox0.getChildren().addAll(this.attrToESBTN, this.attrToRSBTN);
        hbox1 = new HBox(10.0D);
        hbox1.getChildren().addAll(this.attrToAttrBTN);
        vbox0.getChildren().addAll(hbox0, hbox1);
        TitledPane connectAttribute = new TitledPane("Connect Attribute", vbox0);
        connectAttribute.setExpanded(false);
        this.buttonPane.add(connectAttribute, 0, ri++, 2, 1);
        connectAttribute.setBackground(C2.AppForeground);
        this.buttonPane.add(this.generateRelationalModelCB, 0, ri++, 2, 1);


        VBox box = new VBox(10.0D);
        box.getChildren().addAll(this.addCurrentDateToDatabaseNameCB, this.generateInsertsCB, this.singleInsertStatementCB, this.saveSQLScriptBTN);
        TitledPane createddl = new TitledPane("Create DDL", box);
        createddl.setExpanded(false);
        this.buttonPane.add(createddl, 0, ri++, 2, 1);

        VBox csbox = new VBox(10.0D);
        csbox.getChildren().addAll(saveCSScriptBTN);

        TitledPane createcsharp = new TitledPane("Create C# Code", csbox);
        createcsharp.setExpanded(false);
        this.buttonPane.add(createcsharp, 0, ri, 2, 1);

        this.statusInformation = new TextField("Creation Mode: entity-set -> press left mouse button on working area -> enter name of entity-set -> press enter key");
        this.statusInformation.setEditable(false);
        this.statusInformation.setFocusTraversable(false);

        this.currentTab = addNewTab(null);

        ScrollPane scrollPane = new ScrollPane();
        scrollPane.setContent(this.buttonPane);
        scrollPane.setFitToHeight(true);

        this.borderPane = new BorderPane();
        this.borderPane.setLeft(scrollPane);
        this.borderPane.setCenter(this.tabPane);
        this.borderPane.setRight(this.treeBorderPane);
        this.borderPane.setBottom(this.statusInformation);

        this.borderPane.setOnKeyPressed(arg0 -> {
            if (B3.this.currentTab != null && B3.this.currentTab.canvas != null) {
                B3.this.currentTab.canvas.sdfdsfd567657rrt(arg0);
            }
        });

        setTitle("ER-Modeling-Chen++ -> Relational Model -> Database Creation + Data Generation ~ [jre-" +
                System.getProperty("java.version") + " - " + System.getProperty("java.class.path") + "]");

        setResizable(true);
        centerOnScreen();


        MenuBar menuBar = new MenuBar();


        Menu menuFile = new Menu("_File");

        menuFile.setMnemonicParsing(true);


        this.menuNewMI = new MenuItem("_New model");
        this.menuNewMI.setMnemonicParsing(true);

        this.menuNewMI.addEventHandler(ActionEvent.ACTION, this.controller);
        this.menuNewMI.setAccelerator(
                KeyCombination.keyCombination("SHORTCUT+N"));

        this.menuRedrawMI = new MenuItem("_Redraw model");
        this.menuRedrawMI.setMnemonicParsing(true);

        this.menuRedrawMI.addEventHandler(ActionEvent.ACTION, this.controller);
        this.menuRedrawMI.setAccelerator(
                KeyCombination.keyCombination("SHORTCUT+R"));

        this.menuReadMI = new MenuItem("_Open model");

        this.menuReadMI.addEventHandler(ActionEvent.ACTION, this.controller);
        this.menuReadMI.setAccelerator(
                KeyCombination.keyCombination("SHORTCUT+O"));

        this.menuSaveMI = new MenuItem("_Save model");
        this.menuSaveMI.addEventHandler(ActionEvent.ACTION, this.controller);
        this.menuSaveMI.setAccelerator(
                KeyCombination.keyCombination("SHORTCUT+S"));


        this.menuSaveAsMI = new MenuItem("Save model as");

        this.menuSaveAsMI.addEventHandler(ActionEvent.ACTION, this.controller);

        this.menuExportMI = new MenuItem("_Export model (png)");
        this.menuExportMI.setMnemonicParsing(true);

        this.menuExportMI.addEventHandler(ActionEvent.ACTION, this.controller);

        this.menuExitMI = new MenuItem("_Exit");

        this.menuExitMI.addEventHandler(ActionEvent.ACTION, this.controller);
        this.menuExitMI.setMnemonicParsing(true);
        this.menuExitMI.setAccelerator(
                KeyCombination.keyCombination("SHORTCUT+E"));

        menuFile.getItems().addAll(this.menuNewMI, new SeparatorMenuItem(),
                this.menuRedrawMI, new SeparatorMenuItem(),
                this.menuReadMI, this.menuSaveMI, this.menuSaveAsMI, this.menuExportMI, new SeparatorMenuItem(),
                this.menuExitMI);

        Menu menuEdit = new Menu("_Edit");

        this.menuCutMI = new MenuItem("Cut");
        this.menuCutMI.setMnemonicParsing(true);
        this.menuCutMI.setAccelerator(
                KeyCombination.keyCombination("SHORTCUT+X"));

        this.menuCopyMI = new MenuItem("_Copy");
        this.menuCopyMI.setMnemonicParsing(true);
        this.menuCopyMI.setAccelerator(
                KeyCombination.keyCombination("SHORTCUT+C"));

        this.menuCopyMI.addEventHandler(ActionEvent.ACTION, this.controller);

        this.menuPasteMI = new MenuItem("Paste");
        this.menuPasteMI.setMnemonicParsing(true);
        this.menuPasteMI.setAccelerator(
                KeyCombination.keyCombination("SHORTCUT+V"));

        this.menuPasteMI.addEventHandler(ActionEvent.ACTION, this.controller);

        this.menuSelectAllMI = new MenuItem("Select all");
        this.menuSelectAllMI.setMnemonicParsing(true);
        this.menuSelectAllMI.setAccelerator(
                KeyCombination.keyCombination("SHORTCUT+A"));

        this.menuSelectAllMI.addEventHandler(ActionEvent.ACTION, this.controller);

        this.menuUndoMI = new MenuItem("Undo");
        this.menuUndoMI.setMnemonicParsing(true);
        this.menuUndoMI.setAccelerator(
                KeyCombination.keyCombination("SHORTCUT+Z"));

        this.menuUndoMI.addEventHandler(ActionEvent.ACTION, this.controller);

        menuEdit.getItems().addAll(this.menuUndoMI, new SeparatorMenuItem(), this.menuCutMI, this.menuCopyMI, this.menuPasteMI, new SeparatorMenuItem(), this.menuSelectAllMI);

        Menu menuModel = new Menu("_Model");
        this.mergeModelsMI = new MenuItem("Merge models");
        this.mergeModelsMI.setOnAction(arg0 -> {
            if (B3.this.generateRelationalModelCB.isSelected()) {
                return;
            }


            for (Tab tab : B3.this.tabPane.getTabs()) {
                U1 runningTab = (U1) tab;
                if (runningTab.getText().contains("*")) {
                    return;
                }
            }


            ZZ30 mergedModel = new ZZ30(B3.this.thisERMViewFX);
            try {
                boolean merged = mergedModel.mergeAllModelsInPanes();
                if (!merged) {
                    return;


                }


            } catch (ClassNotFoundException | IOException e) {
                return;
            }


            B3.this.currentTab = B3.this.addNewTab(null);

            for (Graphic_Main_Elem gme : mergedModel.getGraphicElements()) {
                gme.setGc(B3.this.currentTab.canvas.getGraphicsContext2D());

                gme.isVisible = true;
            }

            B3.this.currentTab.canvas.dsfds124332(B3.this.currentTab.canvas.sdfsddf345ersdf());

            B3.this.currentTab.canvas.clearERMDrawCanvas();
            B3.this.currentTab.canvas.safdsadsa65765ewthjk(mergedModel.getGraphicElements());
            B3.this.currentTab.canvas.sdfsdfds3465er(true);

            B3.this.tabPane.getSelectionModel().select(B3.this.currentTab);


            B3.this.currentTab.canvas.dsfdsdfssdf45645re();
        });


        this.menuVisibility = new Menu("_Visibility");
        this.menuVisibility.setDisable(true);
        this.menuVisibilityAllRMI = new RadioMenuItem("All");
        this.menuVisibilityAllRMI.setSelected(true);
        this.menuVisibilityAllRMI.addEventHandler(ActionEvent.ACTION, this.controller);
        this.menuVisibilityES_RSRMI = new RadioMenuItem("ES + RS");
        this.menuVisibilityES_RSRMI.addEventHandler(ActionEvent.ACTION, this.controller);
        this.menuVisibilityES_RS_KEYRMI = new RadioMenuItem("ES + RS + KEYS");
        this.menuVisibilityES_RS_KEYRMI.addEventHandler(ActionEvent.ACTION, this.controller);
        this.menuVisibilityTEXTRMI = new RadioMenuItem("Text");
        this.menuVisibilityTEXTRMI.addEventHandler(ActionEvent.ACTION, this.controller);
        this.menuVisibilityTEXTRMI.setSelected(true);


        menuModel.getItems().addAll(this.menuVisibility, this.mergeModelsMI);
        this.menuVisibility.getItems().addAll(this.menuVisibilityAllRMI, this.menuVisibilityES_RSRMI, this.menuVisibilityES_RS_KEYRMI, this.menuVisibilityTEXTRMI);
        ToggleGroup tggroup = new ToggleGroup();
        tggroup.getToggles().addAll(this.menuVisibilityAllRMI, this.menuVisibilityES_RSRMI, this.menuVisibilityES_RS_KEYRMI);


        Menu menuHelp = new Menu("_Help");
        this.menuVersionMI = new MenuItem("Version");
        this.menuVersionMI.addEventHandler(ActionEvent.ACTION, this.controller);
        this.menuVersionMI.setOnAction(e -> {
            //TODO: version popup
        });

        this.menuDownloadMI = new MenuItem("_Download");
        this.menuDownloadMI.setOnAction(e -> {
            try {
                URL url = new URL("https://www.actionobject.eu/");
                Desktop.getDesktop().browse(url.toURI());
            } catch (IOException | URISyntaxException e2) {

                e2.printStackTrace();
            }
        });
        menuHelp.getItems().addAll(this.menuDownloadMI, this.menuVersionMI);


        menuBar.getMenus().addAll(menuFile, menuEdit, menuModel, menuHelp);


        vBox.getChildren().addAll(menuBar, this.borderPane);


        Scene scene = new Scene(vBox, 1300.0D, 870.0D);
        setScene(scene);
        sizeToScene();


        getIcons().add(C2.applicationImageIconAsICO);


        show();
    }


    public void exportModel() {
        FileChooser fc = new FileChooser();
        fc.setInitialDirectory(new File("/"));
        fc.getExtensionFilters().add(new FileChooser.ExtensionFilter("PNG", "*.png"));
        fc.setTitle("Export Map to png");
        File file = fc.showSaveDialog(this);
        if (file != null) {
            double[] size = this.currentTab.canvas.dssfsdfd43643634();
            WritableImage wi = new WritableImage((int) size[0], (int) size[1]);
            try {
                SnapshotParameters sp = new SnapshotParameters();
                sp.setFill(Paint.valueOf("rgb(27, 27, 30)"));
                ImageIO.write(SwingFXUtils.fromFXImage(this.currentTab.canvas.snapshot(sp, wi), null), "png", file);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }


    public boolean saveModelAs() {
        if (this.currentTab == null || this.currentTab.canvas == null) return false;

        FileChooser fc = new FileChooser();
        fc.setInitialDirectory(new File(System.getProperty("user.home")));

        String tabname = this.currentTab.getText();
        tabname = tabname.replace("*", "");
        fc.setInitialFileName(tabname);
        fc.getExtensionFilters().add(new FileChooser.ExtensionFilter("ERM", "*.erm"));
        fc.setTitle("Save model as ...");
        File file = fc.showSaveDialog(this);
        if (file != null) {
            this.currentTab.canvas.setInitialDirectory(file.getParentFile().getAbsolutePath());
            try {
                ObjectOutputStream wo = new ObjectOutputStream(new FileOutputStream(file));
                wo.writeObject(this.currentTab.canvas.sddsfsfsdf45645645());
                wo.close();

                this.currentTab.canvas.setSaveFile(file);

                String databaseName = file.getName().replace(".erm", "") + "db";
                this.currentTab.canvas.dsfdsfd45645zr().setDatabaseName(databaseName);
                this.currentTab.setText(file.getName());
                return true;
            } catch (IOException e) {


                return false;
            }
        }
        return false;
    }

    public void saveCSScript() throws  ZZ20 {
        if (this.currentTab == null || this.currentTab.canvas == null)
            return;
        FileChooser fc = new FileChooser();
        fc.setInitialDirectory(new File(System.getProperty("user.home")));

        fc.setInitialFileName(this.currentTab.canvas.dsfdsfd45645zr().getDatabaseName());
        fc.getExtensionFilters().add(new FileChooser.ExtensionFilter("*.cs", "*.cs"));
        fc.setTitle("Save cs script as ...");
        final File file = fc.showSaveDialog(this);

        if (file != null) {

            this.progress = new V1(this);

            Thread t = new Thread(() -> {
                FileWriter fw = null;
                try {
                    B3.this.borderPane.setDisable(true);

                    fw = new FileWriter(file);

                    StringBuffer sb = B3.this.currentTab.canvas.dsfdsfd45645zr().create_CS_Script();

                    assert sb != null;
                    fw.write(sb.toString());
                    fw.close();

                } catch (IOException | ZZ20 ex) {

                    try {
                        if (fw != null) fw.close();
                    } catch (IOException ignored) {
                    }
                }

                Platform.runLater(() -> {
                    B3.this.progress.close();
                    B3.this.progress = null;
                });
            });
            this.progress.setThread(t);
            try {
                t.join();
            } catch (InterruptedException ignored) {
            }

            this.borderPane.setDisable(false);
        }


        String databaseName = this.currentTab.getText().replace(".cs", "") + "db";
        this.currentTab.canvas.dsfdsfd45645zr().setDatabaseName(databaseName);
    }
    public void saveSQLScript() throws ZZ20 {
        if (this.currentTab == null || this.currentTab.canvas == null)
            return;
        FileChooser fc = new FileChooser();
        fc.setInitialDirectory(new File(System.getProperty("user.home")));

        LocalDate today = LocalDate.now();
        String currentDate = "";
        if (this.addCurrentDateToDatabaseNameCB.isSelected()) {
            currentDate = today.getYear() + ((today.getMonthValue() < 10) ? ("0" + today.getMonthValue()) : String.valueOf(today.getMonthValue())) + ((today.getDayOfMonth() < 10) ? ("0" + today.getDayOfMonth()) : String.valueOf(today.getDayOfMonth()));
        }
        fc.setInitialFileName(currentDate + this.currentTab.canvas.dsfdsfd45645zr().getDatabaseName());
        fc.getExtensionFilters().add(new FileChooser.ExtensionFilter("*.SQL", "*.sql"));
        fc.setTitle("Save sql script as ...");
        final File file = fc.showSaveDialog(this);

        if (file != null) {

            this.progress = new V1(this);

            Thread t = new Thread(() -> {
                FileWriter fw = null;
                try {
                    B3.this.borderPane.setDisable(true);

                    fw = new FileWriter(file);

                    StringBuffer sb = null;


                    if (B3.this.mySqlStyle.isSelected()) {
                        sb = B3.this.currentTab.canvas.dsfdsfd45645zr().create_MySQL_Script(B3.this.generateInsertsCB.isSelected(),
                                B3.this.addCurrentDateToDatabaseNameCB.isSelected(),
                                B3.this.singleInsertStatementCB.isSelected());
                    } else if (B3.this.msSqlStyle.isSelected()) {
                        sb = B3.this.currentTab.canvas.dsfdsfd45645zr().create_MS_SQL_Script(B3.this.generateInsertsCB.isSelected(),
                                B3.this.addCurrentDateToDatabaseNameCB.isSelected(),
                                B3.this.singleInsertStatementCB.isSelected());
                    }

                    assert sb != null;
                    fw.write(sb.toString());
                    fw.close();
                } catch (IOException | ZZ20 ex) {

                    try {
                        if (fw != null) fw.close();
                    } catch (IOException ignored) {
                    }
                }

                Platform.runLater(() -> {
                    B3.this.progress.close();
                    B3.this.progress = null;
                });
            });
            this.progress.setThread(t);
            try {
                t.join();
            } catch (InterruptedException ignored) {
            }

            this.borderPane.setDisable(false);
        }


        String databaseName = this.currentTab.getText().replace(".erm", "") + "db";
        this.currentTab.canvas.dsfdsfd45645zr().setDatabaseName(databaseName);
    }

    public void saveModel() {
        if (this.currentTab == null || this.currentTab.canvas == null)
            return;
        if (this.currentTab.canvas.getSaveFile() == null) {
            boolean done = saveModelAs();
            if (done) {

                String tabname = this.currentTab.getText();
                tabname = tabname.replace("*", "");
                this.currentTab.setText(tabname);
            }
            return;
        }
        try {
            this.currentTab.canvas.setInitialDirectory(this.currentTab.canvas.getSaveFile().getParentFile().getAbsolutePath());
            ObjectOutputStream wo = new ObjectOutputStream(new FileOutputStream(this.currentTab.canvas.getSaveFile()));
            wo.writeObject(this.currentTab.canvas.sddsfsfsdf45645645());
            wo.close();

            String tabname = this.currentTab.getText();
            tabname = tabname.replace("*", "");
            this.currentTab.setText(tabname);
        } catch (IOException e) {

            e.printStackTrace();
        }
    }


    public void readModel() {
        FileChooser fc = new FileChooser();

        if (this.currentTab != null && this.currentTab.canvas != null && this.currentTab.canvas.getInitialDirectory() != null) {
            fc.setInitialDirectory(new File(this.currentTab.canvas.getSaveFile().getParentFile().getAbsolutePath()));
        } else {
            fc.setInitialDirectory(new File("/"));
        }
        fc.getExtensionFilters().add(new FileChooser.ExtensionFilter("ERM", "*.erm"));
        fc.setTitle("Open model");
        File file = fc.showOpenDialog(this);
        if (file != null) {

            this.graphicElemLV.getItems().clear();

            this.currentTab = addNewTab(file);
            this.currentTab.canvas.setInitialDirectory(file.getParentFile().getAbsolutePath());
            try {
                ObjectInputStream ro = new ObjectInputStream(new FileInputStream(file));
                @SuppressWarnings("unchecked") ArrayList<Graphic_Main_Elem> readModel = (ArrayList<Graphic_Main_Elem>) ro.readObject();


                for (Graphic_Main_Elem gme : readModel) {
                    gme.setGc(this.currentTab.canvas.getGraphicsContext2D());
                    if(gme instanceof Graphic_ATTR_Elem) {
                        if(gme.name.equalsIgnoreCase("id")) {
                            ((Graphic_ATTR_Elem) gme).datatype = "int";
                        }
                    }

                    gme.isVisible = true;
                }

                this.currentTab.canvas.dsfds124332(this.currentTab.canvas.sdfsddf345ersdf());

                this.currentTab.canvas.clearERMDrawCanvas();
                this.currentTab.canvas.safdsadsa65765ewthjk(readModel);
                this.currentTab.canvas.sdfsdfds3465er(true);


                this.currentTab.canvas.setSaveFile(file);
                this.currentTab.setText(file.getName());
                this.tabPane.getSelectionModel().select(this.currentTab);


                this.currentTab.canvas.dsfdsdfssdf45645re();

                ro.close();
            } catch (IOException | ClassNotFoundException e) {

                e.printStackTrace();
            }
        }


        this.selectModeBTN.setSelected(true);
        this.creationModelabel.setStyle("-fx-text-fill:white");
        this.selectModeBTN.setStyle("-fx-text-fill:red");

        this.menuVisibility.setDisable(false);
    }


    public U1 getCurrentTab() {
        return this.currentTab;
    }


    public void setCurrentTab(U1 currentTab) {
        this.currentTab = currentTab;
    }


    public U1 addNewTab(File modelFromFile) {
        int number = this.tabPane.getTabs().size();

        U1 currentTab = new U1(this, "erm" + number + ".erm", modelFromFile);
        this.tabPane.getTabs().add(currentTab);
        return currentTab;
    }


    public ArrayList<Graphic_Main_Elem> getToCopyElements() {
        return this.toCopyElements;
    }


    public void setToCopyElements(ArrayList<Graphic_Main_Elem> toCopyElements) {
        this.toCopyElements = toCopyElements;
    }


    private void setMouseHandler(final Labeled node) {
        node.setOnMouseEntered(event -> {
            B3.this.getScene().getRoot().setCursor(Cursor.HAND);
            if (node.getGraphic() != null)
                T3.asdasda345435ertretr(node.getGraphic(), 1.4D, 1.1D, 0.4D, 0.3D, 0.4D, -0.2D);
            T3.fdssdf4354(node, C2.MouseSelectedColor);
        });

        node.setOnMouseExited(event -> {
            B3.this.getScene().getRoot().setCursor(Cursor.DEFAULT);
            if (node.getGraphic() != null)
                T3.buttonMouseExited(node.getGraphic());
            node.setEffect(null);
        });
    }


}


