Very good.
I have a method that checks if all TextField is complete and that it returns a boolean based on that. My idea is that I want to use this method in several classes to do it with different windows (frames), since each one has different fields.
The question is, I wanted to use the previous method in a Class as Auxiliares and specify it as estatic , and I would just pass it a list of fields. But the problem is that it does not leave me, because of the non-static context.
Trying to solve this (I work), I decided to create a normal class and create an instance of it to use this method in question. But this makes me noise, because I do not know if it would be nice to create a Class that does not represent an entity a Functionality.
I hope you can clarify what I'm trying to do. Any questions I will answer as soon as possible. Thank you!
MetodosAuxiliares ma = new MetodosAuxiliares(campos);
@FXML
private void btnGuardar_Click(MouseEvent event) throws IOException {
if (ma.informacionDeCamposCompleta(campos)) {
Ventana.cerrarVentanaActual(btnGuardar, Formularios.FRM_VENDEDORES_EDICION);
Ventana.abrirVentana(Formularios.FRM_VENDEDORES, getClass());
}
}
I'll leave the class you use in case you want to check something
public class MetodosAuxiliares {
private ArrayList<Control> camposTxt;
public MetodosAuxiliares() {
camposTxt = new ArrayList<>();
}
public boolean informacionDeCamposCompleta(ArrayList<Control> campos) {
return validarCampos(campos);
}
private boolean validarCampos(ArrayList<Control> camposTxt) {
for (Control campo : camposTxt) {
if (campo instanceof TextField) {
TextField c = (TextField) campo;
if (c.getText().isEmpty()) {
//Tira una alerta informando que campo falta completar
validarFalla(campo);
return false;
}
}
if (campo instanceof TextArea) {
TextArea c = (TextArea) campo;
if (c.getText().isEmpty()) {
validarFalla(campo);
return false;
}
}
}
return confirmarGuardado();
}
private void validarFalla(Control campo) {
String tooltip = campo.getTooltip().getText();
Alert alert = new Alert(Alert.AlertType.INFORMATION);
alert.setTitle("Adm Concesionaria");
alert.setHeaderText("No completo todos los campos requeridos");
alert.setContentText("El campo " + tooltip + " no puede estar vacio");
alert.showAndWait();
campo.requestFocus();
}
private boolean confirmarGuardado() {
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
alert.setTitle("Adm Concesionaria");
alert.setHeaderText("Esta apunto de guardar los datos, desea contiuar?");
Optional<ButtonType> btnPresionado = alert.showAndWait();
return btnPresionado.get() == ButtonType.OK;
}