Kenmegne
7 days ago 494d349fb67be74da49caae2794fda702f595fb4
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
 */
package com.megatim.fdxgenerator.forms;
 
import com.megatimfx.common.annontations.Champ;
import com.megatimfx.common.customcontrols.AbstractSelectionItem;
import com.megatimfx.components.customdialogs.AlertMessageUtil;
import com.megatimfx.components.customdialogs.LoadinIndicatorDialogUtil;
import com.megatim.fdxgenerator.controller.table.TypeFichierTable;
import com.megatim.fdxgenerator.enums.DataType;
import com.megatim.fdxgenerator.model.TypeFichier;
import com.megatim.fdxgenerator.service.TypeFichierService;
import java.net.URL;
import java.util.Arrays;
import java.util.HashSet;
import java.util.ResourceBundle;
import java.util.Set;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.concurrent.Task;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.CheckBox;
import javafx.scene.control.ComboBox;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import javafx.scene.control.TitledPane;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent;
import javafx.util.Pair;
 
/**
 *
 * @author STEPHANIE
 */
public class FichierValidationEditFormController implements Initializable {
 
    @FXML
    @Champ(mappedBy = "typeFichier", type = TypeFichier.class, update = false)
    private AbstractSelectionItem<TypeFichier> typeFichierAbstractSelectItem;
 
    @FXML
    private TextField showKeyToEncrypt;
 
    @FXML
    @Champ(mappedBy = "formatDate")
    private ComboBox<String> formatDate;
 
//    @FXML
//    @Champ(mappedBy = "extension")
//    private ComboBox<DataType> extensionFichier;
 
    @FXML
    @Champ(mappedBy = "maxValueTierce", type = Integer.class)
    private TextField MaxValueTierceTextField;
 
    @FXML
    @Champ(mappedBy = "protege", type = Boolean.class)
    private CheckBox isProtegeCheckBox;
 
    @FXML
    @Champ(mappedBy = "validateFileName", type = Boolean.class)
    private CheckBox validateFileNameCheckBox;
 
    @FXML
    private TitledPane fileNameTitledPane;
 
    @FXML
    private ImageView imageView;
 
    @FXML
    @Champ(mappedBy = "keyToEncrypt")
    private PasswordField keyToEncryptField;
 
    @FXML
    @Champ(mappedBy = "keyConfirmation")
    private PasswordField keyConfirmationField;
 
    private final TypeFichierService typeFichierService = TypeFichierService.getInstance();
 
    //ELEMENTS DE CHARGEMENT
    private final Set<TypeFichier> typeFichierSet = new HashSet<>();
 
    private boolean passwordVisible;
 
    @Override
    public void initialize(URL location, ResourceBundle resources) {
        keyToEncryptField.setDisable(true);
        keyConfirmationField.setDisable(true);
        showKeyToEncrypt.setDisable(true);
        fileNameTitledPane.setDisable(true);
        
        keyToDecryptWithEye();
 
        formatDate.setPromptText("Selectionnez un format");
        formatDate.setItems(FXCollections.observableArrayList(
                "yyyyMMddHHmmss", "yyyyMMdd",
                "yyyyddMMHHmmss", "yyyyddMM",
                "MMyyyyddHHmmss", "MMyyyydd",
                "MMddyyyHHmmss", "MMddyyy"
        ));
//        extensionFichier.setPromptText("Selectionnez un format");
//        extensionFichier.setItems(FXCollections.observableArrayList(
//                DataType.values()
//        ));
        typeFichierAbstractSelectItem.setTitle("Choix du type de fichier");
        typeFichierAbstractSelectItem.setColumns(Arrays.asList(
                TypeFichierTable.codeColumn(),
                TypeFichierTable.libelleColumn()
        ));
        typeFichierAbstractSelectItem.setSearchFieldPairs(Arrays.asList(
                new Pair<>("code", "Code"),
                new Pair<>("libelle", "LibellĂ©")
        ));
 
        MaxValueTierceTextField.textProperty().addListener((ObservableValue<? extends String> observable, String oldValue, String newValue) -> {
            if (!newValue.matches("\\d{1,9}")) {
                MaxValueTierceTextField.setText(newValue.replaceAll("[^\\d]", ""));
            }
        });
 
        isProtegeCheckBox.selectedProperty().addListener(l -> {
            if (isProtegeCheckBox.isSelected()) {
                keyToEncryptField.setDisable(false);
                keyConfirmationField.setDisable(false);
                showKeyToEncrypt.setDisable(false);
            }
 
            if (!isProtegeCheckBox.isSelected()) {
                keyToEncryptField.setDisable(true);
                keyConfirmationField.setDisable(true);
                showKeyToEncrypt.setDisable(true);
            }
        });
        
        validateFileNameCheckBox.selectedProperty().addListener(l -> {
            
            if (validateFileNameCheckBox.isSelected()) {
                fileNameTitledPane.setDisable(false);
            }
 
            if (!validateFileNameCheckBox.isSelected()) {
                fileNameTitledPane.setDisable(true);
            }
        });
        
        initElements();
    }
 
    private void initElements() {
        Task<Void> task = new Task() {
            @Override
            protected Object call() throws Exception {
                typeFichierSet.clear();
                typeFichierSet.addAll(typeFichierService.getAllTypeFichWithValidateur());
                return null;
            }
        };
        task.setOnRunning(e -> LoadinIndicatorDialogUtil.getLoadingIndicatorDialog().show());
        task.setOnSucceeded(e -> {
            LoadinIndicatorDialogUtil.getLoadingIndicatorDialog().hide();
            typeFichierAbstractSelectItem.setElements(typeFichierSet);
        });
        task.setOnFailed(e -> {
            LoadinIndicatorDialogUtil.getLoadingIndicatorDialog().hide();
            AlertMessageUtil.showAlertException(task.getException(),
                    "Une exception s'est produite pendant le traitement", "Erreur");
        });
        Thread thread = new Thread(task);
        thread.setDaemon(true);
        thread.start();
    }
 
    public AbstractSelectionItem<TypeFichier> getTypeFichierAbstractSelectItem() {
        return typeFichierAbstractSelectItem;
    }
 
    public void setTypeFichierAbstractSelectItem(AbstractSelectionItem<TypeFichier> typeFichierAbstractSelectItem) {
        this.typeFichierAbstractSelectItem = typeFichierAbstractSelectItem;
    }
 
    public CheckBox getIsProtegeCheckBox() {
        return isProtegeCheckBox;
    }
 
    public PasswordField getKeyToEncryptField() {
        return keyToEncryptField;
    }
 
    public PasswordField getKeyConfirmationField() {
        return keyConfirmationField;
    }
 
    @FXML
    void eyeOnMousePressed(MouseEvent event) {
        if (passwordVisible) {
            showKeyToEncrypt.setVisible(false);
            keyToEncryptField.setVisible(true);
            passwordVisible = false;
        } else {
            keyToEncryptField.setVisible(false);
            showKeyToEncrypt.setVisible(true);
            passwordVisible = true;
        }
    }
 
    private void keyToDecryptWithEye() {
        passwordVisible = false;
        keyToEncryptField.textProperty().bindBidirectional(showKeyToEncrypt.textProperty());
        showKeyToEncrypt.setVisible(false);
        keyToEncryptField.setVisible(true);
    }
 
}