/* * 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.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.concurrent.Task; import javafx.fxml.FXML; import javafx.fxml.Initializable; import javafx.scene.control.TextField; import javafx.util.Pair; /** * * @author ASUS */ public class JournalSearchFormController implements Initializable { @Search(fieldName = "codeTypefichier", operateur = Operateur.LIKE) @FXML private TextField typeFichierTextField; @FXML private AbstractSelectionItem typeFichierAbstractSelectionItem; private final Set typeFichierSet = new HashSet<>(); @Override public void initialize(URL url, ResourceBundle rb) { typeFichierAbstractSelectionItem.setTitle("Choix du type de fichier"); typeFichierAbstractSelectionItem.setColumns(Arrays.asList( TypeFichierTable.codeColumn(), TypeFichierTable.libelleColumn() )); typeFichierAbstractSelectionItem.setSearchFieldPairs(Arrays.asList( new Pair<>("code", "Code"), new Pair<>("libelle", "Libellé") )); typeFichierAbstractSelectionItem.selectedElementProperty().addListener((observable, oldValue, newValue) -> { if (newValue == null) { typeFichierTextField.setText(""); } else { typeFichierTextField.setText(newValue.getCode()); } }); initElements(); } public AbstractSelectionItem getTypeFichierAbstractSelectionItem() { return typeFichierAbstractSelectionItem; } private void initElements() { Task 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 -> { typeFichierAbstractSelectionItem.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(); } }