/* * 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.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.fdxconvert.controller.table.AlphaNumeriqueFieldTable; import com.megatim.fdxconvert.dao.AlphaNumeriqueFieldDAO; import com.megatim.fdxconvert.model.AlphaNumeriqueField; import com.megatim.fdxconvert.model.TypeFichier; import com.megatim.fdxconvert.service.AlphaNumeriqueFieldService; 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.util.Pair; /** * * @author ASUS */ public class MetaAlphaNumeriqueFieldEditFormController implements Initializable { @FXML @Champ(mappedBy = "alphaNumeriqueField", type = AlphaNumeriqueField.class, update = false) private AbstractSelectionItem alphaNumeriqueFieldAbstractSelectItem; private AlphaNumeriqueFieldService alphaNumeriqueFieldService = AlphaNumeriqueFieldService.getInstance(); private TypeFichier typeFichier; private final Set alphaNumeriqueFieldSet = new HashSet<>(); @Override public void initialize(URL location, ResourceBundle resources) { alphaNumeriqueFieldAbstractSelectItem.setTitle("Choix des colonnes à tronquer"); alphaNumeriqueFieldAbstractSelectItem.setColumns(Arrays.asList( AlphaNumeriqueFieldTable.codeColonneColumn(), AlphaNumeriqueFieldTable.tailleColumn(), AlphaNumeriqueFieldTable.indexColumn() )); alphaNumeriqueFieldAbstractSelectItem.setSearchFieldPairs(Arrays.asList( new Pair<>("codeColonne", "Code du champ"), new Pair<>("taille", "Taille du champ"), new Pair<>("index", "Index du champ") )); initElements(); } private void initElements() { Task task = new Task() { @Override protected Object call() throws Exception { alphaNumeriqueFieldSet.clear(); alphaNumeriqueFieldSet.addAll(AlphaNumeriqueFieldDAO.findByCodeTypeFichier(typeFichier.getCode())); return null; } }; task.setOnRunning(e -> LoadinIndicatorDialogUtil.getLoadingIndicatorDialog().show()); task.setOnSucceeded(e -> { LoadinIndicatorDialogUtil.getLoadingIndicatorDialog().hide(); alphaNumeriqueFieldAbstractSelectItem.setElements(alphaNumeriqueFieldSet); }); 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 TypeFichier getTypeFichier() { return typeFichier; } public void setTypeFichier(TypeFichier typeFichier) { this.typeFichier = typeFichier; } }