VictorDevCode21 / first_project_edd

First project of the course EDD.
0 stars 0 forks source link

Add validations to Page3 interface in the method removeBranchButton #16

Closed VictorDevCode21 closed 6 hours ago

VictorDevCode21 commented 3 days ago

This can be easily broke if the user introduces something different to the name of the Station that contains the branch, need validations to manage the exceptions that the input could throw

private void removeBranchButtonActionPerformed(java.awt.event.ActionEvent evt) {
// Obtiene el texto ingresado por el usuario String branchName = inputRemoveBranch.getText().trim();

    // Verifica si el texto no está vacío
    if (!branchName.isEmpty()) {
        // Obtiene la referencia a la instancia de NetworkTrain a través de GUI
        NetworkTrain networkTrain = gui.getNetworkTrain();  // Asumo que tienes un método en GUI para obtener el grafo

        // Busca la sucursal en NetworkTrain (el grafo) y la elimina
        Station branchStation = networkTrain.getStationByName(branchName); // Método en NetworkTrain para obtener la estación
        if (branchStation != null) {
            gui.removeBranch(branchStation); // Llama al método removeBranch en GUI para eliminar la sucursal
            displayBranchesList(); // Actualiza la lista en el TextArea
            gui.updateGraph(); // Actualiza el grafo después de eliminar la sucursal
        } else {
            // Si la sucursal no existe, puedes mostrar un mensaje de error o manejar el caso
            System.out.println("Sucursal no encontrada.");
        }
    }
}