Mejora de los NumberFormatedTextFields
This commit is contained in:
@@ -107,8 +107,8 @@ public class ArqueoController {
|
||||
*/
|
||||
private void fillDocumentos() {
|
||||
this.documentos = this.documentosDAO.findByCaja(caja);
|
||||
this.view.getTarjetasField().setText(String.valueOf(documentos.getTarjetas()));
|
||||
this.view.getChequesField().setText(String.valueOf(documentos.getCheques()));
|
||||
this.view.getTarjetasField().setValue(documentos.getTarjetas());
|
||||
this.view.getChequesField().setValue(documentos.getCheques());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -197,6 +197,7 @@ public class ArqueoController {
|
||||
this.view.getCienField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"),"nextField");
|
||||
this.view.getCincuentaField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"),"nextField");
|
||||
this.view.getDiezField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"),"save");
|
||||
this.view.getGuardarEfectivoButton().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"),"save");
|
||||
|
||||
this.view.getVeinteMilField().getActionMap().put("nextField", new NextAction(this.view.getDiezMilField()));
|
||||
this.view.getDiezMilField().getActionMap().put("nextField", new NextAction(this.view.getCincoMilField()));
|
||||
@@ -207,16 +208,15 @@ public class ArqueoController {
|
||||
this.view.getCienField().getActionMap().put("nextField", new NextAction(this.view.getCincuentaField()));
|
||||
this.view.getCincuentaField().getActionMap().put("nextField", new NextAction(this.view.getDiezField()));
|
||||
this.view.getDiezField().getActionMap().put("save", new GuardarEfectivoAction(this));
|
||||
this.view.getGuardarEfectivoButton().getActionMap().put("save", new GuardarEfectivoAction(this));
|
||||
|
||||
|
||||
this.view.getChequesField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"),"nextField");
|
||||
this.view.getTarjetasField().getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"),"save");
|
||||
this.view.getChequesField().getActionMap().put("nextField", new NextAction(this.view.getTarjetasField()));
|
||||
this.view.getTarjetasField().getActionMap().put("save", new GuardarDocumentosAction(this));
|
||||
this.view.getGuardarDocumentosButton().getActionMap().put("save", new GuardarDocumentosAction(this));
|
||||
|
||||
|
||||
this.view.getGuardarEfectivoButton().addActionListener(e -> guardarEfectivoActionListener());
|
||||
this.view.getGuardarDocumentosButton().addActionListener(e -> guardarDocumentosActionListener());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -233,8 +233,7 @@ public class ArqueoController {
|
||||
* Primero llama a normalizar el input, luego a esconder los mensajes de error y finalmente a guardar los documentos
|
||||
*/
|
||||
private void guardarDocumentosActionListener(){
|
||||
this.normalizeDocumentosInput();
|
||||
this.hiddeDocumentosErrorMessages();
|
||||
this.view.getGuardarDocumentosButton().requestFocus();
|
||||
this.guardarDocumentos();
|
||||
}
|
||||
|
||||
@@ -273,87 +272,20 @@ public class ArqueoController {
|
||||
* llama a updateResumenDocumentos y updateResumenArqueo para actualizar los datos de documentosField y arqueoField
|
||||
*/
|
||||
private void guardarDocumentos() {
|
||||
String tarjetas = this.view.getTarjetasField().getText();
|
||||
String cheques = this.view.getChequesField().getText();
|
||||
int tarjetas = this.view.getTarjetasField().getValue();
|
||||
int cheques = this.view.getChequesField().getValue();
|
||||
|
||||
if (this.validateDocumentosInput(tarjetas, cheques)) {
|
||||
this.documentos.setTarjetas(Integer.valueOf(tarjetas));
|
||||
this.documentos.setCheques(Integer.valueOf(cheques));
|
||||
this.documentosDAO.updateDocumentos(documentos);
|
||||
this.documentos.setTarjetas(tarjetas);
|
||||
this.documentos.setCheques(cheques);
|
||||
this.documentosDAO.updateDocumentos(documentos);
|
||||
|
||||
this.updateResumenDocumentos();
|
||||
this.updateResumenArqueo();
|
||||
}
|
||||
this.updateResumenDocumentos();
|
||||
this.updateResumenArqueo();
|
||||
}
|
||||
|
||||
/**
|
||||
* Llama a las validaciones necesarias el input de Documentos
|
||||
* @return si es que todas las validaciones fueron correctas
|
||||
*/
|
||||
private boolean validateDocumentosInput(String tarjetas, String cheques) {
|
||||
|
||||
boolean tarjetasValidation = validateDocumentosValor(tarjetas, this.view.getErrorTarjetas());
|
||||
boolean chequesValidation = validateDocumentosValor(cheques, this.view.getErrorCheques());
|
||||
|
||||
return tarjetasValidation && chequesValidation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Valida el valor entregado contra las siguientes pruebas
|
||||
* - Es null
|
||||
* - Esta vacio
|
||||
* - Los caracteres no son solamente digitos
|
||||
* - El largo es mayor que diez
|
||||
* Setea un mensaje de error correspondiente en el errorLabel entregado.
|
||||
* @return cuando cualquiera de los casos anteriores sea true se retorna falso, si no retorna true.
|
||||
*/
|
||||
private boolean validateDocumentosValor(String valor, JLabel errorLabel) {
|
||||
|
||||
if (valor == null) {
|
||||
errorLabel.setText("Hubo un problema con los datos");
|
||||
errorLabel.setVisible(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (valor.isEmpty()) {
|
||||
errorLabel.setText("El campo esta vacio");
|
||||
errorLabel.setVisible(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!valor.chars().allMatch(Character::isDigit)) {
|
||||
errorLabel.setText("Deben ser numeros");
|
||||
errorLabel.setVisible(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (valor.length() > 10) {
|
||||
errorLabel.setText("El numero ingresado es demasiado largo");
|
||||
errorLabel.setVisible(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Esconde los mensajes de error en los campos de documentos
|
||||
*/
|
||||
private void hiddeDocumentosErrorMessages(){
|
||||
this.view.getErrorTarjetas().setVisible(false);
|
||||
this.view.getErrorCheques().setVisible(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ejecuta trim sobre todos los campos de documentos
|
||||
*/
|
||||
private void normalizeDocumentosInput() {
|
||||
this.view.getChequesField().setText(this.view.getChequesField().getText().trim());
|
||||
this.view.getTarjetasField().setText(this.view.getTarjetasField().getText().trim());
|
||||
}
|
||||
|
||||
private class GuardarEfectivoAction extends AbstractAction{
|
||||
private class GuardarEfectivoAction extends AbstractAction {
|
||||
ArqueoController controller;
|
||||
|
||||
GuardarEfectivoAction(ArqueoController controller){
|
||||
this.controller = controller;
|
||||
}
|
||||
@@ -364,8 +296,9 @@ public class ArqueoController {
|
||||
}
|
||||
}
|
||||
|
||||
private class GuardarDocumentosAction extends AbstractAction{
|
||||
private class GuardarDocumentosAction extends AbstractAction {
|
||||
ArqueoController controller;
|
||||
|
||||
GuardarDocumentosAction(ArqueoController controller){
|
||||
this.controller = controller;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user