NumberFormatTextField agregado en el campo value de egresos y el total egresos

This commit is contained in:
Daniel Cortes
2019-01-06 00:52:15 -03:00
parent 73f5b44cf5
commit 573df8fc03
8 changed files with 289 additions and 226 deletions

View File

@@ -159,7 +159,7 @@ public class EgresosController {
String nro = this.view.getNroField().getText();
String descripcion = this.view.getDescripcionField().getText();
String valor = this.view.getValorField().getText();
int valor = this.view.getValorField().getValue();
TipoEgreso tipo = (TipoEgreso) this.view.getTipoCombo().getSelectedItem();
if(editing){
@@ -182,6 +182,7 @@ public class EgresosController {
this.egresoDAO.deleteEgreso(egreso);
this.updateTotalEgresos();
this.updateButtonsEnabled();
this.resetFocus();
}
}
@@ -206,7 +207,7 @@ public class EgresosController {
this.view.getNroField().setText(egreso.getNro());
this.view.getDescripcionField().setText(egreso.getDescripcion());
this.view.getValorField().setText(String.valueOf(egreso.getValor()));
this.view.getValorField().setValue(egreso.getValor());
this.view.getTipoCombo().setSelectedItem(egreso.getTipoEgreso());
}
}
@@ -216,7 +217,7 @@ public class EgresosController {
*/
private void updateTotalEgresos() {
int total = this.egresoDAO.getTotalEgreso(this.caja);
this.view.getTotalEgresosField().setText(String.valueOf(total));
this.view.getTotalEgresosField().setValue(total);
}
/**
@@ -237,10 +238,10 @@ public class EgresosController {
* Guarda un egreso tras llamar a validar su input
* Luego de guardar, agrega el egreso a la tabla, llama a actualizar el total de egresos y llama a limpiar a los inputs
*/
private void guardarEgreso(String nro, String descripcion, String valor, TipoEgreso tipo, Caja caja) {
if (this.validateInput(nro, descripcion, valor, tipo, caja)) {
private void guardarEgreso(String nro, String descripcion, int valor, TipoEgreso tipo, Caja caja) {
if (this.validateInput(nro, descripcion, tipo, caja)) {
Egreso egreso = new Egreso();
egreso.setValor(Integer.valueOf(valor));
egreso.setValor(valor);
egreso.setDescripcion(descripcion);
egreso.setNro(nro);
egreso.setTipoEgreso(tipo);
@@ -257,8 +258,8 @@ public class EgresosController {
* Tras esto actualiza el egreso en la tabla, llama a actualizar el total de egresos y a limpiar los inputs
* Finalmente setea la flag editing a false
*/
private void editarEgreso(String nro, String descripcion, String valor, TipoEgreso tipo, Caja caja) {
if (this.validateInput(nro, descripcion, valor, tipo, caja)) {
private void editarEgreso(String nro, String descripcion, int valor, TipoEgreso tipo, Caja caja) {
if (this.validateInput(nro, descripcion, tipo, caja)) {
this.editingEgreso.setValor(Integer.valueOf(valor));
this.editingEgreso.setDescripcion(descripcion);
this.editingEgreso.setNro(nro);
@@ -275,15 +276,14 @@ public class EgresosController {
* llama a los metodos necesarios para validar los inputs entregados
* @return true cuando todas las validaciones retoran true, si no, false
*/
private boolean validateInput(String nro, String descripcion, String valor, TipoEgreso tipoEgreso, Caja caja) {
private boolean validateInput(String nro, String descripcion, TipoEgreso tipoEgreso, Caja caja) {
boolean nroValidation = this.validateNro(nro);
boolean descripcionValidation = this.validateDescripcion(descripcion);
boolean valorValidation = this.validateValor(valor);
boolean tipoEgresoValidation = this.validateTipoEgreso(tipoEgreso);
boolean cajaValidation = this.validateCaja(caja);
return nroValidation && descripcionValidation && valorValidation && tipoEgresoValidation;
return nroValidation && descripcionValidation && tipoEgresoValidation;
}
/**
@@ -332,44 +332,6 @@ public class EgresosController {
return true;
}
/**
* Valida la variable valor contra los casos
* - Es null
* - Esta vacio
* - Los caracteres no son todos digitos
* - El largo del string es mayot a 10
* Cuando el primer caso sea true, colocara un mensaje de error correspondiente en el jlabel correspondiente
* @return Si cualquiera de estos casos son true se retornara false, si no, se retorna true
*/
private boolean validateValor(String valor) {
if (valor == null) {
this.view.getErrorValor().setText("Hubo un problema con los datos");
this.view.getErrorValor().setVisible(true);
return false;
}
if (valor.isEmpty()) {
this.view.getErrorValor().setText("El campo esta vacio");
this.view.getErrorValor().setVisible(true);
return false;
}
if (!valor.chars().allMatch(Character::isDigit)) {
this.view.getErrorValor().setText("Deben ser numeros");
this.view.getErrorValor().setVisible(true);
return false;
}
if (valor.length() > 10) {
this.view.getErrorValor().setText("El numero ingresado es demasiado largo");
this.view.getErrorValor().setVisible(true);
return false;
}
return true;
}
/**
* Valida la variable tipoEgreso contra los casos
* - Es null
@@ -399,7 +361,6 @@ public class EgresosController {
*/
private void hideErrorMessages() {
this.view.getErrorTipoEgreso().setVisible(false);
this.view.getErrorValor().setVisible(false);
this.view.getErrorDescripcion().setVisible(false);
this.view.getErrorNumero().setVisible(false);
}
@@ -410,6 +371,7 @@ public class EgresosController {
private void clearInputs() {
this.view.getTipoCombo().setSelectedIndex(0);
this.view.getNroField().setText("");
this.view.getValorField().setValue(0);
this.view.getValorField().setText("");
this.view.getDescripcionField().setText("");
}
@@ -418,7 +380,6 @@ public class EgresosController {
* Ejecuta trim sobre todos los campos de texto
*/
private void normalizeInputs(){
this.view.getValorField().setText(this.view.getValorField().getText().trim());
this.view.getNroField().setText(this.view.getNroField().getText().trim());
this.view.getDescripcionField().setText(this.view.getDescripcionField().getText().trim());

View File

@@ -69,7 +69,7 @@
</constraints>
<properties/>
</component>
<component id="696ee" class="javax.swing.JTextField" binding="valorField">
<component id="228a2" class="danielcortes.xyz.views.components.NumberFormatedTextField" binding="valorField">
<constraints>
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
@@ -218,7 +218,7 @@
<text value="Total Egresos:"/>
</properties>
</component>
<component id="2b8d0" class="javax.swing.JTextField" binding="totalEgresosField">
<component id="80b19" class="danielcortes.xyz.views.components.NumberFormatedTextField" binding="totalEgresosField">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>

View File

@@ -29,6 +29,7 @@ import com.intellij.uiDesigner.core.GridLayoutManager;
import com.intellij.uiDesigner.core.Spacer;
import danielcortes.xyz.models.tipo_egreso.TipoEgreso;
import danielcortes.xyz.views.components.EgresosTableModel;
import danielcortes.xyz.views.components.NumberFormatedTextField;
import javax.swing.*;
import javax.swing.table.TableRowSorter;
@@ -38,10 +39,10 @@ public class EgresosView {
public JPanel contentPanel;
private JTable egresosTable;
private JButton guardarButton;
private JTextField valorField;
private NumberFormatedTextField valorField;
private JTextField descripcionField;
private JTextField nroField;
private JTextField totalEgresosField;
private NumberFormatedTextField totalEgresosField;
private JComboBox<TipoEgreso> tipoCombo;
@@ -83,7 +84,7 @@ public class EgresosView {
return editarButton;
}
public JTextField getValorField() {
public NumberFormatedTextField getValorField() {
return valorField;
}
@@ -95,7 +96,7 @@ public class EgresosView {
return nroField;
}
public JTextField getTotalEgresosField() {
public NumberFormatedTextField getTotalEgresosField() {
return totalEgresosField;
}
@@ -165,7 +166,7 @@ public class EgresosView {
panel2.add(descripcionField, new GridConstraints(1, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false));
nroField = new JTextField();
panel2.add(nroField, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false));
valorField = new JTextField();
valorField = new NumberFormatedTextField();
panel2.add(valorField, new GridConstraints(1, 2, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false));
final JLabel label3 = new JLabel();
label3.setText("Valor");
@@ -230,7 +231,7 @@ public class EgresosView {
final JLabel label5 = new JLabel();
label5.setText("Total Egresos:");
panel5.add(label5, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_EAST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
totalEgresosField = new JTextField();
totalEgresosField = new NumberFormatedTextField();
totalEgresosField.setEditable(false);
panel5.add(totalEgresosField, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false));
}

View File

@@ -115,16 +115,6 @@
<visible value="false"/>
</properties>
</component>
<component id="4b7ff" class="javax.swing.JLabel" binding="errorValor">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<foreground color="-65536"/>
<text value="Label"/>
<visible value="false"/>
</properties>
</component>
<component id="7d011" class="javax.swing.JLabel" binding="errorNroInicial">
<constraints>
<grid row="2" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>

View File

@@ -201,11 +201,6 @@ public class IngresosView {
errorTipoIngreso.setText("Label");
errorTipoIngreso.setVisible(false);
panel2.add(errorTipoIngreso, new GridConstraints(2, 5, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
errorValor = new JLabel();
errorValor.setForeground(new Color(-65536));
errorValor.setText("Label");
errorValor.setVisible(false);
panel2.add(errorValor, new GridConstraints(2, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
errorNroInicial = new JLabel();
errorNroInicial.setForeground(new Color(-65536));
errorNroInicial.setText("Label");