NumberFormatTextField agregado en el campo value de ingresos y formateado los campos integer en los tablemodels

This commit is contained in:
Daniel Cortes
2019-01-06 00:44:49 -03:00
parent f1c199487a
commit 73f5b44cf5
7 changed files with 31 additions and 70 deletions

BIN
dist/caja.jar vendored

Binary file not shown.

BIN
dist/database.sqlite vendored

Binary file not shown.

View File

@@ -158,7 +158,7 @@ public class IngresosController {
this.normalizeInputs(); this.normalizeInputs();
this.hideErrorMessages(); this.hideErrorMessages();
String valor = this.view.getValorField().getText(); int valor = this.view.getValorField().getValue();
String nroZInicial = this.view.getNroZInicialField().getText(); String nroZInicial = this.view.getNroZInicialField().getText();
String nroZFinal = this.view.getNroZFinalField().getText(); String nroZFinal = this.view.getNroZFinalField().getText();
String nroInicial = this.view.getNroInicialField().getText(); String nroInicial = this.view.getNroInicialField().getText();
@@ -208,7 +208,7 @@ public class IngresosController {
this.editing = true; this.editing = true;
this.view.getTipoCombo().setSelectedItem(ingreso.getTipoIngreso()); this.view.getTipoCombo().setSelectedItem(ingreso.getTipoIngreso());
this.view.getValorField().setText(String.valueOf(ingreso.getValor())); this.view.getValorField().setValue(ingreso.getValor());
this.view.getNroZInicialField().setText(String.valueOf(ingreso.getNroZInicial())); this.view.getNroZInicialField().setText(String.valueOf(ingreso.getNroZInicial()));
this.view.getNroZFinalField().setText(String.valueOf(ingreso.getNroZFinal())); this.view.getNroZFinalField().setText(String.valueOf(ingreso.getNroZFinal()));
this.view.getNroInicialField().setText(String.valueOf(ingreso.getNroInicial())); this.view.getNroInicialField().setText(String.valueOf(ingreso.getNroInicial()));
@@ -221,7 +221,7 @@ public class IngresosController {
*/ */
private void updateTotalIngresos(){ private void updateTotalIngresos(){
int total = this.ingresoDAO.getTotalIngreso(this.caja); int total = this.ingresoDAO.getTotalIngreso(this.caja);
this.view.getTotalIngresoField().setText(String.valueOf(total)); this.view.getTotalIngresoField().setValue(total);
} }
/** /**
@@ -243,12 +243,12 @@ public class IngresosController {
* Guarda un ingreso tras llamar a validar el input * Guarda un ingreso tras llamar a validar el input
* Luego de guardar agrega a la tabla el ingreso, llama a limpiar los campos de input y a actualizar el total de ingresos * Luego de guardar agrega a la tabla el ingreso, llama a limpiar los campos de input y a actualizar el total de ingresos
*/ */
private void guardarIngreso(String valor, String nroZInicial, String nroZFinal, String nroInicial, String nroFinal, TipoIngreso tipoIngreso, Caja caja){ private void guardarIngreso(int valor, String nroZInicial, String nroZFinal, String nroInicial, String nroFinal, TipoIngreso tipoIngreso, Caja caja){
if(this.validateInput(valor, nroZInicial, nroZFinal, nroInicial, nroFinal, tipoIngreso, caja)){ if(this.validateInput(nroZInicial, nroZFinal, nroInicial, nroFinal, tipoIngreso, caja)){
Ingreso ingreso = new Ingreso(); Ingreso ingreso = new Ingreso();
ingreso.setTipoIngreso(tipoIngreso); ingreso.setTipoIngreso(tipoIngreso);
ingreso.setCaja(caja); ingreso.setCaja(caja);
ingreso.setValor(Integer.valueOf(valor)); ingreso.setValor(valor);
ingreso.setNroZInicial(nroZInicial); ingreso.setNroZInicial(nroZInicial);
ingreso.setNroZFinal(nroZFinal); ingreso.setNroZFinal(nroZFinal);
ingreso.setNroInicial(nroInicial); ingreso.setNroInicial(nroInicial);
@@ -267,10 +267,10 @@ public class IngresosController {
* Tras esto actualiza el ingreso en la tabla, llama a actualizar el total de ingresos, a limpiar los campos de input y a desactivar la flag de editing. * Tras esto actualiza el ingreso en la tabla, llama a actualizar el total de ingresos, a limpiar los campos de input y a desactivar la flag de editing.
* *
*/ */
private void editarIngreso(String valor, String nroZInicial, String nroZFinal, String nroInicial, String nroFinal, TipoIngreso tipoIngreso, Caja caja){ private void editarIngreso(int valor, String nroZInicial, String nroZFinal, String nroInicial, String nroFinal, TipoIngreso tipoIngreso, Caja caja){
if(this.validateInput(valor, nroZInicial, nroZFinal, nroInicial, nroFinal, tipoIngreso, caja)){ if(this.validateInput(nroZInicial, nroZFinal, nroInicial, nroFinal, tipoIngreso, caja)){
this.editingIngreso.setTipoIngreso(tipoIngreso); this.editingIngreso.setTipoIngreso(tipoIngreso);
this.editingIngreso.setValor(Integer.valueOf(valor)); this.editingIngreso.setValor(valor);
this.editingIngreso.setNroZInicial(nroZInicial); this.editingIngreso.setNroZInicial(nroZInicial);
this.editingIngreso.setNroZFinal(nroZFinal); this.editingIngreso.setNroZFinal(nroZFinal);
this.editingIngreso.setNroInicial(nroInicial); this.editingIngreso.setNroInicial(nroInicial);
@@ -287,10 +287,9 @@ public class IngresosController {
* Llama a los metodos necesarios para validar el input * Llama a los metodos necesarios para validar el input
* @return true cuando todas las validaciones retoran true, si no, false * @return true cuando todas las validaciones retoran true, si no, false
*/ */
private boolean validateInput(String valor, String nroZInicial, String nroZFinal, String nroInicial, String nroFinal, TipoIngreso tipoIngreso, Caja caja) { private boolean validateInput(String nroZInicial, String nroZFinal, String nroInicial, String nroFinal, TipoIngreso tipoIngreso, Caja caja) {
this.hideErrorMessages(); this.hideErrorMessages();
boolean valorValidation = this.validateValor(valor);
boolean nroZInicialValidation = this.validateNroZInicial(nroZInicial); boolean nroZInicialValidation = this.validateNroZInicial(nroZInicial);
boolean nroZFinalValidation = this.validateNroZFinal(nroZFinal); boolean nroZFinalValidation = this.validateNroZFinal(nroZFinal);
boolean nroInicialValidation = this.validateNroInicial(nroInicial); boolean nroInicialValidation = this.validateNroInicial(nroInicial);
@@ -298,7 +297,7 @@ public class IngresosController {
boolean tipoIngresoValidation = this.validateTipoIngreso(tipoIngreso); boolean tipoIngresoValidation = this.validateTipoIngreso(tipoIngreso);
boolean cajaValidation = this.validateCaja(caja); boolean cajaValidation = this.validateCaja(caja);
return valorValidation && tipoIngresoValidation && cajaValidation; return nroZInicialValidation && nroZFinalValidation && nroInicialValidation && nroFinalValidation && tipoIngresoValidation && cajaValidation;
} }
/** /**
@@ -310,44 +309,6 @@ public class IngresosController {
return caja != null; return caja != null;
} }
/**
* Valida la variable valor contra los casos
* - Es null
* - Esta vacio
* - Los caracteres no son solamente digitos
* - El largo del string es mayor 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 nroInicial contra los casos * Valida la variable nroInicial contra los casos
* - Es null * - Es null
@@ -456,7 +417,6 @@ public class IngresosController {
*/ */
private void hideErrorMessages() { private void hideErrorMessages() {
this.view.getErrorTipoIngreso().setVisible(false); this.view.getErrorTipoIngreso().setVisible(false);
this.view.getErrorValor().setVisible(false);
this.view.getErrorNroZInicial().setVisible(false); this.view.getErrorNroZInicial().setVisible(false);
this.view.getErrorNroZFinal().setVisible(false); this.view.getErrorNroZFinal().setVisible(false);
this.view.getErrorNroInicial().setVisible(false); this.view.getErrorNroInicial().setVisible(false);
@@ -468,6 +428,7 @@ public class IngresosController {
*/ */
private void clearInputs() { private void clearInputs() {
this.view.getTipoCombo().setSelectedIndex(0); this.view.getTipoCombo().setSelectedIndex(0);
this.view.getValorField().setValue(0);
this.view.getValorField().setText(""); this.view.getValorField().setText("");
this.view.getNroZInicialField().setText(""); this.view.getNroZInicialField().setText("");
this.view.getNroZFinalField().setText(""); this.view.getNroZFinalField().setText("");
@@ -479,7 +440,6 @@ public class IngresosController {
* Ejecuta un trim sobre todos los jtextfield * Ejecuta un trim sobre todos los jtextfield
*/ */
private void normalizeInputs(){ private void normalizeInputs(){
this.view.getValorField().setText(this.view.getValorField().getText().trim());
this.view.getNroZInicialField().setText(this.view.getNroZInicialField().getText().trim()); this.view.getNroZInicialField().setText(this.view.getNroZInicialField().getText().trim());
this.view.getNroZFinalField().setText(this.view.getNroZFinalField().getText().trim()); this.view.getNroZFinalField().setText(this.view.getNroZFinalField().getText().trim());
this.view.getNroInicialField().setText(this.view.getNroInicialField().getText().trim()); this.view.getNroInicialField().setText(this.view.getNroInicialField().getText().trim());

View File

@@ -65,7 +65,7 @@
<text value="Valor"/> <text value="Valor"/>
</properties> </properties>
</component> </component>
<component id="375b0" class="javax.swing.JTextField" binding="valorField"> <component id="482fa" class="danielcortes.xyz.views.components.NumberFormatedTextField" binding="valorField">
<constraints> <constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false"> <grid row="1" column="0" 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"/> <preferred-size width="150" height="-1"/>
@@ -223,7 +223,7 @@
<text value="Total Ingresos"/> <text value="Total Ingresos"/>
</properties> </properties>
</component> </component>
<component id="d9f4a" class="javax.swing.JTextField" binding="totalIngresoField"> <component id="69973" class="danielcortes.xyz.views.components.NumberFormatedTextField" binding="totalIngresoField">
<constraints> <constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"> <grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/> <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 com.intellij.uiDesigner.core.Spacer;
import danielcortes.xyz.models.tipo_ingreso.TipoIngreso; import danielcortes.xyz.models.tipo_ingreso.TipoIngreso;
import danielcortes.xyz.views.components.IngresosTableModel; import danielcortes.xyz.views.components.IngresosTableModel;
import danielcortes.xyz.views.components.NumberFormatedTextField;
import javax.swing.*; import javax.swing.*;
import javax.swing.table.TableRowSorter; import javax.swing.table.TableRowSorter;
@@ -39,8 +40,8 @@ public class IngresosView {
private JTable ingresosTable; private JTable ingresosTable;
private JButton guardarButton; private JButton guardarButton;
private JButton eliminarButton; private JButton eliminarButton;
private JTextField totalIngresoField; private NumberFormatedTextField totalIngresoField;
private JTextField valorField; private NumberFormatedTextField valorField;
private JComboBox<TipoIngreso> tipoCombo; private JComboBox<TipoIngreso> tipoCombo;
private JLabel errorTipoIngreso; private JLabel errorTipoIngreso;
private JLabel errorValor; private JLabel errorValor;
@@ -85,11 +86,11 @@ public class IngresosView {
return eliminarButton; return eliminarButton;
} }
public JTextField getTotalIngresoField() { public NumberFormatedTextField getTotalIngresoField() {
return totalIngresoField; return totalIngresoField;
} }
public JTextField getValorField() { public NumberFormatedTextField getValorField() {
return valorField; return valorField;
} }
@@ -183,7 +184,7 @@ public class IngresosView {
final JLabel label2 = new JLabel(); final JLabel label2 = new JLabel();
label2.setText("Valor"); label2.setText("Valor");
panel2.add(label2, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); panel2.add(label2, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
valorField = new JTextField(); valorField = new NumberFormatedTextField();
panel2.add(valorField, 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)); panel2.add(valorField, 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));
final JLabel label3 = new JLabel(); final JLabel label3 = new JLabel();
label3.setText("N° Inicial"); label3.setText("N° Inicial");
@@ -244,7 +245,7 @@ public class IngresosView {
final JLabel label7 = new JLabel(); final JLabel label7 = new JLabel();
label7.setText("Total Ingresos"); label7.setText("Total Ingresos");
panel4.add(label7, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_EAST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); panel4.add(label7, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_EAST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
totalIngresoField = new JTextField(); totalIngresoField = new NumberFormatedTextField();
totalIngresoField.setEditable(false); totalIngresoField.setEditable(false);
panel4.add(totalIngresoField, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false)); panel4.add(totalIngresoField, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false));
final JPanel panel5 = new JPanel(); final JPanel panel5 = new JPanel();

View File

@@ -27,16 +27,21 @@ package danielcortes.xyz.views.components;
import danielcortes.xyz.models.egreso.Egreso; import danielcortes.xyz.models.egreso.Egreso;
import javax.swing.table.AbstractTableModel; import javax.swing.table.AbstractTableModel;
import java.text.NumberFormat;
import java.util.ArrayList; import java.util.ArrayList;
public class EgresosTableModel extends AbstractTableModel { public class EgresosTableModel extends AbstractTableModel {
private String[] columns; private String[] columns;
private ArrayList<Egreso> rows; private ArrayList<Egreso> rows;
private NumberFormat nf;
public EgresosTableModel(){ public EgresosTableModel(){
super(); super();
this.columns = new String[]{"", "Descripcion", "Valor", "Tipo"}; this.columns = new String[]{"", "Descripcion", "Valor", "Tipo"};
this.rows = new ArrayList<>(); this.rows = new ArrayList<>();
this.nf = NumberFormat.getIntegerInstance();
} }
@Override @Override
@@ -86,7 +91,7 @@ public class EgresosTableModel extends AbstractTableModel {
case 1: case 1:
return rows.get(row).getDescripcion(); return rows.get(row).getDescripcion();
case 2: case 2:
return rows.get(row).getValor(); return nf.format(rows.get(row).getValor());
case 3: case 3:
return rows.get(row).getTipoEgreso(); return rows.get(row).getTipoEgreso();
} }
@@ -97,12 +102,4 @@ public class EgresosTableModel extends AbstractTableModel {
return rows.get(row); return rows.get(row);
} }
@Override
public Class<?> getColumnClass(int columnIndex) {
if (rows.isEmpty()) {
return Object.class;
}
return getValueAt(0, columnIndex).getClass();
}
} }

View File

@@ -27,16 +27,19 @@ package danielcortes.xyz.views.components;
import danielcortes.xyz.models.ingreso.Ingreso; import danielcortes.xyz.models.ingreso.Ingreso;
import javax.swing.table.AbstractTableModel; import javax.swing.table.AbstractTableModel;
import java.text.NumberFormat;
import java.util.ArrayList; import java.util.ArrayList;
public class IngresosTableModel extends AbstractTableModel { public class IngresosTableModel extends AbstractTableModel {
private String[] columns; private String[] columns;
private ArrayList<Ingreso> rows; private ArrayList<Ingreso> rows;
private NumberFormat nf;
public IngresosTableModel() { public IngresosTableModel() {
super(); super();
this.columns = new String[]{"Valor","N° Z Inicial", "N° Z Final", "N° Inicial", "N° Final", "Tipo"}; this.columns = new String[]{"Valor","N° Z Inicial", "N° Z Final", "N° Inicial", "N° Final", "Tipo"};
this.rows = new ArrayList<>(); this.rows = new ArrayList<>();
this.nf = NumberFormat.getIntegerInstance();
} }
@Override @Override
@@ -76,7 +79,7 @@ public class IngresosTableModel extends AbstractTableModel {
public Object getValueAt(int row, int col) { public Object getValueAt(int row, int col) {
switch (col) { switch (col) {
case 0: case 0:
return this.rows.get(row).getValor(); return nf.format(this.rows.get(row).getValor());
case 1: case 1:
return this.rows.get(row).getNroZInicial(); return this.rows.get(row).getNroZInicial();
case 2: case 2: