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
package com.megatim.fdxgenerator.controller;
 
import com.megatimfx.common.abstracts.AbstractEditDialogController;
import com.megatimfx.common.customdialogs.LoadinIndicatorDialogUtil;
import com.megatimfx.common.dialogs.NotificationDialog;
import com.megatimfx.common.dialogs.NotificationType;
import com.megatimfx.common.enums.TypeOperation;
import com.megatimfx.common.utils.ViewLoaderUtil;
import com.megatim.fdxgenerator.App;
import com.megatim.fdxgenerator.enums.TypeDonnee;
import com.megatim.fdxgenerator.forms.StructureLigneEditFormController;
import com.megatim.fdxgenerator.model.StructureLigne;
import com.megatim.fdxgenerator.model.TypeFichier;
import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.scene.Node;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
 
public class StructureLigneEditDialogController extends AbstractEditDialogController<StructureLigne> {
 
    private StructureLigneEditFormController structureLigneEditFormController;
 
    private ObservableList<StructureLigne> selectedStructureLignes = FXCollections.observableArrayList();
 
    private TypeFichier typeFichier;
 
    @Override
    public void initialize(URL url, ResourceBundle rb) {
        super.initialize(url, rb);
    }
 
    @Override
    public String getTitle() {
        return "Editer une structure de ligne";
    }
 
    @Override
    public Pane getContentFormPane() throws IOException {
        return ViewLoaderUtil.getPaneFromFxmlFile(
                structureLigneEditFormController.getClass().getResource("StructureLigneEditForm.fxml"),
                structureLigneEditFormController
        );
    }
 
    @Override
    public Object getContentFormController() {
        return structureLigneEditFormController;
    }
 
    @Override
    protected void beforeBindFormFieldWithCurrentObject(StructureLigne bindObject, Object formController, TypeOperation typeOperation) {
 
        if (formController instanceof StructureLigneEditFormController) {
 
            if (typeOperation.equals(TypeOperation.UPDATE) || typeOperation.equals(TypeOperation.VIEW)) {
                
                if (bindObject.getTypeDonnee().equals(TypeDonnee.DATE) && App.SEPARATEURS_DATE.containsKey(bindObject.getSeparateurDate())) {
                   
                    bindObject.setDelimiteurDate(App.SEPARATEURS_DATE.get(bindObject.getSeparateurDate()));
                }
                if (bindObject.getTypeDonnee().equals(TypeDonnee.DECIMAL) && App.SEPARATEURS_DECIMAUX.containsKey(bindObject.getSeparateurDecimal())) {
                   
                    bindObject.setDelimiteurDecimal(App.SEPARATEURS_DECIMAUX.get(bindObject.getSeparateurDecimal()));
                }
            }
 
        }
    }
 
    @Override
    public boolean beforeSave(ActionEvent event) {
        Boolean proceed = super.beforeSave(event);
        StringBuilder message = new StringBuilder(0);
 
        if (proceed) {
 
            if (getCurrentObject().getTypeDonnee().equals(TypeDonnee.DATE)) {
 
                boolean proceed1 = getCurrentObject().getFormatDate() != null
                        && getCurrentObject().getTaille() == getCurrentObject().getFormatDate().length();
 
                proceed = proceed && proceed1;
 
                if (!proceed1) {
                    message.append("Le format de la date est obligatoire et sa taille doit être égale à la taille du champ\n");
                }
 
                boolean proceedSeparateurDate = getCurrentObject().getDelimiteurDate() != null;
                proceed = proceed && proceedSeparateurDate;
 
                if (proceedSeparateurDate) {
                    getCurrentObject().setSeparateurDate(getCurrentObject().getDelimiteurDate().getCode());
                } else {
                    message.append("Le séparateur de date est obligatoire\n");
                }
 
            }
 
            if (getCurrentObject().getTypeDonnee().equals(TypeDonnee.DECIMAL)) {
 
                boolean proceedSeparateurDecimal = getCurrentObject().getDelimiteurDecimal() != null;
                proceed = proceed && proceedSeparateurDecimal;
 
                if (proceedSeparateurDecimal) {
                    getCurrentObject().setSeparateurDecimal(getCurrentObject().getDelimiteurDecimal().getCode());
                } else {
                    message.append("Le séparateur de décimal est obligatoire\n");
                }
 
                boolean proceedTailleDecimal = getCurrentObject().getTaillePartieDecimal() > 1;
                proceed = proceed && proceedTailleDecimal;
 
                if (!proceedTailleDecimal) {
                    message.append("La taille de la partie entière doit être supérieure à 0");
                }
            }
        }
 
        if (!proceed && !message.toString().isEmpty()) {
 
            LoadinIndicatorDialogUtil.getLoadingIndicatorDialog().hide();
            Node source = (Node) event.getSource();
            Stage parentStage = (Stage) source.getScene().getWindow();
            NotificationDialog notificationDialog = new NotificationDialog(
                    message.toString(),
                    NotificationType.ERROR,
                    parentStage
            );
 
            notificationDialog.showNotification();
        }
 
        return proceed;
    }
 
    @Override
    protected void afterBindCurrentObjectWithFormField(StructureLigne bindObject, Object formController, TypeOperation typeOperation) {
        if (formController instanceof StructureLigneEditFormController) {
            if (typeFichier != null) {
                bindObject.setId(typeFichier + "" + bindObject.getPosition());
            }
        }
    }
 
    public StructureLigneEditFormController getStructureLigneEditFormController() {
        return structureLigneEditFormController;
    }
 
    public void setStructureLigneEditFormController(StructureLigneEditFormController structureLigneEditFormController) {
        this.structureLigneEditFormController = structureLigneEditFormController;
    }
 
    public void setTypeFichier(TypeFichier typeFichier) {
        this.typeFichier = typeFichier;
    }
 
    public void setSelectedStructureLignes(ObservableList<StructureLigne> selectedStructureLignes) {
        this.selectedStructureLignes = selectedStructureLignes;
    }
 
    @Override
    public void afterSave(ActionEvent event, Object formController, TypeOperation typeOperation) {
 
        StructureLigneEditFormController controller = (StructureLigneEditFormController) formController;
 
        if (getTypeOperation().equals(TypeOperation.UPDATE)) {
 
            boolean exists = false;
 
            ObservableList<Integer> liste = controller.getList();
 
            for (Integer i : liste) {
 
                if (i.equals(controller.getInitialUpdateSelection())) {
 
                    exists = true;
 
                    break;
                }
            }
 
            if (!exists) {
 
                liste.add(controller.getInitialUpdateSelection());
            }
        }
    }
 
    @Override
    protected void afterBindFormFieldWithCurrentObject(StructureLigne bindObject, Object formController, TypeOperation typeOperation) {
        StructureLigneEditFormController controller = (StructureLigneEditFormController) formController;
 
        if (typeOperation.equals(TypeOperation.UPDATE)) {
            controller.setInitialUpateSelection();
 
        }
    }
 
}