Kenmegne
7 days ago b3d0580439b9a00c7eb918085de1694151066004
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
package com.megatim.fdxconvert.views;
 
import com.megatim.fdxconvert.model.TypeFichierJson;
import com.megatim.fdxconvert.viewmodel.JsonStructureTableViewModel;
import javafx.beans.property.SimpleStringProperty;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Modality;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
 
import java.io.IOException;
import java.net.URL;
import java.util.Arrays;
import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.Logger;
 
public class JsonStructureTableViewController implements Initializable {
 
    @FXML
    private BorderPane searchPane;
 
    @FXML
    private Button btnSearch;
 
    @FXML
    private Button btnReset;
 
    @FXML
    private CheckBox advancedCheckBox;
 
    @FXML
    private VBox normalSearchContainer;
 
    @FXML
    private VBox advancedSearchContainer;
 
    @FXML
    private HBox buttonContainer;
 
    @FXML
    private Button btnAdd;
 
    @FXML
    private Button btnEdit;
 
    @FXML
    private Button btnDelete;
 
    @FXML
    private TableView<TypeFichierJson> elementTable;
 
    @FXML
    private Button btnPrevious;
 
    @FXML
    private Button btnNext;
 
    @FXML
    private Label paginationNumberInfo;
 
    @FXML
    private Button btnClose;
 
    private final JsonStructureTableViewModel viewModel = new JsonStructureTableViewModel();
 
    @Override
    public void initialize(URL location, ResourceBundle resources) {
 
        viewModel.init();
 
        initTable();
 
        btnNext.setOnAction(event -> viewModel.nextPage());
        btnPrevious.setOnAction(event -> viewModel.previousPage());
        btnAdd.setOnAction(event -> openFormDialog(null));
        btnEdit.setOnAction(event ->  viewModel.loadSelectedItemChildren(selectedItem -> openFormDialog(selectedItem)));
        btnDelete.setOnAction(event -> viewModel.deleteSelectedItem());
 
        viewModel.selectedItemProperty().bind(elementTable.getSelectionModel().selectedItemProperty());
 
        paginationNumberInfo.textProperty().bind(viewModel.getPaginationNumberInfo());
        btnEdit.disableProperty().bind(elementTable.getSelectionModel().selectedItemProperty().isNull());
        btnDelete.disableProperty().bind(elementTable.getSelectionModel().selectedItemProperty().isNull());
        btnNext.disableProperty().bind(viewModel.getLastProperty());
        btnPrevious.disableProperty().bind(viewModel.getFirstProperty());
 
    }
 
    private void initTable() {
 
        TableColumn<TypeFichierJson, String> codeTypeFichierColumn = new TableColumn("Code type fichier");
        codeTypeFichierColumn.setCellValueFactory(c -> {
            return new SimpleStringProperty(c.getValue().getTypeFichier() != null ? c.getValue().getTypeFichier().getCode() : "");
        });
 
        TableColumn<TypeFichierJson, String> libelleTypeFichierColumn = new TableColumn("LibellĂ© type fichier");
        libelleTypeFichierColumn.setCellValueFactory(c -> {
            return new SimpleStringProperty(c.getValue().getTypeFichier() != null ? c.getValue().getTypeFichier().getLibelle() : "");
        });
 
        elementTable.getColumns().addAll(Arrays.asList(codeTypeFichierColumn, libelleTypeFichierColumn));
 
        this.elementTable.setPlaceholder(new Label("Pas de donnĂ©es"));
 
        elementTable.setItems(viewModel.getData());
    }
 
    @FXML
    public void close(ActionEvent event) {
        ((Stage) elementTable.getScene().getWindow()).close();
    }
 
    @FXML
    public void maximize(ActionEvent event) {
    }
 
    @FXML
    public void minimize(ActionEvent event) {
    }
 
    @FXML
    public void mouseDraggedTitleBar(MouseEvent event) {
    }
 
    @FXML
    public void mousePressedTitleBar(MouseEvent event) {
    }
 
    private void openFormDialog(TypeFichierJson typeFichierJson) {
        try {
            JsonStructureFormController jsonStructureFormController = new JsonStructureFormController(typeFichierJson);
            FXMLLoader loader = new FXMLLoader(JsonStructureFormController.class.getResource("JsonStructureFormView.fxml"));
            loader.setController(jsonStructureFormController);
            Parent root = loader.load();
            setStage(root);
 
            jsonStructureFormController.resultProperty().addListener((observable, oldValue, newValue) -> {
                viewModel.reloadData();
            });
 
        } catch (IOException ex) {
            Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, ex.getMessage(), ex);
        }
    }
 
    private void setStage(Parent root) {
        Scene scene = new Scene(root);
        Stage stage = new Stage();
 
        stage.setScene(scene);
        stage.initStyle(StageStyle.UNDECORATED);
        stage.initModality(Modality.APPLICATION_MODAL);
        stage.show();
    }
 
}