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.common.customdialogs.LoadinIndicatorDialogUtil; import com.megatimfx.components.customdialogs.AlertMessageUtil; import com.megatim.fdxconvert.App; import com.megatim.fdxconvert.controller.table.ConversionModelTable; 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.Tache; import com.megatim.fdxconvert.model.TypeFichier; import com.megatim.fdxconvert.service.ConversionModelService; 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.beans.value.ObservableValue; 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.TabPane.TabClosingPolicy; import javafx.scene.control.TextField; import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; import javafx.util.Pair; /** * * @author MGT_DEV3 */ public class TacheEditFormController implements Initializable { @FXML private VBox paneContainer; @FXML private HBox sourceHBox; @FXML private HBox destinationHBox; @FXML private AbstractSelectionItem conversionModelAbstractSelectItem; @FXML @Champ(mappedBy = "patternSuppression") private TextField patternSuppression; @FXML @Champ(mappedBy = "repertoireSource") private CustomDirectoryChooser repertoireSource; @FXML @Champ(mappedBy = "repertoireDestination") private CustomDirectoryChooser repertoireDestination; @FXML @Champ(mappedBy = "repertoireErreur") private CustomDirectoryChooser repertoireErreur; //OLD ELEMENTS @Champ(mappedBy = "libelle", type = String.class, update = false) @FXML private TextField libelleTextField; @FXML @Champ(mappedBy = "heureTache", type = Integer.class) private TextField heureTextField; @FXML @Champ(mappedBy = "minuteTache", type = Integer.class) private TextField minuteTextField; @Champ(mappedBy = "monday", type = Boolean.class) @FXML private CheckBox lundiCheckbox; @Champ(mappedBy = "tuesday", type = Boolean.class) @FXML private CheckBox mardiCheckbox; @Champ(mappedBy = "wednesday", type = Boolean.class) @FXML private CheckBox mercrediCheckbox; @Champ(mappedBy = "thursday", type = Boolean.class) @FXML private CheckBox jeudiCheckbox; @Champ(mappedBy = "friday", type = Boolean.class) @FXML private CheckBox vendrediCheckbox; @Champ(mappedBy = "saturday", type = Boolean.class) @FXML private CheckBox samediCheckbox; @Champ(mappedBy = "sunday", type = Boolean.class) @FXML private CheckBox dimancheCheckbox; @FXML @Champ(mappedBy = "strictValidation", type = Boolean.class) private CheckBox strictValidationCheckbox; @FXML private CheckBox useExistingConversionModelCheckBox; @Champ(mappedBy = "typeFichier", type = TypeFichier.class) @FXML 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 = "withHeader", type = Boolean.class) private CheckBox withHeader; @FXML @Champ(mappedBy = "active", type = Boolean.class) private CheckBox active; @FXML @Champ(mappedBy = "dataType", type = DataType.class) private ComboBox dataTypeComboBox; @FXML @Champ(mappedBy = "withoutInterval", type = Boolean.class) private CheckBox withoutInterval; @FXML @Champ(mappedBy = "intervalleTache", type = Integer.class) private TextField intervalleTache; @FXML private CheckBox saisieAlphaNumeriqueFieldChecBox; @FXML @Champ(mappedBy = "metaAlphaNumeriqueFields", type = MetaAlphaNumeriqueField.class, update = true) private AbstractNestedEntityTable metaAlphaNumeriqueFieldAbstractTable; @FXML private TabPane tabPane; private MetaAlphaNumeriqueFieldService metaAlphaNumeriqueFieldService = MetaAlphaNumeriqueFieldService.getInstance(); private Set TypeFichierSet = new HashSet<>(); private Set configurationConversionSet = new HashSet<>(); /** * Initializes the controller class. */ @Override public void initialize(URL url, ResourceBundle rb) { tabPane.setTabClosingPolicy(TabClosingPolicy.UNAVAILABLE); saisieAlphaNumeriqueFieldChecBox.setDisable(true); withoutInterval.setOnAction(e -> { if (withoutInterval.isSelected()) { intervalleTache.setDisable(true); } else { intervalleTache.setDisable(false); } }); intervalleTache.disableProperty().bind(withoutInterval.selectedProperty()); intervalleTache.textProperty().addListener((observable, oldValue, newValue) -> { if (!newValue.matches("\\d+") || (Integer.parseInt(newValue) > 59) || (Integer.parseInt(newValue) < 0)) { heureTextField.setText(oldValue); } }); heureTextField.textProperty().addListener((observable, oldValue, newValue) -> { if (!newValue.matches("\\d*") || (Integer.parseInt(newValue) > 23) || (Integer.parseInt(newValue) < 0)) { heureTextField.setText(oldValue); } }); minuteTextField.textProperty().addListener((ObservableValue observable, String oldValue, String newValue) -> { if (!newValue.matches("\\d*") || (Integer.parseInt(newValue) > 59) || (Integer.parseInt(newValue) < 0)) { minuteTextField.setText(oldValue); } }); 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() )); metaAlphaNumeriqueFieldAbstractTable.setClazz(MetaAlphaNumeriqueField.class); metaAlphaNumeriqueFieldAbstractTable.setParentFieldName("tache"); metaAlphaNumeriqueFieldAbstractTable.setColums(Arrays.asList( MetaAlphaNumeriqueTable.codeColonneColumn(), MetaAlphaNumeriqueTable.tailleColonneColumn(), MetaAlphaNumeriqueTable.indexColonneColumn() )); metaAlphaNumeriqueFieldAbstractTable.setGenericCrudService(metaAlphaNumeriqueFieldService); saisieAlphaNumeriqueFieldChecBox.setOnAction(event -> { typeFichierAbstractSelectItem.setDisable(saisieAlphaNumeriqueFieldChecBox.isSelected()); }); 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); } }); conversionModelAbstractSelectItem.disableProperty().bind(useExistingConversionModelCheckBox.selectedProperty().not()); intitTypeFichiers(); initConversionModel(); } public void intitTypeFichiers() { typeFichierAbstractSelectItem.setTitle("Choix du type de fichier de la tâche"); typeFichierAbstractSelectItem.setColumns(Arrays.asList( TypeFichierTable.codeColumn(), TypeFichierTable.libelleColumn(), TypeFichierTable.participantColumn() )); typeFichierAbstractSelectItem.setSearchFieldPairs(Arrays.asList( new Pair<>("code", "Code"), new Pair<>("libelle", "Libellé") )); 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 -> { LoadinIndicatorDialogUtil.getLoadingIndicatorDialog().hide(); typeFichierAbstractSelectItem.setElements(TypeFichierSet); }); 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 CheckBox getSaisieAlphaNumeriqueFieldChecBox() { return saisieAlphaNumeriqueFieldChecBox; } public AbstractSelectionItem getTypeFichierAbstractSelectItem() { return typeFichierAbstractSelectItem; } 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 getUseExistingConversionModelCheckBox() { return useExistingConversionModelCheckBox; } public CheckBox getWithHeader() { return withHeader; } private void initConversionModel() { conversionModelAbstractSelectItem.setTitle("Choix du modèle de conversion"); conversionModelAbstractSelectItem.setColumns(Arrays.asList(ConversionModelTable.typeFichierColumn(), ConversionModelTable.dataTypeColumn(), ConversionModelTable.delimiteurLigneColumn(), ConversionModelTable.delimiteurColonneColumn(), ConversionModelTable.repertoireSourceColumn(), ConversionModelTable.repertoireDestinationColumn(), ConversionModelTable.repertoireErreurColumn() )); conversionModelAbstractSelectItem.setSearchFieldPairs(Arrays.asList( new Pair<>("delimiteurLigne", "Délimiteur Ligne"), new Pair<>("delimiteurColonne", "Délimiteur Colonne") )); conversionModelAbstractSelectItem.selectedElementProperty().addListener((observable, oldValue, newValue) -> { if (newValue != null) { dataTypeComboBox.setValue(newValue.getDataType()); if (newValue.getCodeDelimiteurColonne() != null) { delimiteurColonne.setValue(App.DELIMITEURS_COLONNE.get(newValue.getCodeDelimiteurColonne())); } if (newValue.getCodeDelimiteurLigne() != null) { delimiteurLigne.setValue(App.DELIMITEURS_LIGNE.get(newValue.getCodeDelimiteurLigne())); } strictValidationCheckbox.setSelected(newValue.isStrictValidation()); withHeader.setSelected(newValue.isHeaderPresent()); typeFichierAbstractSelectItem.setOldElement(newValue.getTypeFichier()); repertoireDestination.setDirectoryLocation(newValue.getRepertoireDestination()); repertoireErreur.setDirectoryLocation(newValue.getRepertoireErreur()); repertoireSource.setDirectoryLocation(newValue.getRepertoireSource()); //MetaAlalphanumériqueField provenant de la BD Set metasFromBd = newValue.getMetaAlphaNumeriqueFields(); metasFromBd.stream().forEach(m -> { //Création de nouveaux MetaAlalphanumériqueField avec uniquement le champ alphaNumerique metaAlphaNumeriqueFieldAbstractTable.getElementObservableList().add(new MetaAlphaNumeriqueField(m.getAlphaNumeriqueField())); }); } }); Task task1 = new Task() { @Override protected Object call() throws Exception { configurationConversionSet.clear(); configurationConversionSet.addAll(ConversionModelService.getInstance().getAll()); return null; } }; task1.setOnRunning(e -> com.megatimfx.components.customdialogs.LoadinIndicatorDialogUtil.getLoadingIndicatorDialog().show()); task1.setOnSucceeded(e -> { conversionModelAbstractSelectItem.setElements(configurationConversionSet); com.megatimfx.components.customdialogs.LoadinIndicatorDialogUtil.getLoadingIndicatorDialog().hide(); }); task1.setOnFailed(e -> { com.megatimfx.components.customdialogs.LoadinIndicatorDialogUtil.getLoadingIndicatorDialog().hide(); AlertMessageUtil.showAlertException(task1.getException(), "Une exception s'est produite pendant le traitement", "Erreur"); }); Thread thread1 = new Thread(task1); thread1.setDaemon(true); thread1.start(); } }