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
/*
 * 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.fdxconvert.controller.search;
 
import com.megatimfx.common.annontations.Search;
import com.megatimfx.common.customcontrols.AbstractSelectionItem;
import com.megatimfx.common.enums.Operateur;
import com.megatimfx.components.customdialogs.AlertMessageUtil;
import com.megatimfx.components.customdialogs.LoadinIndicatorDialogUtil;
import com.megatim.fdxconvert.controller.table.TypeFichierTable;
import com.megatim.fdxconvert.enums.DataType;
import com.megatim.fdxconvert.model.TypeFichier;
import com.megatim.fdxconvert.service.TypeFichierService;
import java.net.URL;
import java.util.Arrays;
import java.util.HashSet;
import java.util.ResourceBundle;
import java.util.Set;
import javafx.collections.FXCollections;
import javafx.concurrent.Task;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.ComboBox;
import javafx.util.Pair;
 
/**
 *
 * @author ASUS
 */
public class ConversionModelSearchController implements Initializable {
 
    @FXML
    @Search(fieldName = "typeFichier", operateur = Operateur.EQUALS)
    private AbstractSelectionItem<TypeFichier> typeFichierAbstractSelectItem;
    
    @FXML
    @Search(fieldName = "dataType", operateur = Operateur.EQUALS)
    private ComboBox<DataType> dataTypeComboBox;
    
    private final Set<TypeFichier> typeFichierSet = new HashSet<>();
 
    @Override
    public void initialize(URL location, ResourceBundle resources) {
        
        dataTypeComboBox.setPromptText("Sélectionnez un élément dans la liste");
 
        dataTypeComboBox.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é")
        ));
        
        initElements();
    }
 
    private void initElements() {
        Task<Void> task = new Task() {
            @Override
            protected Object call() throws Exception {
                typeFichierSet.clear();
                typeFichierSet.addAll(TypeFichierService.getInstance().getAll());
 
                return null;
            }
        };
        task.setOnRunning(e -> LoadinIndicatorDialogUtil.getLoadingIndicatorDialog().show());
        task.setOnSucceeded(e -> {
            typeFichierAbstractSelectItem.setElements(typeFichierSet);
            LoadinIndicatorDialogUtil.getLoadingIndicatorDialog().hide();
 
        });
        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();
    }
}