/* * 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; import com.megatimfx.common.abstracts.AbstractEditDialogController; import com.megatimfx.common.utils.ViewLoaderUtil; import com.megatimfx.components.dialogs.NotificationDialog; import com.megatimfx.components.dialogs.NotificationType; import com.megatim.fdxconvert.forms.MetaAlphaNumeriqueFieldEditFormController; import com.megatim.fdxconvert.model.AlphaNumeriqueField; import com.megatim.fdxconvert.model.MetaAlphaNumeriqueField; import java.io.IOException; import java.net.URL; import java.util.HashMap; import java.util.Map; import java.util.ResourceBundle; import javafx.event.ActionEvent; import javafx.scene.Node; import javafx.scene.layout.Pane; import javafx.stage.Stage; /** * * @author ASUS */ public class MetaAlphaNumeriqueFieldEditDialogController extends AbstractEditDialogController { private MetaAlphaNumeriqueFieldEditFormController alphaNumeriqueFieldEditFormController; //Map qui garde la trace des éléments déjà selectionnés private Map toBeTruncated = new HashMap<>(); @Override public void initialize(URL url, ResourceBundle rb) { super.initialize(url, rb); } @Override public String getTitle() { return "Choisir le champ à tronquer"; } @Override public Pane getContentFormPane() throws IOException { return ViewLoaderUtil.getPaneFromFxmlFile( alphaNumeriqueFieldEditFormController.getClass().getResource("AlphaNumeriqueFieldEditForm.fxml"), alphaNumeriqueFieldEditFormController ); } public MetaAlphaNumeriqueFieldEditFormController getAlphaNumeriqueFieldEditFormController() { return alphaNumeriqueFieldEditFormController; } @Override public boolean beforeSave(ActionEvent event) { boolean proceed = super.beforeSave(event); AlphaNumeriqueField currentAlpha = getCurrentObject().getAlphaNumeriqueField(); if (!toBeTruncated.containsKey(currentAlpha.getCodeColonne())) { toBeTruncated.put(currentAlpha.getCodeColonne(), currentAlpha); } else { proceed = false; Node source = (Node) event.getSource(); Stage parentStage = (Stage) source.getScene().getWindow(); NotificationDialog notificationDialog = new NotificationDialog("La colonne "+currentAlpha.getCodeColonne()+" a déjà été ajouté à la liste " , NotificationType.ERROR, parentStage); notificationDialog.showNotification(); } return proceed; } @Override public Object getContentFormController() { return alphaNumeriqueFieldEditFormController; } public void setAlphaNumeriqueFieldEditFormController(MetaAlphaNumeriqueFieldEditFormController alphaNumeriqueFieldEditFormController) { this.alphaNumeriqueFieldEditFormController = alphaNumeriqueFieldEditFormController; } }