/* * 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.AbstractNestedEntityTable; import com.megatimfx.common.customcontrols.AbstractSelectionItem; import com.megatimfx.common.customcontrols.CustomDirectoryChooser; import com.megatimfx.components.customdialogs.AlertMessageUtil; import com.megatimfx.components.customdialogs.LoadinIndicatorDialogUtil; import com.megatim.fdxconvert.App; import com.megatim.fdxconvert.controller.table.MetaAlphaNumeriqueTable; import com.megatim.fdxconvert.controller.table.TypeFichierTable; import com.megatim.fdxconvert.enums.DataType; import com.megatim.fdxconvert.model.ConversionModel; import com.megatim.fdxconvert.pojo.Delimiteur; import com.megatim.fdxconvert.model.MetaAlphaNumeriqueField; import com.megatim.fdxconvert.model.TypeFichier; import com.megatim.fdxconvert.service.MetaAlphaNumeriqueFieldService; 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.CheckBox; import javafx.scene.control.ComboBox; import javafx.scene.control.TabPane; import javafx.scene.control.TextField; import javafx.util.Pair; /** * * @author ASUS */ public class ConversionModelEditFormController implements Initializable { @FXML @Champ(mappedBy = "typeFichier", type = TypeFichier.class, update = false) private AbstractSelectionItem typeFichierAbstractSelectItem; @FXML @Champ(mappedBy = "delimiteurLigne", type = Delimiteur.class) private ComboBox delimiteurLigne; @FXML @Champ(mappedBy = "delimiteurColonne", type = Delimiteur.class) private ComboBox delimiteurColonne; @FXML @Champ(mappedBy = "dataType", type = DataType.class) private ComboBox dataTypeComboBox; @FXML @Champ(mappedBy = "repertoireSource") private CustomDirectoryChooser repertoireSource; @FXML @Champ(mappedBy = "repertoireDestination") private CustomDirectoryChooser repertoireDestination; @FXML @Champ(mappedBy = "repertoireErreur") private CustomDirectoryChooser repertoireErreur; @FXML @Champ(mappedBy = "strictValidation", type = Boolean.class) private CheckBox strictValidationCheckbox; @FXML @Champ(mappedBy = "headerPresent", type = Boolean.class) private CheckBox headerPresentCheckbox; @FXML private CheckBox saisieAlphaNumeriqueFieldChecBox; @FXML @Champ(mappedBy = "libelle") private TextField libelleTextField; @FXML @Champ(mappedBy = "metaAlphaNumeriqueFields", type = MetaAlphaNumeriqueField.class, update = true) private AbstractNestedEntityTable metaAlphaNumeriqueFieldAbstractTable; @FXML private TabPane tabPane; private final MetaAlphaNumeriqueFieldService metaAlphaNumeriqueFieldService = MetaAlphaNumeriqueFieldService.getInstance(); private final Set typeFichierSet = new HashSet<>(); @Override public void initialize(URL location, ResourceBundle resources) { tabPane.setTabClosingPolicy(TabPane.TabClosingPolicy.UNAVAILABLE); metaAlphaNumeriqueFieldAbstractTable.setParentFieldName("configurationConversion"); saisieAlphaNumeriqueFieldChecBox.setDisable(true); metaAlphaNumeriqueFieldAbstractTable.setDisable(true); delimiteurColonne.setPromptText("Sélectionnez un élément dans la liste"); delimiteurColonne.setItems(FXCollections.observableArrayList( App.DELIMITEURS_COLONNE.values() )); delimiteurLigne.setPromptText("Sélectionnez un élément dans la liste"); delimiteurLigne.setItems(FXCollections.observableArrayList( App.DELIMITEURS_LIGNE.values() )); 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é") )); metaAlphaNumeriqueFieldAbstractTable.setClazz(MetaAlphaNumeriqueField.class); metaAlphaNumeriqueFieldAbstractTable.setColums(Arrays.asList( MetaAlphaNumeriqueTable.typeFichierColumn(),MetaAlphaNumeriqueTable.typeDonneeColumn(), MetaAlphaNumeriqueTable.codeColonneColumn(), MetaAlphaNumeriqueTable.tailleColonneColumn(), MetaAlphaNumeriqueTable.indexColonneColumn() )); metaAlphaNumeriqueFieldAbstractTable.setGenericCrudService(metaAlphaNumeriqueFieldService); saisieAlphaNumeriqueFieldChecBox.selectedProperty().addListener((observable, oldValue, newValue) -> { if (newValue) { typeFichierAbstractSelectItem.setDisable(true); saisieAlphaNumeriqueFieldChecBox.setDisable(true); } }); typeFichierAbstractSelectItem.selectedElementProperty().addListener((observable, oldValue, newValue) -> { if (newValue != null) { saisieAlphaNumeriqueFieldChecBox.setDisable(typeFichierAbstractSelectItem == null); } }); initElements(); } 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 -> { 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(); } public AbstractSelectionItem getTypeFichierAbstractSelectItem() { return typeFichierAbstractSelectItem; } public CheckBox getSaisieAlphaNumeriqueFieldChecBox() { return saisieAlphaNumeriqueFieldChecBox; } public AbstractNestedEntityTable getMetaAlphaNumeriqueFieldAbstractTable() { return metaAlphaNumeriqueFieldAbstractTable; } public CheckBox getStrictValidationCheckbox() { return strictValidationCheckbox; } public ComboBox getDelimiteurLigne() { return delimiteurLigne; } public ComboBox getDelimiteurColonne() { return delimiteurColonne; } public ComboBox getDataTypeComboBox() { return dataTypeComboBox; } public CheckBox getHeaderPresentCheckbox() { return headerPresentCheckbox; } }